运行总是提示如下信息
[Error] Unit1.pas(25): Unsatisfied forward or external declaration: 'TForm1.ProfitCount'
代码如下:请帮忙改改!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label3: TLabel;
Edit3: TEdit;
private
{ Private declarations }
public
{ Public declarations }
function ProfitCount(x,Y:Integer;Z:real):Real;
end;var
Form1: TForm1;implementation{$R *.dfm}
function ProfitCount(x,Y:Integer;Z:real):Real;
begin
result:=(x/z)-y;
end;end.
[Error] Unit1.pas(25): Unsatisfied forward or external declaration: 'TForm1.ProfitCount'
代码如下:请帮忙改改!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label3: TLabel;
Edit3: TEdit;
private
{ Private declarations }
public
{ Public declarations }
function ProfitCount(x,Y:Integer;Z:real):Real;
end;var
Form1: TForm1;implementation{$R *.dfm}
function ProfitCount(x,Y:Integer;Z:real):Real;
begin
result:=(x/z)-y;
end;end.
金盆洗澡 重出江湖 打劫.抢分 掀起一场腥风血雨 戒烟攒钱 只为换新车
function ProfitCount(x,Y:Integer;Z:real):Real;
begin
result:=(x/z)-y;
end;
这里应该是:
implementation{$R *.dfm}
function Tform1.ProfitCount(x,Y:Integer;Z:real):Real;
begin
result:=(x/z)-y;
end;
unit Unit1;interfaceuses
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 }
end;var
Form1: TForm1;implementation{$R *.dfm}function ProfitCount(x,Y:Integer;Z:real):Real;
begin
result:=(x/z)-y;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(vartostr(profitcount(6,3,1)));
end;end.
一是把public里面的声明去掉
二是带着声明,在下面的函数部分加form1.,如一楼所说
1:type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
function ProfitCount(x,Y:Integer;Z:real):Real;//如果这样声明
end;
function Tform1.ProfitCount(x,Y:Integer;Z:real):Real;//则必须这样定义
begin
result:=(x/z)-y;
end;
2:implementation{$R *.dfm}
function ProfitCount(x,Y:Integer;Z:real):Real;//如果是这样,则用的时侯直接调用就可。
begin
do something;
end;