Discussion:
How to call virtual StoredProc from PropInfo
(too old to reply)
Ondrej Pokorny
2017-05-17 16:13:45 UTC
Permalink
Raw Message
Hello!

For the Lazarus IDE I need to call the stored function from a property.

I was able to get the pointer of a static procedure and call it:

function GetStoredFunction(APropInfo: PPropInfo; AInstance:
TPersistent): CodePointer;
var
StoredProcType: Byte;
begin
StoredProcType := ((APropInfo^.PropProcs shr 4) and 3);
case StoredProcType of
ptStatic: Result:=APropInfo^.StoredProc; // this is fine
ptVirtual: Result:=APropInfo^.StoredProc; // this is obviously
wrong - it has to be instance-dependent
else
Result:=nil;
end;
end;

type
TBoolFunc = function: Boolean of object;
function CallStoredFunction(APropInfo: PPropInfo; AInstance:
TPersistent): Boolean;
var
Func: TMethod;
FFunc: TBoolFunc;
begin
Func.Code := GetStoredFunction(APropInfo, AInstance);
Func.Data := AInstance;
FFunc := TBoolFunc(Func);
Result := FFunc();
end;

But this approach is obviously wrong for virtual stored properties
because the StoredProc cannot point to the actual virtual/overridden
method.

My question is, how can I call a virtual stored procedure from PropInfo?

+ Test project attached :)

Ondrej
Ondrej Pokorny
2017-05-17 17:13:57 UTC
Permalink
Raw Message
Post by Ondrej Pokorny
My question is, how can I call a virtual stored procedure from PropInfo?
Digging through the code, I found it:

function GetStoredFunction(APropInfo: PPropInfo; AInstance:
TPersistent): CodePointer;
var
StoredProcType: Byte;
xT: Pointer;
begin
StoredProcType := ((APropInfo^.PropProcs shr 4) and 3);
case StoredProcType of
ptStatic: Result:=APropInfo^.StoredProc; // this is fine
* ptVirtual: Result :=
PPointer(Pointer(AInstance.ClassType))[{%H-}PtrInt(APropInfo^.StoredProc)
div SizeOf(Pointer)];**
* end else
Result:=nil;
end;
end;

Ondrej

Loading...