unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm2 = class(TForm)
    Label1: TLabel;
    edtAccount: TEdit;
    Label2: TLabel;
    edtPassword: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
     function VerifyAccount:Boolean;  //声明位置不对?
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form2: TForm2;implementation{$R *.dfm}procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;procedure TForm2.Button1Click(Sender: TObject);
begin
if not VerifyAccount then
ShowMessage('账号或密码错误,请重新输入。');
end;function VerifyAccount:Boolean;
var
TextFileVar:TextFile;
sUserName,sPassword,sLine:string;
begin
Result:=False;
AssignFile(TextFileVar,'powder.txt');
Reset(TextFileVar);
while not Eof(TextFileVar) do
begin
ReadLn(TextFileVar,sLine);
sUserName:=Copy(sLine,0,Pos('=',sLine)-1);
sPassword:=Copy(sLine,Pos('=',sLine)+1,MaxInt);
if SameText(sUserName,edtAccount.Text)and(sPassword=edtPassword.Text)then    //这是57行
begin
ModalResult:=mrOK;  //这是59行,ModalResult是什么? 与Result不一样?
Break;
end;
end;
CloseFile(TextFileVar);
Result:=ModalResult=mrOK;
end;end.
[Error] Unit2.pas(57): Undeclared identifier: 'edtAccount'
[Error] Unit2.pas(57): ')' expected but identifier 'Text' found
[Error] Unit2.pas(59): Undeclared identifier: 'ModalResult'
[Warning] Unit2.pas(64): Comparing signed and unsigned types - widened both operands
[Error] Unit2.pas(19): Unsatisfied forward or external declaration: 'TForm2.VerifyAccount'
[Fatal Error] Project1.dpr(7): Could not compile used unit 'Unit2.pas'

解决方案 »

  1.   

    function TForm2.VerifyAccount:Boolean; 
    begin
    //dothing.
    end;
      

  2.   

    function VerifyAccount:Boolean; 这是个全局个函数,不是TForm2里的,edtAccount和edtPassword、ModalResult都是TForm2里的对象,所以编译找不到
    要么VerifyAccount这个函数放到TForm2里,要么就在edtAccount、edtPassword和ModalResult前都加上“Form2.”(就是变成Form2.edtAccount和Form2.edtPassword、Form2.ModalResult,虽然不推荐这样,但也能让你编译过,运行也没什么问题)