Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TMemoryStreams...

Posted on 1999-07-24
22
Medium Priority
?
144 Views
Last Modified: 2010-04-04
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...
0
Comment
Question by:cosminm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 5
22 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1390923
1&2) Use a StringStream instead. You can use ReadString and WriteString then.
3) Stream1.CopyFrom(Stream2, 0) concattenates stream2 to stream1


Epsylon.
0
 

Author Comment

by:cosminm
ID: 1390924
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1390925
use MemStream.Read()
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:viktornet
ID: 1390926
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
 

Author Comment

by:cosminm
ID: 1390927
What happened with you guys? I'm a newbie.
Please give me an example!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1390928
okay...

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

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

..-=ViKtOr=-..
0
 

Author Comment

by:cosminm
ID: 1390929
STR will contain first 50 bytes from MemStream then?
And how to insert some bytes before MemStream?
0
 

Author Comment

by:cosminm
ID: 1390930
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
 
LVL 10

Accepted Solution

by:
viktornet earned 400 total points
ID: 1390931
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1390932
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1390933
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
 

Author Comment

by:cosminm
ID: 1390934
Ok, I am waiting...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1390935
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
 

Author Comment

by:cosminm
ID: 1390936
I test them in my program and if I had problems I'll contact you later, ok?
Thank you.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1390937
AAAAARRRRGGGGGGHHHHHH!!!!!!!!!!!!
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1390938
Viktor, you are annoying me    :O(
0
 

Author Comment

by:cosminm
ID: 1390939
> AAAAARRRRGGGGGGHHHHHH!!!!!!!!!!!!
viktornet was quicker.... :]
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1390940
yeah, sure... if you're having any problems please let me know...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1390941
Epsylon, what the hell is your problem??
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1390942
It's the way you lock answers!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1390943
Epsylon, what is wrong with the way I lock answers?

..-=fOoL=-..
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1390944
btw, I ANSWER questions, whereas you refer to that as LOCKING questions, and which you probably do...

..-=fOoL=-..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question