Property,read,write的困惑 |
缺席
|
alex_soong
一般會員 ![]() ![]() 發表:2 回覆:3 積分:1 註冊:2004-11-04 發送簡訊給我 |
我是初次寫VCL檔,可是在property時,read和write總是會報如下錯誤:
Incompatible types
察看幫助,得到如下結果:
This message is displayed when you try to use a var parameter in a property setter parameter. The parameter of a property setter procedure cannot be a var or out parameter.
雖然,我能理解字面的意思,但是實在是無法做出正確的理解。
我的檔案如下:
FADODatabase = class(TComponent)
private
{private declarations here}
fFilePathandName: string;
fFilepath: string;//數據庫路徑
fFileName: string;//數據庫表名
fTableNames: Tstrings; //數據庫表名的列表
fTablecount: integer; //表名個數
fTableIndex: integer; //工作的指針
fBExists: boolean; //檢測數據庫是否存在
Procedure SetFilePath(FilePathAndName:string);
procedure SetFileName(FilePathAndName:string);
Procedure SetDatabaseExists(FilePathAndName:string);
procedure CreateDatabase(FilePathAndName:string);
function SetTableNames(FilePathAndName:string): Tstrings;
procedure SetTableNamesCount;
Protected
{protected declarations here} public
{public declarations here}
Property FilePathAndName: string read fFilePathandName write fFilePathandName;
property FilePath: string read fFilepath write SetFilePath;
Property Filename: string read fFileName Write SetFileName;
Property BFileExists: boolean read fBExists;// Write SetDatabaseExists;
property TableNameList: Tstrings read fTableNames;// Write SetTableNames;
property Tablenamecount: integer read
constructor Create(AOwner: TComponent); override;
destructor Destroy; override ; published
{published declarations here}
end; 在我寫到Property BFileExists: boolean read fBExists;// Write SetDatabaseExists;時就會報以上錯誤。
謝謝各位
|
wzw_2005
一般會員 ![]() ![]() 發表:1 回覆:4 積分:1 註冊:2005-05-31 發送簡訊給我 |
|
alex_soong
一般會員 ![]() ![]() 發表:2 回覆:3 積分:1 註冊:2004-11-04 發送簡訊給我 |
|
wameng
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
做一點簡短的補充:
一般屬性的寫法為 Property BFileExists: boolean read fBExists Write fBExists Default false; 看起來很簡單。讀就是讀。寫就是寫。不做任何處理。 Property BFileExists: boolean read GetBExists Write fBExists; Function GetBExists:Boolean; begin Result := FileExists(....); end; 當讀取該元件屬性時,會執行 GetBExists。 用來確認屬性的正確性。例如:TLabel 的 GetTransparent Property BFileExists: boolean read fBExists Write WriteBExists; Procedure WriteBExists(Value:Boolean); begin if fBExists<>Value then begin ... end; end; 通常這樣的用意在於,寫入該屬性時。 可以檢查屬性的有效值或觸發異動屬性的事件。做一些處理。 像是刷新元件等 Repaint。~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |