Tags: contents, copy, delphi, memorystream, procedure, programming, string, widestring, widestringi

Copy Memorystream to widestring

On Programmer » Delphi

4,134 words with 4 Comments; publish: Wed, 30 Apr 2008 20:19:00 GMT; (200101.56, « »)

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.

All Comments

Leave a comment...

  • 4 Comments
    • 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(.delphi.todaysummary.com.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.

      #1; Wed, 30 Apr 2008 20:20:00 GMT
    • 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.delphi.todaysummary.com.charter

      .net> wrote:

      >Costa wrote:

      >try

      > ReadBuffer(Pointer(.delphi.todaysummary.com.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.

      #2; Wed, 30 Apr 2008 20:21:00 GMT
    • 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.delphi.todaysummary.com.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)..

      #3; Wed, 30 Apr 2008 20:22:00 GMT
    • 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.delphi.todaysummary.com.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)..

      #4; Wed, 30 Apr 2008 20:23:00 GMT