unit Unit1;
 
interface
 
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Menus;
 
type
 
  
 
  TForm1 = class(TForm)
    Button1: TButton;
    Button3: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    Memo3: TMemo;
    Memo4: TMemo;
    Memo5: TMemo;
    Memo6: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    AStream, BStream, CStream,ResultStream,newstream: TMemoryStream;
    ArrStream: Array of TMemoryStream;
    procedure DecompressStream(childstream:TMemoryStream;var ResStream:TMemoryStream; nl:Boolean = false);
    procedure CompressStream(var childstream : array of TMemoryStream; const FText: Array of String; var  ResStream:TMemoryStream);
    function StreamToString(Stream: TStream): String;
    procedure StringToStream(const AString: string; var Stream: TMemoryStream);
    procedure StringsToArray(const AArray : Array of String; var BArray : Array of String);
    
  public
    
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.lfm}
 
 
function TForm1.StreamToString(Stream: TStream): String;
var
   SL:TStringList;
begin
     SL:=TStringList.Create;
     stream.Position := 0;
     SL.LoadFromStream(stream);
     result:=SL.Text;
     SL.Free;
end;
 
procedure TForm1.StringToStream(const AString: string; var Stream: TMemoryStream);
begin
  Stream.Write(AString[1], Length(AString));
end;
 
 
 
procedure TForm1.DecompressStream(childstream:TMemoryStream;var ResStream:TMemoryStream; nl:Boolean = false);
var
   outfile : TMemoryStream;
  i,l,c : Integer;
  s:string;
begin
  
  if nl then
    childstream.Position := 0;
 
 childstream.Read(l,SizeOf(l));       
 
 ResStream := TMemoryStream.create;    
 ResStream.CopyFrom(childstream,l);
end;
 
procedure TForm1.CompressStream(var childstream : array of TMemoryStream; const  FText: Array of String; var ResStream:TMemoryStream);
var
  i,DataSize : Integer;
  s : String;
begin
    for i:= 0 to Length(childstream)-1 do begin
 
      if text<>'' then begin
         childstream[i]:=TMemoryStream.Create;
         StringToStream(FText[i], childstream[i]);
      end;
           
    DataSize := childstream[i].Size;
    ResStream.Write(DataSize,SizeOf(DataSize));
          
    ResStream.CopyFrom(childstream[i], 0);
 
    childstream[i].Free;
    end;
 
 
end;
 
procedure TForm1.StringsToArray(const AArray : Array of String; var BArray : Array of String);
var I:Integer;
begin
 for i:=0 to Length(AArray)-1 do
   BArray[i] :=AArray[i];
end;
 
 
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ResultStream:=TMemoryStream.Create;
 
  SetLength(ArrStream,3);
  CompressStream(ArrStream, [memo1.Text, memo2.Text, memo3.Text], ResultStream);
  ResultStream.SaveToFile(ExtractFileDir(ParamStr(0))+'/11.srt');
  Button3.Enabled:=true;
end;
 
procedure TForm1.Button3Click(Sender: TObject);
begin
 DecompressStream(ResultStream,AStream,true);
 memo4.text:=StreamToString(AStream);
 DecompressStream(ResultStream,BStream,false);
 memo5.text:=StreamToString(BStream);
 DecompressStream(ResultStream,CStream,false);
 memo6.text:=StreamToString(CStream);
end;
 
end.