 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Peter Guest
|
Posted: Mon May 16, 2005 12:25 am Post subject: Hide and Seek Getting to know streams |
|
|
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
|
Posted: Mon May 16, 2005 1:51 am Post subject: Re: Hide and Seek Getting to know streams |
|
|
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 |
|
 |
|
|
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
|
|