Delphi部分:
我有一个带有事件的类,需要从该事件中调用一个过程,并将接口对象传递给它。在Delphi中可以正常工作,但在Pascal Script中声明时遇到了问题。
背景说明 - IGPGraphics
接口是Delphi GDI+库
的一部分,没有定义方法,如下所示:
type
IGdiplusBase = interface
['{24A5D3F5-4A9B-42A2-9F60-20825E2740F5}']
IGPGraphics = interface(IGdiPlusBase)
['{57F85BA4-CB01-4466-8441-948D03588F54}']
以下是我需要在Pascal Script中完成的简化Delphi伪代码:
type
TRenderEvent = procedure(Sender: TObject; const GPGraphics: IGPGraphics) of object;
TRenderClass = class(TGraphicControl)
private
FOnRender: TRenderEvent;
public
property OnRender: TRenderEvent read FOnRender write FOnRender;
end;
// when the TRenderClass object instance fires its OnRender event I want to call
// the RenderObject procedure passing the IGPGraphics interfaced object to it; I
// hope I'm doing it right, I'm just a newbie to this stuff - but it works so far
// in Delphi (since I didn't get it to work in Pascal Script)
procedure TForm1.RenderClass1Render(Sender: TObject; const GPGraphics: IGPGraphics);
begin
RenderObject(GPGraphics, 10, 10);
end;
// what I need in Pascal Script is between these two lines; just pass the interface
// object from the event fired by component to the procedure called from inside it
procedure RenderObject(const GPGraphics: IGPGraphics; X, Y);
begin
// and here to work with the interfaced object somehow
end;
Pascal脚本编译部分:
我的目标是在Pascal脚本中使用具有事件的类,并将该接口对象传递给该过程,就像上面那样。因此,我首先尝试在编译时声明以下内容(但我甚至不确定这是否是正确的方法):
// the interface
PS.AddInterface(Cl.FindInterface('IUnknown'), StringToGuid('{57F85BA4-CB01-4466-8441-948D03588F54}'), 'IGPGraphics');
// the type for the event
PS.AddTypeS('TRenderEvent', 'procedure(Sender: TObject; const GPGraphics: IGPGraphics)');
// and the class with the event itself
with PS.AddClassN(PS.FindClass('TGraphicControl'), 'TRenderClass') do
begin
RegisterProperty('OnRender', 'TRenderEvent', iptrw);
end;
Pascal脚本运行时部分:
我确实迷失在运行时部分。我无法弄清楚如何从调用堆栈中获取接口对象并将其传递给我的RenderObject过程:
function RenderClassProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global,
Stack: TPSStack): Boolean;
var
PStart: Cardinal;
begin
PStart := Stack.Count-1;
Result := True;
if Proc.Name = 'RENDEROBJECT' then
begin
// how do I get the interfaced object from Stack (or whatever else) and pass
// it to the RenderObject proc here ? I can't find anything related about it
// except functions that has no parameter index
RenderObject(Stack.Get ?, Stack.GetInt(PStart-2), Stack.GetInt(PStart-3));
end;
end;
问题是:
有没有人能建议我如何正确定义这种情况下的编译和运行时部分,或者通过某种方式传递接口对象进行修正?
P.S. 对于使用Inno-Setup标签的情况表示抱歉,但也许有来自那里的人尝试过以这种方式自定义InnoSetup。
非常感谢!