你的目的是要查询Form上的控件,函数的定义和返回值需要改一下...implementationuses Unit2;{$R *.dfm}function TForm1.FindForm(FormName,FormCaption, ControlName:string):TWinControl;var FindForm:TForm; FindFormClass:TFormClass; classname:string;//窗体类名 i:integer;begin result:=nil; FindForm:=tform(FormName); classname:='T'+formname; if Findclass(classname)=nil then exit; FindFormClass:=TFormClass(Findclass(classname)); if FindFormClass<>nil then begin application.Createform(FindFormClass,FindForm); FindForm.Caption:=FormCaption; FindForm.Show; for i:=0 to FindForm.ControlCount-1 do if FindForm.Controls.Name=ControlName then result:=TWinControl(FindForm.Controls); end;end;procedure TForm1.Button1Click(Sender: TObject);begin //这里没有考虑FindForm的返回值为nil的情况 TEdit(FindForm('Form2','AAA','Edit1')).Text:='TEST'; TButton(FindForm('Form2','AAA','Button1')).Caption:='TEST';end;initialization RegisterClass(TForm2);finalization UnRegisterClass(TForm2);