Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageCosta 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.
Post Follow-up to this messageSame 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.
Post Follow-up to this messageCosta 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)..
Post Follow-up to this messageI 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)..
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.