Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Copy Memorystream to widestring
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Costa
05-02-05 02:10 AM


Re: Copy Memorystream to widestring
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.


Report this thread to moderator Post Follow-up to this message
Old Post
Jamie
05-02-05 02:10 AM


Re: Copy Memorystream to widestring
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.


Report this thread to moderator Post Follow-up to this message
Old Post
Costa
05-02-05 02:10 AM


Re: Copy Memorystream to widestring
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)..


Report this thread to moderator Post Follow-up to this message
Old Post
Jamie
05-02-05 02:10 AM


Re: Copy Memorystream to widestring
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)..


Report this thread to moderator Post Follow-up to this message
Old Post
Costa
05-03-05 09:00 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Delphi archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:21 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.