Delphi 上有像 C++ 的 Static variable 嗎? |
尚未結案
|
Diviner
初階會員 發表:36 回覆:112 積分:34 註冊:2002-03-13 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
Diviner
初階會員 發表:36 回覆:112 積分:34 註冊:2002-03-13 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
I don't think there is any equivalent in Delphi. Perhaps you could make use of unit global variable? e.g.
TMyClass = class {...} property MyVar: integer read GetVar write SetVar; {...} end; implementation var AVar: integer; {..} procedure TMyClass.GetVar: integer; begin Result := AVar; end; procedure TMyClass.SetVar(Value: integer); begin AVar := Value; end;Of course the above simple example is NOT thread safe |
ecafe
一般會員 發表:0 回覆:8 積分:11 註冊:2002-07-21 發送簡訊給我 |
|
thomas0728
中階會員 發表:112 回覆:260 積分:89 註冊:2002-03-12 發送簡訊給我 |
TMyClass = class
{...}
property MyVar: integer read GetVar write SetVar;
{...}
end; implementation {..} CONSTRUCTOR TMyClass.CREATE;
{$J }
CONST
AVar=10;
{$J-}
BEGIN
INHERITED;
......
END; procedure TMyClass.GetVar: integer;
begin
Result := AVar;
end; procedure TMyClass.SetVar(Value: integer);
begin
AVar := Value;
end;
加上編釋指引就可以有靜態的類別變數或屬性了。 如果愛情也有味覺
那麼 有沒有ㄧ種愛
微微泛酸 不太苦澀 有點甜密
嚐起來的滋味讓人想起幸福
Thomas Chiou
------
Thomas Chiou |
Diviner
初階會員 發表:36 回覆:112 積分:34 註冊:2002-03-13 發送簡訊給我 |
|
shrobert
一般會員 發表:0 回覆:5 積分:6 註冊:2002-06-03 發送簡訊給我 |
使用class function 去存取只宣告於可見度在該unit 中的變數或物件
.. type
TMyObj = class
class function GetX:integer;
end;
.
implementation var
X:integer; class function TMyObj.GetX:integer;
begin
result := X;
end; initialization
X := 3; finaliization end; Object Pascal 中並無class 變數,最新的版本我不知有無?
不知是否合乎要求
|
Diviner
初階會員 發表:36 回覆:112 積分:34 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |