初学者声明函数问题(50分)

  • 主题发起人 自我教育
  • 开始时间

自我教育

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Function Tfrom1.c(a,b:integer):integer;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
Function Tfrom1.c(a,b:integer):integer;
Begin
Result:=a+b;
End;
{$R *.dfm}

end.
错误提示:Expected'='but'('found
附加问题:如何调用dll中的过程?
 
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
Function c(a,b:integer):integer;
end;

 
我想你干脆不要type里面的申明,然后去掉implementation里面函数申明中的Tform1就可以了
 
type
TForm1 = class(TForm)
private
// 也可在这里声明;
{ Private declarations }
public
{ Public declarations }
Function c(a,b:integer):integer;
end;
 
上面修改错误提示:Undeclared identifier:'Tform1'
Undeclared identifier:'c'
Undeclared identifier:'Result'
我想声明个全局函数
 
换一下声明位置试一试,我这里测试通过,没有问题
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
Function Tfrom1.c(a,b:integer):integer;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
Function c(a,b:integer):integer;
Begin
Result:=a+b;
End;
end.
 
在声明区:
type
TForm1 = class(TForm)
Function Tfrom1.c(a,b:integer):integer;
中去掉Tfrom1,成为:
Function c(a,b:integer):integer;
 
to 浮生
问题依然是Expected'='but'('found
 
to自我教育
你太粗心了,TForm你写成了Tfrom,不出错才怪呢,对于你的错误,第一个一眼就能看出来,第二个只有细心才能看出来
 
对于你的错误有二
type
TForm1 = class(TForm)
Function Tfrom1.c(a,b:integer):integer;
1. //不用加^^^^^^
2. //不能在此处加,这里只能是窗体上的控件。
private
{ Private declarations }
public
{ Public declarations }
end;
 
正解:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
Function Tfrom1.c(a,b:integer):integer;// <---去掉 Tfrom1. 几个字,放到下面 |
private |
<----------------------|
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
<------
Function Tfrom1.c(a,b:integer):integer; | // Tfrom1 改为 TForm1
Begin |
Result:=a+b; |
End; |
{$R *.dfm} // <---消息定义和资源储存文件说明往上提-|
end.

 
后边的两位也很粗心,Tfrom仍然没改,干什么都得细心,编程更是如此,如此简单的问题不用再讨论的,应该结束了,
多人接受了答案
 
TO:chuguozhen
我没改吗?请看仔细。
 
你应该在在新的Unit里写
不要在新的Form里
 
同意楼上。
 
谢谢各位,全局函数是应该声明在type部分的,并且在引用时uses该单元,就ok了!
 
顶部