早教吧作业答案频道 -->其他-->
delphi7自己定义的FUNCTION应该放在哪?unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Edit1:TEdit;Edit2:TEdit;Label1:TLabel;Button1:TButton;procedureButton
题目详情
delphi7 自己定义的FUNCTION应该放在哪?
unit Unit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForm1 = class(TForm)
Edit1:TEdit;
Edit2:TEdit;
Label1:TLabel;
Button1:TButton;
procedure Button1Click(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
FUNCTION MYSTR(var num1,num2:integer):integer;
var
pf,mysum,num1,num2:integer;
begin
pf:=num2*5;
mysum:=num1+pf;
mystr:=mysum;
end
var
Form1:TForm1;
implementation
{$R *.dfm}
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
label1.Caption:=mystr(edit1.Text,edit2.Text);
end;
end.
这里有一个自定义的FUNCTION,但是运行的时候总出错,不知道FUNCTION应该放在什么位置,随便就放了一个位置(运行时是提示错误的),请问大侠们,我应该把FUNCTION放在哪里才能使代码正确的运行呢!
上面的FUNCTION是不是有错误啊?
请大人们指正!
unit Unit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForm1 = class(TForm)
Edit1:TEdit;
Edit2:TEdit;
Label1:TLabel;
Button1:TButton;
procedure Button1Click(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
FUNCTION MYSTR(var num1,num2:integer):integer;
var
pf,mysum,num1,num2:integer;
begin
pf:=num2*5;
mysum:=num1+pf;
mystr:=mysum;
end
var
Form1:TForm1;
implementation
{$R *.dfm}
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
label1.Caption:=mystr(edit1.Text,edit2.Text);
end;
end.
这里有一个自定义的FUNCTION,但是运行的时候总出错,不知道FUNCTION应该放在什么位置,随便就放了一个位置(运行时是提示错误的),请问大侠们,我应该把FUNCTION放在哪里才能使代码正确的运行呢!
上面的FUNCTION是不是有错误啊?
请大人们指正!
▼优质解答
答案和解析
你的函数写的有问题啊~函数参数是num1,num2,那你怎么还在过程中定义num1,num2呢?还有你调用也有问题啊!label1.Caption:=mystr(edit1.Text,edit2.Text); 你自己定义函数返回值和参数都是整形,你调用使用的字符串类型,你把函数返回值赋给label1.Caption也不对啊~他不是整形啊
你写好函数声明部分写在 private或者public下都行
type
TForm1 = class(TForm)
Edit1:TEdit;
Edit2:TEdit;
Label1:TLabel;
Button1:TButton;
procedure Button1Click(Sender:TObject);
private
{ Private declarations }
//添加函数声明
public
{ Public declarations }
//添加函数声明
end;
添加好函数声明后,将光标放到函数声明上,按下“Ctrl+Shift+C”这样delphi自动为你生成函数定义部分框架,你在begin end;中添加代码即可
你写好函数声明部分写在 private或者public下都行
type
TForm1 = class(TForm)
Edit1:TEdit;
Edit2:TEdit;
Label1:TLabel;
Button1:TButton;
procedure Button1Click(Sender:TObject);
private
{ Private declarations }
//添加函数声明
public
{ Public declarations }
//添加函数声明
end;
添加好函数声明后,将光标放到函数声明上,按下“Ctrl+Shift+C”这样delphi自动为你生成函数定义部分框架,你在begin end;中添加代码即可
看了 delphi7自己定义的FU...的网友还看了以下:
如图,P为△ABC点,<APB=<BPC,将△ABP绕B点旋转60度到△A'BP',此时A',P' 2020-04-26 …
已知函数f(X)=x^(-1/2p^2+p+3/2)(p属于Z)在(0,+无穷)上是增函数,且在其 2020-05-13 …
已知曲线C的极坐标方程ρ=2,给定两点P(0,π/2),Q(-2,π),则有()A.P在曲线C上, 2020-05-15 …
如图,在三角形abc中,边ab,bc的垂直平分线相交于点p 求证pa=pb=pc 点p是否也在边a 2020-05-16 …
在△ABC中,边AB,BC的垂直平分线交于点P. 1.求证PA=PB=PC. 2.点P是否也在边A 2020-05-16 …
在什么条件下,P(A1∪A2)=P(A1)+P(A2)?在什么条件下,P(A∩B)=P(A)P(B 2020-05-17 …
在平面直角坐标系中,若两点P,Q满足条件:①P,Q都在函数y=f(x)的图象上;②P,Q两点关于直 2020-05-21 …
delphi7自己定义的FUNCTION应该放在哪?unitUnit1;interfaceuses 2020-06-09 …
三角形周长面积问题“三角形三边为a,b,c,则面积S=根号[p*(p-a)*(p-b)*(p-c) 2020-07-31 …
P/R(光合作用/呼吸作用)问题P/R是评价水体健康与否的有用指标,在贫营养湖中P/R=(),在富营 2020-12-09 …