Board index » delphi » Strange WideString bug

Strange WideString bug

I have COM component that instantiates another COM component and calls
its method. All parameters for the call are WideStrings. When I
debuged second COM component and lookedd at call parameters, they
where all empty strings though I knew for sure that they should be not
empty.
After short investigation it turned out that PWideString(Argument)
wasn't empty. Means that string length in parameter[0] was set to 0.
Unfortunately, I can not get to it to set it to right value without
trickery. And it is, obviously, a bug. Only strings that are longer
then 1023 characters behave this way.
I had to use ss2:=WideCharToString(@Parameter[1]) in order to retrieve
the value. Does anybody know how to fix it? Patches to Delphi?  I use
D5 Enterprize with updates installed..
    Slava
 

Re:Strange WideString bug


  I'm not sure if it will help you or not, but whenever we take in a
WideString parameter value in a COM call, we immediately assign it to a
local string variable.  Then we pass that local variable to any other COM
calls that need it (even if their parameters are also defined as
WideString).  Likewise, beofre returning a value as a WideString result (or
out or var parameter), we build it in a local string variable and then
assign Result (or the var or out parameter) the value of that local string
variable.  Also, we never use WideString *except* as a parameter or result
of an inteface method...within our internal COM objects' code we only define
and pass string variables.  These practices have solved the headaches you
are describing, at least for us.  Hope this helps...
-Howard

Re:Strange WideString bug


Never seen this bug. I know the IDE de{*word*81} has a bug that sometimes it
does correctly display WideString values. Also, for WideStrings, s[0] is not
necessarily the string length - WideString/BSTR variables are not the same
as Delphi shortstring variables.

If you have to call WideCharToString to arrive at the correct value, then
the caller is not passing the string in as a BSTR. It is likely that the
caller passed in a z-terminated unicode string (^array of WideChars). Note
that a BSTR/WideString is not semantically the same as an array of
WideChars.

--
have fun
Binh Ly
http://www.techvanguards.com

Quote
"Slava Uchitel" <slava.uchi...@dsiddoms.eds.com> wrote in message

news:3bbb084e.77167015@newsgroups.borland.com...
Quote
> I have COM component that instantiates another COM component and calls
> its method. All parameters for the call are WideStrings. When I
> debuged second COM component and lookedd at call parameters, they
> where all empty strings though I knew for sure that they should be not
> empty.
> After short investigation it turned out that PWideString(Argument)
> wasn't empty. Means that string length in parameter[0] was set to 0.
> Unfortunately, I can not get to it to set it to right value without
> trickery. And it is, obviously, a bug. Only strings that are longer
> then 1023 characters behave this way.
> I had to use ss2:=WideCharToString(@Parameter[1]) in order to retrieve
> the value. Does anybody know how to fix it? Patches to Delphi?  I use
> D5 Enterprize with updates installed..
>     Slava

Other Threads