unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,unit3;//unit3在函数定义前就要加入
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
function Name1(Aform:TForm3):string;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.Name1(Aform:TForm3):string;
begin
result:=aform.RadioButton1.Caption;//返回值
end;
procedure TForm1.Button1Click(Sender: TObject);
var a:tform3;//先申明
begin
a:=tform3.Create(application);//要先显示建立,因为这样才返回a指针值
showmessage('a.RadioButton1.Caption is: '+name1(a));
end;
end.
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm3 = class(TForm)
RadioButton1: TRadioButton;//定义好RadioButton1
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
end.
注意函数function TForm1.Name1(Aform:TForm3):string;中的aform一定是一个(有效)指针
才可以访问,不然的话会发生内存访问错误的!依靠var a:tform3;//先申明
begin
a:=tform3.Create(application);//要先显示建立,因为这样才返回a的有效指针值
不知道是不是你要的效果!!!!