Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

convert string to widestring in Delphi

696 views
Skip to first unread message

Sean

unread,
Feb 5, 2003, 2:51:36 PM2/5/03
to
I just wasted 4 hours so maybe I can save some of your time.
Assigning a string to a widestring such as in:

var
wString: wideString;
nString: string;
begin
nString := 'hello';
wString := nString;
end;

works fine UNLESS the nString is greater than 4096 characters, in
which case the assignment to wString results in a empty string.

Sean

Mikael Mann

unread,
Feb 5, 2003, 11:54:13 PM2/5/03
to
delphicon...@yahoo.com (Sean) wrote in <c9b4f122.0302051151.7e92c8e7
@posting.google.com>:


What version of Delphi?

I have seen other problems with explicit conversion from WideString to
string, such as in: DoSomething([string(OneHelluvaWideString))]).

When the called function uses "array of const", and you include an
explicitly converted WideString as part of the array, all kinds of trouble
may occur - memory corruption, invalid string ref-counts etc. I've only
seen this happen in Delphi 5.0 though.

- M.m.

Sean

unread,
Feb 6, 2003, 3:29:19 PM2/6/03
to
> What version of Delphi?
>
> I have seen other problems with explicit conversion from WideString to
> string, such as in: DoSomething([string(OneHelluvaWideString))]).
>
> When the called function uses "array of const", and you include an
> explicitly converted WideString as part of the array, all kinds of trouble
> may occur - memory corruption, invalid string ref-counts etc. I've only
> seen this happen in Delphi 5.0 though.

I'm using Delphi 5. I'm thinking it has more to do with a COM
limitation than a Delphi limitation because the WideString I was
assigning to was a parameter in a COM call.

Sean

Mikael Mann

unread,
Feb 7, 2003, 7:10:02 AM2/7/03
to
delphicon...@yahoo.com (Sean) wrote in
<c9b4f122.03020...@posting.google.com>:


Funny you say that, because the WideString in my case was also coming from
a COM call (this was in a server-app).

My solution, anyways, was simply to drop the explicit conversion, and let
Delphi do the conversion automagically.


- M.m.

0 new messages