from http://ibeblog.com/program StaticTest; {$APPTYPE CONSOLE} uses SysUtils, Classes; type TTestClass = class private class var FStaticField: TStrings; class function GetStaticField: string; static; class procedure SetStaticField(const Value: string); static; public class property StaticField: string read GetStaticField write SetStaticField; class constructor CreateClass; class destructor DestroyClass; end; { TTestClass } class constructor TTestClass.CreateClass; begin FStaticField := TStringList.Create; FStaticField.Text := 'Hello world!'; end; class destructor TTestClass.DestroyClass; begin FStaticField.Free; end; class function TTestClass.GetStaticField: string; begin Result := FStaticField.Text; end; class procedure TTestClass.SetStaticField(const Value: string); begin FStaticField.Text := Value; end; begin WriteLn(TTestClass.StaticField); ReadLn; // Stop window from closing end.
類別變數/函式的使用
週三, 2014-04-30 16:40
#1
類別變數/函式的使用