4
votes

I have a COM server App that and need to link callbacks to specific events which are late bound.

My test VB script is as follows

Sub Main
  dim Frm
  Set Frm=NewForm("Form1")
  Frm.OnActivate = getRef("Frm_OnActivate")
  a= Frm.Showmodal
end Sub

sub Frm_OnActivate
  MsgBox("Activate")
end Sub

My com server has the onActivate property which is of type OleVariant.

function TALform.Get_OnActivate: OleVariant;
begin
  result:=FonActivate;
end;

procedure TALform.Set_OnActivate(Value: OleVariant);
begin
  FonActivate:=Value;
  Fform.OnActivate:=OnactivateEx
end;

My question is, having got that value, how do I call the VBscript function from the value stored in the Olevariant (which the debugger shows to be of type VarDispatch) ?

1

1 Answers

3
votes

Try something like this:

var
    Param: TDispParams;
    MethodResult: OleVariant;
    Result: HRESULT;
begin
    Param.rgvarg := nil;
    Param.rgdispidNamedArgs := nil;
    Param.cArgs := 0;
    Param.cNamedArgs := 0;
    Result := IDispatch(FonActivate).Invoke(0, GUID_NULL, SysLocale.DefaultLCID, DISPATCH_METHOD, Param, @MethodResult, nil, nil);
end;