F
fengfan
Unregistered / Unconfirmed
GUEST, unregistred user!
变量怎么赋值?请教大家,请先看问题
一个问题,全局变量,怎样给一个全局变量赋值:
unit Unit2
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
type
TForm1 = class(TForm)
Button1: TButton
Button2: TButton
procedure Button1Click(Sender: TObject)
procedure Button2Click(Sender: TObject)
private
{ Private declarations }
public
{ Public declarations }
procedure test2(test:string)
end
var
Form1: TForm1
test:string
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject)
var
test1:string
begin
test1:='测试';//在这个地方调用下面的函数赋值
test2(test1)
end
procedure TForm1.test2(test: string)
begin
test:=test;//在这里赋值
showmessage(test);//显示结果为 ‘测试’
end
procedure TForm1.Button2Click(Sender: TObject)
begin
form1.Caption:=test;//在这里的显示为空,
end
end.
执行过程为:先按BUTTON1按纽,然后在按BUTTON2按纽,而在这时FORM。
CAPTION则显示为空了。怎么解决啊。 高手帮忙啊。请赶紧帮忙啊。
一个问题,全局变量,怎样给一个全局变量赋值:
unit Unit2
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
type
TForm1 = class(TForm)
Button1: TButton
Button2: TButton
procedure Button1Click(Sender: TObject)
procedure Button2Click(Sender: TObject)
private
{ Private declarations }
public
{ Public declarations }
procedure test2(test:string)
end
var
Form1: TForm1
test:string
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject)
var
test1:string
begin
test1:='测试';//在这个地方调用下面的函数赋值
test2(test1)
end
procedure TForm1.test2(test: string)
begin
test:=test;//在这里赋值
showmessage(test);//显示结果为 ‘测试’
end
procedure TForm1.Button2Click(Sender: TObject)
begin
form1.Caption:=test;//在这里的显示为空,
end
end.
执行过程为:先按BUTTON1按纽,然后在按BUTTON2按纽,而在这时FORM。
CAPTION则显示为空了。怎么解决啊。 高手帮忙啊。请赶紧帮忙啊。