TMemoryStreams...

I don't know exactly how to manipulate them.
1. I want to INSERT at beginning a STRING.
2. I want to READ it.
3. I want to concatenate 2 memory streams in another.
Examples please...
cosminmAsked:
Who is Participating?
 
viktornetConnect With a Mentor Commented:
OK MAN.... HOLD ON A SECOND.... and PLEASE stop reject.. i will give you the code in a second... you're not the only one whose answers i answer., okay? have some patience... i'll give you the code in a few minutes...
0
 
EpsylonCommented:
1&2) Use a StringStream instead. You can use ReadString and WriteString then.
3) Stream1.CopyFrom(Stream2, 0) concattenates stream2 to stream1


Epsylon.
0
 
cosminmAuthor Commented:
For concatenating I get the message... It's ok.
But for 1&2 I can't use StringStreams.
I can use only MemoryStreams. Please just tell me how to insert and read bytes or chars and you get the points.

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
viktornetCommented:
use MemStream.Read()
0
 
viktornetCommented:
or MemStream.ReadBuffer()

or use the Memory property and then use the Move() function..

var
  str : string[50];
...
Move(MemStream.Memory^, str, 50);

now STR contains 50 bytes...

this should do it pretty good...

..-=ViKtOr=-..
0
 
cosminmAuthor Commented:
What happened with you guys? I'm a newbie.
Please give me an example!
0
 
viktornetCommented:
okay...

var
  str : string[100];
begin
  MemStream.Read(str, 100);

there you have it.. now str contains the 100 bytes..

..-=ViKtOr=-..
0
 
cosminmAuthor Commented:
STR will contain first 50 bytes from MemStream then?
And how to insert some bytes before MemStream?
0
 
cosminmAuthor Commented:
You don't receive the points so easy :)
Please respond to INSERT part and I give you the points.
I really need it (urgent).
0
 
viktornetCommented:
try something like this..

var
  str : pchar;
  len : integer;
....

len := MemStream.size;
getmem(str, len);
MemStream.Read(str^, len);
MemStream.SetSize(len+Length('SOMETHING_'));
MemStream.Write('SOMETHING', Length('SOMETHING'));
MemStream.Write(str^, len);
freemem(str);
....

this should be something similar to what you need...

btw, I haven't tested and haven't used the help file so I'm not sure if the parameters are right, but as far as I remember they are correct :)

..-=ViKtOr=-..
0
 
viktornetCommented:
you can also use StrMove() and many other functions that work with PChar's which is actually clean memory... and not Delphi's string... which is kinda difficult to work with sometimes....

..-=ViKtOr=-..
0
 
cosminmAuthor Commented:
Ok, I am waiting...
0
 
EpsylonCommented:
var ms: TMemoryStream;
    s: String;
    a: PChar;
begin
  s := 'Hello world';
  ms := TMemoryStream.Create;
  ms.Write(s[1], length(s));

  s := ''; //just resetting
  ms.Position := 0;

  a := AllocMem(ms.Size);
  ms.Read(a[0], ms.Size);
  SetString(s, a, ms.Size);
  FreeMem(a);
  ShowMessage(s);
end;

0
 
cosminmAuthor Commented:
I test them in my program and if I had problems I'll contact you later, ok?
Thank you.
0
 
EpsylonCommented:
AAAAARRRRGGGGGGHHHHHH!!!!!!!!!!!!
0
 
EpsylonCommented:
Viktor, you are annoying me    :O(
0
 
cosminmAuthor Commented:
> AAAAARRRRGGGGGGHHHHHH!!!!!!!!!!!!
viktornet was quicker.... :]
0
 
viktornetCommented:
yeah, sure... if you're having any problems please let me know...
0
 
viktornetCommented:
Epsylon, what the hell is your problem??
0
 
EpsylonCommented:
It's the way you lock answers!
0
 
viktornetCommented:
Epsylon, what is wrong with the way I lock answers?

..-=fOoL=-..
0
 
viktornetCommented:
btw, I ANSWER questions, whereas you refer to that as LOCKING questions, and which you probably do...

..-=fOoL=-..
0
All Courses

From novice to tech pro — start learning today.