Wykres funkcji w trybie graficznym w Delphi7

0

Witam chcę zrobić wykres funkcji którego wykresem jest hiperbola , chciałbym żeby zawierała się tylko w dodatniej części układu współrzędnych (tzn tylko w górnej prawej części układu ) . W programie musze podac parametr a . Zrobiłem program lecz jest błąd w jednej linijce i program nie chce zadziałać a ja nie wiem o co chodzi (jestem początkujący w delphi). Proszę o pomoc.

o to kod (1 button , 1 edit , 1 iamge)

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var a,  i, x, y : real;

begin



a := StrToint(Edit1.Text);





With Image1 do
  begin
    Canvas.MoveTo(100, 0);
    Canvas.LineTo(100, 200);
    Canvas.MoveTo(0, 100);
    Canvas.LineTo(200, 100);
  end;

//Rysowanie wykresu funkcji
  Image1.Canvas.MoveTo(-1, 101);

  x := 0;
  REPEAT
  begin
    y := a/x;
    Image1.Canvas.LineTo(x + 100, -y + 100);
    x := x + 1;
  end;
  UNTIL (x = 100);
end;

end.

tu mam błąd :

Image1.Canvas.LineTo(x + 100, -y + 100);

2
Image1.Canvas.LineTo( round( x + 100 ),
                                    round( -y + 100));
0

zrobiłem tak jak mi napisałeś ale po uruchomieniu wyskakuje mi error systemowy : Project Project1.exe raised exception class EZeroDivide with message
'Floating point division by zero' . Process stoped. Use step or run to continue.

Dokładnie tak zrobiłem i ten błąd mam


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var a,i, x, y : real;

begin

a := StrToint(Edit1.Text);

With Image1 do
  begin
    Canvas.MoveTo(100, 0);
    Canvas.LineTo(100, 200);
    Canvas.MoveTo(0, 100);
    Canvas.LineTo(200, 100);
  end;

//Rysowanie wykresu funkcji
  Image1.Canvas.MoveTo(-1, 101);

  x := 0;
  REPEAT
  begin
    y := a/x;
    Image1.Canvas.LineTo(round(x + 100), round(-y + 100));
    x := x + 1;
  end;
  UNTIL (x = 100);
end;

end.

 

Znaczy program się uruchamia ale ten błąd pojawia się po wciśnięciu Buttona (juz w programie)

3

A czego się spodziewasz?

x := 0;
  REPEAT
  begin
    y := a/x;

Cholero, nie dziel przez zero.

0

boże nie widziałem (wstyd ) :) dziękuje bardzo :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1