For Programmers: Free Programming Magazines  


Home > Archive > Delphi > May 2005 > Copy Memorystream to widestring









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Copy Memorystream to widestring
Costa

2005-05-01, 9:10 pm

Hi all,

how can I copy the contents of a memorystream into a widestring?
I can do it for a string, but widestring doesnt work.

procedure TForm1.Button1Click(Sender: TObject);
var
SourceString: widestring;
MemoryStream: TMemoryStream;
begin
.....
MemoryStream.Position := 0;
SetLength(SourceString, MemoryStream.Size);
MemoryStream. ReadBuffer(Pointer(SourceString)^,Memory
Stream.Size);
Caption := SourceString;
....

Can someone help me out? I m stuck.

Thank you.
Jamie

2005-05-01, 9:10 pm

Costa wrote:
> Hi all,
>
> how can I copy the contents of a memorystream into a widestring?
> I can do it for a string, but widestring doesnt work.
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
> SourceString: widestring;
> MemoryStream: TMemoryStream;
> begin
> .....
> MemoryStream.Position := 0;
> SetLength(SourceString, MemoryStream.Size);
> MemoryStream. ReadBuffer(Pointer(SourceString)^,Memory
Stream.Size);
> Caption := SourceString;
> ....
>
> Can someone help me out? I m stuck.
>
> Thank you.

try
ReadBuffer(Pointer(@SourceString[1])^,Me
moryStream.Size);

P.S.
when Setting the Length on Widestrings, the memory hole
normally ends up as twice the size in the widestring.
for example
10 characters = 20 bytes + 2 Bytes for termination.

Costa

2005-05-01, 9:10 pm

Same result. What I basically get is a whole bunch of '?'s as part of
the widestring.

On Sat, 30 Apr 2005 12:14:30 -0700, Jamie
< jamie_5_not_valid_after_5_Please@charter
.net> wrote:

>Costa wrote:
>try
> ReadBuffer(Pointer(@SourceString[1])^,Me
moryStream.Size);
>
> P.S.
> when Setting the Length on Widestrings, the memory hole
>normally ends up as twice the size in the widestring.
> for example
> 10 characters = 20 bytes + 2 Bytes for termination.


Jamie

2005-05-01, 9:10 pm

Costa wrote:

> Same result. What I basically get is a whole bunch of '?'s as part of
> the widestring.
>
> On Sat, 30 Apr 2005 12:14:30 -0700, Jamie
> < jamie_5_not_valid_after_5_Please@charter
.net> wrote:
>
>
>
>

yes, you most likely are!.
Widestring are 2 characters each.
you need to use something that shows
unicode.
also, if you are seeing this at the end of the string it is
because of what i told you before.
widestring is 2 chars each character.
setting the length of the string longer than what memory your
going to transfer into it is going to leave some uninitialized
memory at the 50% mark to the end.
if your trying to fill a WideString with normal chars, i would
suggest to transfer it to a simple string first then simply
assign the WideString from the normal string..
this will help you in converting between the two, the compiler will
fill in the blanks for you. (sort of)..

Costa

2005-05-03, 4:00 am

I think the problem is that the stream (the webpage) contains a
mixture of unicode and normal characters. Is there a way to work
around this?

On Sat, 30 Apr 2005 22:40:16 -0700, Jamie
< jamie_5_not_valid_after_5_Please@charter
.net> wrote:

>Costa wrote:
>
>yes, you most likely are!.
> Widestring are 2 characters each.
> you need to use something that shows
> unicode.
> also, if you are seeing this at the end of the string it is
>because of what i told you before.
> widestring is 2 chars each character.
> setting the length of the string longer than what memory your
>going to transfer into it is going to leave some uninitialized
>memory at the 50% mark to the end.
> if your trying to fill a WideString with normal chars, i would
>suggest to transfer it to a simple string first then simply
>assign the WideString from the normal string..
> this will help you in converting between the two, the compiler will
>fill in the blanks for you. (sort of)..


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com