BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hide and Seek Getting to know streams

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Peter
Guest





PostPosted: Mon May 16, 2005 12:25 am    Post subject: Hide and Seek Getting to know streams Reply with quote



Hi

I want to embed picture files with text files and save it as a stream file
to disk.

Is this how to do it. I measure each files size in bytes. I then combine
both the files. Using this bytes measurement. I use this measurement to
save the newly created file. And then do the reverse to open the fire. That
means I need to save the bytes size data as well in this created file..

How do I do this.. If any one could point me to some examples of what I am
chatting about .. That would be great..




Cheers Peter......



Back to top
Nils Haeck
Guest





PostPosted: Mon May 16, 2005 1:51 am    Post subject: Re: Hide and Seek Getting to know streams Reply with quote



Hi Peter,

You can use something like:

procedure MyDocument.SaveToStream(S: TStream);
var
M: TMemoryStream;
begin
M := TMemoryStream.Create;
try
// Save a picture
MyJpeg.SaveToStream(M);
Count := M.Size;
S.Write(Count, SizeOf(Count));
M.Position := 0;
S.CopyFrom(M, Count);

// Save a text
M.Clear;
MyStringList.SaveToStream(M);
Count := M.Size;
S.Write(Count, SizeOf(Count));
M.Position := 0;
S.CopyFrom(M, Count);
finally
M.Free;
end;
end;

procedure MyDocument.LoadFromStream(S: TStream);
var
M: TMemoryStream;
begin
M := TMemoryStream.Create;
try
// Load a picture
S.Read(Count, SizeOf(Count));
M.CopyFrom(S, Count);
M.Position := 0;
MyJpeg.LoadFromStream(M);

// Load a text
M.Clear;
S.Read(Count, SizeOf(Count));
M.CopyFrom(S, Count);
M.Position := 0;
MyStringList.LoadFromStream(M);
finally
M.Free;
end;
end;

and of course you can add Load/Save FromFile, this is a good way:

procedure MyDocument.LoadFromFile(const Filename: string);
var
S: TFileStream;
begin
S := TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone);
try
LoadFromStream(S);
finally
S.Free;
end;
end;

Figure out the SaveToFile yourself :)

Kind regards,

Nils
www.simdesign.nl

"Peter" <inver (AT) nospam (DOT) nz> schreef in bericht
news:4287e871 (AT) newsgroups (DOT) borland.com...
Quote:
Hi

I want to embed picture files with text files and save it as a stream file
to disk.

Is this how to do it. I measure each files size in bytes. I then combine
both the files. Using this bytes measurement. I use this measurement to
save the newly created file. And then do the reverse to open the fire.
That means I need to save the bytes size data as well in this created
file..

How do I do this.. If any one could point me to some examples of what I am
chatting about .. That would be great..




Cheers Peter......






Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.