BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Possible to call a dispatch interface with the method name i

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Ian Boyd
Guest





PostPosted: Thu Sep 07, 2006 12:53 am    Post subject: Possible to call a dispatch interface with the method name i Reply with quote



Consider

procedure DoStuff(o: OleVariant; doc: IXMLDOMDocument2)
var
MethodName: string;
Param1, Param2: string;

begin
MethodName := doc.selectSingleNode('/body/foo/method');
Param1 := doc.selectSingleNode('/body/foo/param1');
Param2 := doc.selectSingleNode('/body/foo/param2');

o.MethodName(Param1, Param2);
end;

Problem here is that it will try to call a method named "MethodName" rather
than a method name contained in the MethodName variable.

i know i could use
o.GetIDsOfNames(...)
and pass it MethodName and get it's DispID, but then when calling Invoke i
would be faced with having to figure out how to marshall all the parameters
into those horribly scary parameters of Invoke.

i cannot imagine a syntax for such an animal, except possibly
procedure DispatchInvoke(const MethodName: string; const params: array
of OleVariant);

Was such a thing already written for me?
Back to top
Chris Cheney
Guest





PostPosted: Tue Sep 12, 2006 5:13 pm    Post subject: Re: Possible to call a dispatch interface with the method na Reply with quote



"Ian Boyd" <ian.borlandnews010 (AT) avatopia (DOT) com> wrote in
news:44ff2735 (AT) newsgroups (DOT) borland.com:

Quote:
Consider

procedure DoStuff(o: OleVariant; doc: IXMLDOMDocument2)
var
MethodName: string;
Param1, Param2: string;

begin
MethodName := doc.selectSingleNode('/body/foo/method');
Param1 := doc.selectSingleNode('/body/foo/param1');
Param2 := doc.selectSingleNode('/body/foo/param2');

o.MethodName(Param1, Param2);
end;

Problem here is that it will try to call a method named "MethodName"
rather than a method name contained in the MethodName variable.

i know i could use
o.GetIDsOfNames(...)
and pass it MethodName and get it's DispID, but then when calling
Invoke i would be faced with having to figure out how to marshall all
the parameters into those horribly scary parameters of Invoke.

i cannot imagine a syntax for such an animal, except possibly
procedure DispatchInvoke(const MethodName: string; const params:
array
of OleVariant);

Was such a thing already written for me?

This is code that I use to Invoke with one parameter, but modified for two
parameters:

uses
ActiveX, ComObj;

var
TheLcid: Integer; // set to the LCID

function GetDispId(const Obj: IDispatch; const Member: WideString; var
TheDispId: Integer): Boolean;
begin
Result := Succeeded(Obj.GetIdsOfNames(GUID_NULL, @Member, 1, TheLcid,
@TheDispId));
end;

function InvokeMember(const Obj: IDispatch; const Member: WideString; Arg1,
Arg2: OleVariant; DispatchFlags: Word): IUnknown;
var
TheDispId, ArgErr: Integer;
TheDispParams: TDispParams;
Params: array[0..1]of OleVariant; // NB in reverse order
varResult: Variant;
begin
Result := nil;
if GetDispId(Obj, Member, TheDispId) then
begin
with TheDispParams do
begin
rgvarg := @Params;
rgdispidNamedArgs := nil;
cArgs := 2;
cNamedArgs := 0;
end;
Params[0] := Arg2;
Params[1] := Arg1;
OleCheck(Obj.Invoke(TheDispId,
GUID_NULL,
TheLcid,
DispatchFlags, // DISPATCH_METHOD,
DISPATCH_PROPERTYGET, ...
TheDispParams,
{$IFDEF Delphi6Up}Result{$ELSE}@Result{$ENDIF},
nil,
{$IFDEF Delphi6Up}ArgErr{$ELSE}@ArgErr{$ENDIF}));
Result := IUnknown(varResult);
end;
end;

HTH
Back to top
Ian Boyd
Guest





PostPosted: Wed Sep 13, 2006 12:12 am    Post subject: Re: Possible to call a dispatch interface with the method na Reply with quote



Quote:
This is code that I use to Invoke with one parameter, but modified for two
parameters:


i see. So you actually do put together all the scary parameter stuff...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.