[DUG] Returning a WideString in an Invoke Param
Todd Martin
toddm at kol.co.nz
Tue Jul 18 14:02:46 NZST 2006
Then why not use
FreeMem(Parameters.rgvarg[1].pbstrVal);
GetMem(Parameters.rgvarg[1].pbstrVal,Length(layermanagerid));
Not sure when the string memory is freed though, perhaps when the
TVariantArg is destroyed.
Todd.
----- Original Message -----
From: "Phil Middlemiss" <phil at tumonz.co.nz>
To: "NZ Borland Developers Group - Delphi List" <delphi at ns3.123.co.nz>
Sent: Tuesday, July 18, 2006 1:27 PM
Subject: Re: [DUG] Returning a WideString in an Invoke Param
>I have avoided that one because if I set pbstrVal^ then I'm writing
> directly into memory which should just end up causing an access violation.
>
> Todd Martin wrote:
>> Okay. How about setting the "value" of the widestring pointer.
>>
>> Parameters.rgvarg[1].pbstrVal^ := layermanagerid;
>>
>> ----- Original Message ----- From: "Phil Middlemiss" <phil at tumonz.co.nz>
>> To: "NZ Borland Developers Group - Delphi List" <delphi at ns3.123.co.nz>
>> Sent: Tuesday, July 18, 2006 12:30 PM
>> Subject: Re: [DUG] Returning a WideString in an Invoke Param
>>
>>
>>> Yes, I checked after my initial post, and it is a pbstrVal.
>>>
>>> I can read the value fine. It's writing the value that seems to be the
>>> problem. The Params parameter is a Var parameter so that you can return
>>> values in it if you need to. I tried just pointing the pbstrVal to a new
>>> WideString, but it still ends up an empty string by the time it gets
>>> back to the automation server, so
>>>
>>> Parameters.rgvarg[1].pbstrVal := @layermanagerid;
>>> //layermangerid is a WideString
>>>
>>> doesn't work. I think, as Conor says, I need to construct an OleVariant
>>> to return, but the Parameters.rgvarg[1] still needs to be a pbstrVal.
>>> Not quite sure how to fit the bits together.
>>>
>>> Phil.
>>>
>>> Todd Martin wrote:
>>>> Have you checked the TVarType of parameter 1? Is it actually a bStrVal
>>>> and not pbstrVal?
>>>>
>>>> For pbstrVal just dereference the pointer to an ordinary string
>>>> variable. The conversion is automatic.
>>>>
>>>> var
>>>> myValue : string;
>>>> begin
>>>> myValue := Params.rgvarg[1].pbstrVal^;
>>>> end;
>>>>
>>>>
>>>> ----- Original Message ----- From: "Phil Middlemiss"
>>>> <phil at tumonz.co.nz>
>>>> To: "NZ Borland Developers Group - Delphi List" <delphi at ns3.123.co.nz>
>>>> Sent: Tuesday, July 18, 2006 11:13 AM
>>>> Subject: [DUG] Returning a WideString in an Invoke Param
>>>>
>>>>
>>>>> Hi all,
>>>>>
>>>>> I have an automation object with events. One of the events has a
>>>>> couple
>>>>> of VAR parameters which I'm not quite sure how to handle. Here is the
>>>>> code that is NOT working:
>>>>>
>>>>> procedure TT3SDKEvents.DoInvoke(Sender : TObject; DispID: Integer;
>>>>> const
>>>>> IID: TGUID;
>>>>> LocaleID: Integer; Flags: Word; var Params: TDispParams; VarResult,
>>>>> ExcepInfo,
>>>>> ArgErr: Pointer);
>>>>> case DispID of
>>>>>
>>>>> ...
>>>>>
>>>>> 4: { OnIdentify }
>>>>> if assigned(FOnIdentify) then
>>>>> begin
>>>>> //initialise the values
>>>>> layermanagerid := WideCharToString(Params.rgvarg[1].bStrVal);
>>>>> appname := WideCharToString(Params.rgvarg[0].bstrVal);
>>>>> if assigned(FOnIdentify) then
>>>>> FOnIdentify(layermanagerid, appname);
>>>>> Params.rgvarg[1].bstrVal := PWideChar(layermanagerid);
>>>>> Params.rgvarg[0].bstrVal := PWideChar(appname);
>>>>> end;
>>>>> end;
>>>>> end;
>>>>>
>>>>> The above code just ends up returning an empty string - I've
>>>>> checked to
>>>>> make sure that the call to FOnIdentify is indeed returning values.
>>>>> So the question is: how should I be returning a widestring in the
>>>>> TDispParams?
>>>>>
>>>>> Cheers,
>>>>> Phil.
>>>>>
>>>>
>>>>
>>>> --------------------------------------------------------------------------------
>>>>
>>>>
>>>>
>>>>
>>>>> _______________________________________________
>>>>> Delphi mailing list
>>>>> Delphi at ns3.123.co.nz
>>>>> http://ns3.123.co.nz/mailman/listinfo/delphi
>>>>>
>>>>
>>>>
>>>> --------------------------------------------------------------------------------
>>>>
>>>>
>>>>
>>>>
>>>> No virus found in this incoming message.
>>>> Checked by AVG Free Edition.
>>>> Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date:
>>>> 14/07/2006
>>>>
>>>>
>>>>
>>>
>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>>
>>> _______________________________________________
>>> Delphi mailing list
>>> Delphi at ns3.123.co.nz
>>> http://ns3.123.co.nz/mailman/listinfo/delphi
>>>
>>
>>
>> --------------------------------------------------------------------------------
>>
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date:
>> 14/07/2006
>>
>>
>>
>
--------------------------------------------------------------------------------
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
--------------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date: 14/07/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date: 14/07/2006
More information about the Delphi
mailing list