Recent

Author Topic: copy MemoryStream to StringStream  (Read 13603 times)

hosune7845

  • Full Member
  • ***
  • Posts: 159
Re: copy MemoryStream to StringStream
« Reply #15 on: June 26, 2017, 06:03:44 am »
Thanks for all answers.

I tried with
Maybe what you want is

Code: Pascal  [Select][+][-]
  1.   repeat
  2.     sValue := comReceive.ReadData;
  3.     AMemStream.Write(sValue[1], Length(sValue));
  4.   until (sValue = '');

But same issue (file does't match).

I think TLazserial makes the problem.

Any idea?


Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: copy MemoryStream to StringStream
« Reply #16 on: June 26, 2017, 06:46:37 am »
What are the differences? What are the size before and after the process? Can you use HexEdit, GHex or other similar program to examine the content and tell us the differences between the file before and after process?

Also, try to send/receive file with smaller size, maybe text file with 20 characters. I ever had problem sending files over network, the results didn't match if the file size is over hundred KB, but ok for small files. After inspection, the problem was hardware issue - the network cable.

hosune7845

  • Full Member
  • ***
  • Posts: 159
Re: copy MemoryStream to StringStream
« Reply #17 on: June 26, 2017, 08:52:59 am »
What are the differences? What are the size before and after the process? Can you use HexEdit, GHex or other similar program to examine the content and tell us the differences between the file before and after process?

Also, try to send/receive file with smaller size, maybe text file with 20 characters. I ever had problem sending files over network, the results didn't match if the file size is over hundred KB, but ok for small files. After inspection, the problem was hardware issue - the network cable.

Thanks for answer.

I solved by converting the byte to string format like :
Code: Pascal  [Select][+][-]
  1. for I := 0 to memstrSend.Size - 1 do s := s + formatfloat('000', memstrSend.ReadByte);
  2.  

« Last Edit: June 26, 2017, 09:04:38 am by hosune7845 »

Thaddy

  • Hero Member
  • *****
  • Posts: 14363
  • Sensorship about opinions does not belong here.
Re: copy MemoryStream to StringStream
« Reply #18 on: June 26, 2017, 12:44:38 pm »
Better would be to use setstring for read and cast to pchar on write or if you want slightly less inefficient code, do it like this:
Code: Pascal  [Select][+][-]
  1. for I := 0 to memstrSend.Size - 1 do s := s + ansichar(memstrSend.ReadByte));
  2.  

Better would be:
Code: Pascal  [Select][+][-]
  1. SetString(s,PAnsiChar(MemstrSend.Memory),MemStrSend.Size);
  2.  
That's all in one go.

Note that it is good practise to specify a char or string more exact. So use AnsiChar instead of Char etc, because otherwise it is not always obvious what kind of char or string you mean.
« Last Edit: June 26, 2017, 03:05:32 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018