为什么会出错,函数的使用问题

redhatcn 2003-08-17 10:53:16
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
function someDoit(i:Integer):Integer;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
p : Integer;
begin
p := someDoit(5);
Edit1.Text := IntToStr(p);
end;

function someDoit(i : Integer):Integer;
begin
Result := i+1;
end;

end.

---------------
DELPHI 7.0下调试
错误信息:
[Error] Unit1.pas(13): Unsatisfied forward or external declaration: 'TForm1.someDoit'
[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'

...全文
64 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
redhatcn 2003-08-17
  • 打赏
  • 举报
回复
谢谢海天子
cnssk 2003-08-17
  • 打赏
  • 举报
回复
同意一楼
应该在下面定义函数时加上Tform1.
huojiehai 2003-08-17
  • 打赏
  • 举报
回复
var
Form1: TForm1;

implementation

{$R *.dfm}

function someDoit(i : Integer):Integer;//换一下位置
begin
Result := i+1;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
p : Integer;
begin
p := someDoit(5);
Edit1.Text := IntToStr(p);
end;


end.

microjuz 2003-08-17
  • 打赏
  • 举报
回复
function someDoit(i : Integer):Integer;
begin
Result := i+1;
end;
/////
function TForm1.someDoit(i: Integer): Integer;
begin
Result := i+1;
end;

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧