在vb中,
1、全局变量的定义是在任何一个模块中,定义:public str as string;这个str就是一个全局变量了,在任何窗体、模块中都可以使用。
2、在窗体中定义个dim str as string 则可以在窗体内部使用;
3、在模块内用private str as string 则可以在模块内部使用;
在delphi中:
例如:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
int_a:int;//***1
{ Public declarations }
end;
var
Form1: TForm1;
int_b:int;//***2
implementation
{$R *.DFM}
var
int_c:int;//***3
procedure TForm1.Button1Click(Sender: TObject);
begin
//do something
end;
end.
位置1处定义:是类TForm1的变量,如果本单元中有其他的类或者其他单元,那么在其过程中引用时要先写出 "form1. "。
位置2处定义:是本单元的变量,所以本单元内所有的类或者其他单元(当然要引用本单元)都可以直接引用。
以上为本人愚见,请不吝赐教!
3082

被折叠的 条评论
为什么被折叠?



