返回值类型不对; function Isprime(i:integer):boolean 定义了返回值是逻辑型,那么返回当然就要用逻辑的。
是呀! 我返回语句是: result:=false; or result:=true; Isprime:=false; of isprime:=true;
是不是你在写函数体的时候,没有写窗体的名字啊? 声明函数: private function Isprime(i:integer):boolean; 实现部分: function TForm1.Isprime(i:integer):boolean; beginend; 注意:TForm1
[Error] Unit1.pas(17): Unsatisfied forward or external declaration: 'TForm1.Isprime'
program Project1;uses Forms, Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. ///////////////// unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } function Isprime(i:integer):boolean; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var i,j :Integer; begin i:=StrToInt(Edit1.text); if i>5 then for j:=2 to i do if isprime(j) and isprime(i div j) then listbox1.AddItem(inttostr(j)+'*'+inttostr(i div j),Listbox1); end;function IsPrime(i:integer):boolean; var Byes:boolean; j:integer; begin Byes:=true; //标志 for j:=2 to i do if i mod j=0 then Byes:=false; Isprime:=Byes; end; end.
////////// 错误信息[Error] Unit1.pas(17): Unsatisfied forward or external declaration: 'TForm1.Isprime' [Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
function IsPrime(i:integer):boolean; 这部分应该改为: function TForm1.IsPrime(i:integer):boolean;
错误信息不是都已经给你指出来了吗? Unsatisfied forward or external declaration: 'TForm1.Isprime'
program Project1;uses Forms, Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. ///////////////// unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; ListBox1: TListBox; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } function Isprime(i:integer):boolean; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var i,j :Integer; begin i:=StrToInt(Edit1.text); if i>5 then for j:=2 to i do if isprime(j) and isprime(i div j) then listbox1.AddItem(inttostr(j)+'*'+inttostr(i div j),Listbox1); end;function TForm1.IsPrime(i:integer):boolean; //或者把IsPrime从TForm1类里拿出来 var Byes:boolean; j:integer; begin Byes:=true; //标志 for j:=2 to i do if i mod j=0 then Byes:=false; Isprime:=Byes; end; end.
function Isprime(i:integer):boolean
定义了返回值是逻辑型,那么返回当然就要用逻辑的。
我返回语句是:
result:=false; or result:=true;
Isprime:=false; of isprime:=true;
声明函数:
private
function Isprime(i:integer):boolean;
实现部分:
function TForm1.Isprime(i:integer):boolean;
beginend;
注意:TForm1
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
/////////////////
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function Isprime(i:integer):boolean;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i,j :Integer;
begin
i:=StrToInt(Edit1.text);
if i>5 then
for j:=2 to i do
if isprime(j) and isprime(i div j) then
listbox1.AddItem(inttostr(j)+'*'+inttostr(i div j),Listbox1);
end;function IsPrime(i:integer):boolean;
var
Byes:boolean;
j:integer;
begin
Byes:=true; //标志
for j:=2 to i do
if i mod j=0 then
Byes:=false;
Isprime:=Byes;
end;
end.
错误信息[Error] Unit1.pas(17): Unsatisfied forward or external declaration: 'TForm1.Isprime'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
function IsPrime(i:integer):boolean;
这部分应该改为:
function TForm1.IsPrime(i:integer):boolean;
Unsatisfied forward or external declaration: 'TForm1.Isprime'
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
/////////////////
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function Isprime(i:integer):boolean;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i,j :Integer;
begin
i:=StrToInt(Edit1.text);
if i>5 then
for j:=2 to i do
if isprime(j) and isprime(i div j) then
listbox1.AddItem(inttostr(j)+'*'+inttostr(i div j),Listbox1);
end;function TForm1.IsPrime(i:integer):boolean; //或者把IsPrime从TForm1类里拿出来
var
Byes:boolean;
j:integer;
begin
Byes:=true; //标志
for j:=2 to i do
if i mod j=0 then
Byes:=false;
Isprime:=Byes;
end;
end.