Как Правильно Вставить Функцию?

02.06.2014
10
0
#1
PHP:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function F(x:real; var Xmax,Xmin,Ymax,Ymin:real):real;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.Pixels[10,20]:=clBlack;
function Tform1.F(x:real; var Xmax,Xmin,Ymax,Ymin:real):real;
begin
F:=Sin(x);
Xmax:=4*pi;
Xmin:=0;
Ymax:=1;
Ymin:=-1;
end;

end;

end.
Ошибка Statement expected but "FUNCTION" found
и тюп
 

sinkopa

Well-known member
17.06.2009
344
4
#2
PHP:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function F(x:real; var Xmax,Xmin,Ymax,Ymin:real):real;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Canvas.Pixels[10,20]:=clBlack;
function Tform1.F(x:real; var Xmax,Xmin,Ymax,Ymin:real):real;
begin
F:=Sin(x);
Xmax:=4*pi;
Xmin:=0;
Ymax:=1;
Ymin:=-1;
end;

end;

end.
Ошибка Statement expected but "FUNCTION" found
и тюп
Код:
// ...
implementation
// ...
function F(x:real; var Xmax,Xmin,Ymax,Ymin:real):real;
begin
// F := Sin(x);
Result := Sin(x);
Xmax :=4*pi;
Xmin := 0;
Ymax := 1;
Ymin :=-1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,e: Real;
begin
Canvas.Pixels[10,20]:=clBlack;

e := F(1.5,a,b,c,d);
// ... бла бла...

end;
 

Vadik(R)

Well-known member
12.12.2007
469
0
#3
Есть, кстати, и такой вариант - вставить функцию до begin:
Код:
// ...
implementation
// ...

procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,e: Real;

function F(x:real; var Xmax,Xmin,Ymax,Ymin:real):real;
begin
// F := Sin(x);
Result := Sin(x);
Xmax :=4*pi;
Xmin := 0;
Ymax := 1;
Ymin :=-1;
end;

begin
Canvas.Pixels[10,20]:=clBlack;

e := F(1.5,a,b,c,d);
// ... бла бла...

end;