德尔福部分:
我有一类事件,并从该事件中,我需要调用一个程序接口的对象传递给它。 它工作正常在Delphi中,但我有在Pascal脚本宣布它的问题。
到背景- IGPGraphics
接口是的一部分Delphi GDI+ library
并且没有被定义像这样的方法:
type
IGdiplusBase = interface
['{24A5D3F5-4A9B-42A2-9F60-20825E2740F5}']
IGPGraphics = interface(IGdiPlusBase)
['{57F85BA4-CB01-4466-8441-948D03588F54}']
以下仅仅是我所需要的Pascal脚本做一个简化的德尔福伪代码:
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脚本运行时的部分:
凡我肯定失去是运行时的一部分。 我无法弄清楚如何从调用堆栈获取接口对象,并把它传递给我的渲染对象的过程:
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;
而问题是:
任何人都可以建议我如何正确定义编译和运行一部分这种情况下或以某种方式传递接口对象指正?
PS为InnoSetup标签抱歉,但也许从那里有人试图自定义InnoSetup这样。
非常感谢!