0 delphi properties class function
TApplicationWrapper = class(TObjectWrapper)
private
function GetMyFonk(): string;
procedure SetMyFonk(myCmd: string);
published
property myFonk: String read GetMyFonk write SetMyFonk;
...
function TApplicationWrapper.GetMyFonk(): string;
begin
ShowMessage('GetMyFonk is Run');
Result :='';
end;
procedure TApplicationWrapper.SetMyFonk(myCmd: string);
begin
ShowMessage('SetMyFonk is Run');
end;
Run Code Online (Sandbox Code Playgroud)
该程序是这样工作的。但我想为GetMyFonk()函数分配参数。
function GetMyFonk (myCommand : String ): string;
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息。
[dcc32 Error] altPanellerU.pas(74): E2008 Incompatible types
Run Code Online (Sandbox Code Playgroud)
如何为函数赋值?
您的属性根本不支持带有参数的 getter 函数。对于要添加到 getter 的每个参数,您必须向属性和 setter 添加相应的参数,例如:
TApplicationWrapper = class(TObjectWrapper)
private
function GetMyFonk(myCommand : String): string;
procedure SetMyFonk(myCommand : String; Value : string);
published
property myFonk[myCommand : String] : String read GetMyFonk write SetMyFonk;
...
function TApplicationWrapper.GetMyFonk(myCommand : String): string;
begin
ShowMessage('GetMyFonk is Run w/ ' + myCommand);
Result :='';
end;
procedure TApplicationWrapper.SetMyFonk(myCommand : String; Value: string);
begin
ShowMessage('SetMyFonk is Run w/ ' + myCommand);
end;
Run Code Online (Sandbox Code Playgroud)
然后你必须像这样访问该属性:
App: TApplicationWrapper;
...
S := App.MyFonk['command'];
...
App.MyFonk['command'] := S;
Run Code Online (Sandbox Code Playgroud)
Embarcadero 的文档对此进行了更详细的讨论:
请参阅“数组属性”部分。
| 归档时间: |
|
| 查看次数: |
553 次 |
| 最近记录: |