Multi files in tfilestream or tmemorystream?

Please discuss general Delphi programming topics here.

Multi files in tfilestream or tmemorystream?

Postby warfighter » March 22nd, 2009, 7:25 pm

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;
warfighter
Active Member
Active Member
 
Posts: 11
Joined: March 17th, 2009, 5:56 pm

Re: Multi files in tfilestream or tmemorystream?

Postby Kambiz » March 23rd, 2009, 9:28 am

You should define a header for your main stream to include at least size of each file.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Multi files in tfilestream or tmemorystream?

Postby warfighter » March 29th, 2009, 4:48 pm

can show me an example ?
warfighter
Active Member
Active Member
 
Posts: 11
Joined: March 17th, 2009, 5:56 pm

Re: Multi files in tfilestream or tmemorystream?

Postby Kambiz » March 30th, 2009, 1:43 pm

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;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron