delphi 怎样读取另一个窗口的变量
1个回答
展开全部
在调用窗体单元的实现部分用uses 子句引用被调用窗体单元,然后就可以带窗体名称的引用了。
例如:
unit Unit1;
interface
uses
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
uses unit2; {*****************}
{$R *.dfm}
procedure 缺乱TForm1.Button1Click(Sender: TObject);
begin
showmessage(form2.s); {在第1个窗弯亮体中显示串s}
end;
end.
========================================================
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
伏闹档s:string; {**********************第2个窗体定义的串变量}
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
s:='form2';
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询