implementation{$R *.dfm}
{$R SysStr.res} const
ENGLISH = (SUBLANG_ENGLISH_UK shl 10) or LANG_ENGLISH;
CHINESE = (SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE;
{$R SysStr.res} const
ENGLISH = (SUBLANG_ENGLISH_UK shl 10) or LANG_ENGLISH;
CHINESE = (SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE;
TfrmMain =class(TForm)
priate
class function showInfo:integer;
end;var
frmMain : TfrmMain; implementationclass function showInfo:integer;
begin
result :=ClassVar; //这里返回一个类变量以便外部引用,这个ClassVar怎么定义
end;
A = class
class function Get: Integer;
end;//注意,D6不支持,用全局变量
//var
// I: Integer;class function A.Get: Integer;
const
I: Integer = 0;
begin
Result := I;
Inc(I);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := IntToStr(A.Get);
end;
class function A.Get: Integer;
const
I: Integer = 0;
var
P: PInteger;
begin
Result := I;
P := @I;
Inc(P^)
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := IntToStr(A.Get);
end;
所以一般来说你想翻译C的类变量,只能用全局变量来代替,或者如我上面所写。C中为什么要用静态变量自有它的道理,而在Delphi中你希望也在到如此功能,只能按照它的规则。
老兄,转一门语言其实不难,烦的是习惯,还有遇到问题那种下意识反应很难改。
这个问题是从面向对象编程中引申过来的,通过类的实例访问实例变量是没有问题的,
假如要直接访问一个类的方法,不是通过实例(注意这里不是对象,对象和实例有区别)来做,而且是各个实例之间的共享信息的结构,都可以直接引用类的方法由类变量来维护。
procedure TForm1.Button1Click(Sender: TObject);
{$J+}
const
J: Integer = 2;
{$J-}
begin
Caption := IntToStr(J);
J := J + 1;end;
如你所说:你的想法跟得到TObject.ClassName那没什么区别,但我到现在还没搞清楚它的具体格式和存放。跟你说了这么多,我还是没说明白,失败。
用编译指令:{$J}Assignable typed constants 即可分配类型的常量开关,好像这个做法呵呵,,聪明的delphi程序员
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
public
class function a1: TClass;
end;var
Form1: TForm1;implementation{$R *.dfm}class function TForm1.A1: TClass;
begin
Result := Self;
end;initialization
if TForm1.A1 = TForm1 then with TForm1.Create(nil) do Show;;
end.
//请在你的应用中好好利用Delphi的这些好方法