没有带有这些参数的重载版本 - 带有 read/write 属性 的 var param
No overloaded version with these arguments - var param with read/write property
我有两个重载过程,我想调用其中的第二个:
function ModifySyncProperties(AEWSItemId: String; AEvent: TcxSchedulerEvent; var AEWSChangeKey: String): Boolean; overload;
function ModifySyncProperties(AEWSItemId: String; ATTID: Integer; ASyncID: String; var AEWSChangeKey: String): Boolean; overload;
虽然出现错误,但失败了:
lSuccess := FDMExchange.ModifySyncProperties(lEWSId, lApp.EventID, lNewOutlookID, lApp.EWSItemChangeKey);
There is no overloaded version of 'ModifySyncProperties' that can be called with these arguments
虽然这有效:
lChangeKey := lApp.EWSItemChangeKey;
lSuccess := FDMExchange.ModifySyncProperties(lEWSId, lApp.EventID, lNewOutlookID, lChangeKey);
lApp.EWSItemChangeKey := lChangeKey;
以下是类型和变量:
lNewOutlookID,
lEWSID,
lChangeKey : String;
lApp : TEWSAppointment;
lSuccess : Boolean;
TEWSAppointment
在另一个单元的 interface
部分定义为:
TEWSAppointment = class
private
FEventID: Integer;
...
FEWSItemChangeKey: String;
...
public
property EventID: Integer read FEventID write FEventID;
...
property EWSItemChangeKey: String read FEWSItemChangeKey write FEWSItemChangeKey;
...
end;
为什么编译器不接受 read/write lApp
属性 作为 var
参数?
我正在使用 Delphi Rio 10.3.1。
var
parameters 的文档说:
If a routine's declaration specifies a var parameter, you must pass an assignable expression - that is, a variable, typed constant (in the {$J+} state), dereferenced pointer, field, or indexed variable to the routine when you call it.
一个属性不符合这个要求。
此外,properties 的文档明确指出:
Unlike fields, properties cannot be passed as var parameters, nor can the @ operator be applied to a property.
在实现层面,ABI,var
参数是通过传递变量的地址来实现的。由于属性不一定有带地址的支持变量,编译器不能直接获取这样的变量地址。
此外,如果 属性 getter 或 setter 执行超出读取或写入变量的操作,则需要调用它们。
原则上至少该语言可以通过声明局部变量并编译此代码来支持您希望的用法:
localVar := myProperty;
foo(localVar);
myProperty := localVar;
但是,编译器的设计者在将属性引入语言时并没有实现这一点。
我有两个重载过程,我想调用其中的第二个:
function ModifySyncProperties(AEWSItemId: String; AEvent: TcxSchedulerEvent; var AEWSChangeKey: String): Boolean; overload;
function ModifySyncProperties(AEWSItemId: String; ATTID: Integer; ASyncID: String; var AEWSChangeKey: String): Boolean; overload;
虽然出现错误,但失败了:
lSuccess := FDMExchange.ModifySyncProperties(lEWSId, lApp.EventID, lNewOutlookID, lApp.EWSItemChangeKey);
There is no overloaded version of 'ModifySyncProperties' that can be called with these arguments
虽然这有效:
lChangeKey := lApp.EWSItemChangeKey;
lSuccess := FDMExchange.ModifySyncProperties(lEWSId, lApp.EventID, lNewOutlookID, lChangeKey);
lApp.EWSItemChangeKey := lChangeKey;
以下是类型和变量:
lNewOutlookID,
lEWSID,
lChangeKey : String;
lApp : TEWSAppointment;
lSuccess : Boolean;
TEWSAppointment
在另一个单元的 interface
部分定义为:
TEWSAppointment = class
private
FEventID: Integer;
...
FEWSItemChangeKey: String;
...
public
property EventID: Integer read FEventID write FEventID;
...
property EWSItemChangeKey: String read FEWSItemChangeKey write FEWSItemChangeKey;
...
end;
为什么编译器不接受 read/write lApp
属性 作为 var
参数?
我正在使用 Delphi Rio 10.3.1。
var
parameters 的文档说:
If a routine's declaration specifies a var parameter, you must pass an assignable expression - that is, a variable, typed constant (in the {$J+} state), dereferenced pointer, field, or indexed variable to the routine when you call it.
一个属性不符合这个要求。
此外,properties 的文档明确指出:
Unlike fields, properties cannot be passed as var parameters, nor can the @ operator be applied to a property.
在实现层面,ABI,var
参数是通过传递变量的地址来实现的。由于属性不一定有带地址的支持变量,编译器不能直接获取这样的变量地址。
此外,如果 属性 getter 或 setter 执行超出读取或写入变量的操作,则需要调用它们。
原则上至少该语言可以通过声明局部变量并编译此代码来支持您希望的用法:
localVar := myProperty;
foo(localVar);
myProperty := localVar;
但是,编译器的设计者在将属性引入语言时并没有实现这一点。