Page 1 of 1

Multi files in tfilestream or tmemorystream?

PostPosted: March 22nd, 2009, 7:25 pm
by warfighter
Multi files in tfilestream or tmemorystream ?

I join all in a single variable and send the files over the internet, how can I do that ?


I want to learn how? in this example did not result


I do this

Code: Select all
var
me:tmemorystream;
begin
me := tmemorystream.create;

//
to join is correct?
//

me.loadtofile := ('file1');
me.loadtofile := ('file2');
me.loadtofile := ('file3');
socket.sendstream(me);
socket.receivestream(me);

//
as divided now ?
//

end;

Re: Multi files in tfilestream or tmemorystream?

PostPosted: March 23rd, 2009, 9:28 am
by Kambiz
You should define a header for your main stream to include at least size of each file.

Re: Multi files in tfilestream or tmemorystream?

PostPosted: March 29th, 2009, 4:48 pm
by warfighter
can show me an example ?

Re: Multi files in tfilestream or tmemorystream?

PostPosted: March 30th, 2009, 1:43 pm
by Kambiz
In this case, providing an example is like writing the final code. Try to write it by yourself. However, I give you a pseudo code.

Suppose FileArray is an array variable containing the name of files to be stored in the array.

To save files:

Code: Select all
NumOfFiles = Length(FileArray);
SetLength(FileSizeArray, NumOfFiles);
StreamWriteInteger(NumOfFiles);
SreamWriteIntegerArray(FileSizeArray);
for i := 0 to NumOfFiles - 1 do
begin
  FileSizeArray[i] := FileSizeOf(FileArray[i]);
  StreamWriteFile(FileArray[i]);
end;
Stream.Seek(0, soFromBigining);
SreamWriteIntegerArray(FileSizeArray);

and to load files:

Code: Select all
NumOfFiles = StreamReadInteger;
SetLength(FileSizeArray, NumOfFiles);
SreamReadIntegerArray(FileSizeArray);
for i := 0 to NumOfFiles - 1 do
begin
  StreamReadFile(FileArray[i], FileSizeArray[i]);
end;