如果F是一个Function类型的指针,var F : Function :Integer;
MyFunction是一个定义好的Function
那么判断两个Function的返回值是否一致,用if F = MyFunction then ...;编译时为什么会出错
改为if @F = @MyFunction then ...;是正确的?为什么取一个procedural变量的内存地址用的是@@?@@MyFunction@不就是取址吗?
MyFunction是一个定义好的Function
那么判断两个Function的返回值是否一致,用if F = MyFunction then ...;编译时为什么会出错
改为if @F = @MyFunction then ...;是正确的?为什么取一个procedural变量的内存地址用的是@@?@@MyFunction@不就是取址吗?
function MyFunc(): Integer;
begin
......
end;......var
F : Function: Integer;
begin
if F = MyFunc then
begin
......
end;
end;
编译不出错啊?
if F = MyFunction then ...;
In this case, the occurrence of F results in a function call; the compiler calls the function pointed to by F, then calls the function
MyFunction, then compares the results. The rule is that whenever a procedural variable occurs within an expression, it
represents a call to the referenced procedure or function. In a case where F references a procedure (which doesn't return a
value), or where F references a function that requires parameters, the previous statement causes a compilation error. To
compare the procedural value of F with MyFunction, use
if @F = @MyFunction then ...;
@F converts F into an untyped pointer variable that contains an address, and @MyFunction returns the address of MyFunction.
To get the memory address of a procedural variable (rather than the address stored in it), use @@. For example, @@F returns
the address of F.