Показать сообщение отдельно
  #3  
Старый 13.05.2014, 23:12
Virus191288 Virus191288 вне форума
Прохожий
 
Регистрация: 24.08.2009
Сообщения: 2
Репутация: 10
По умолчанию

Спасибо за подсказку на я уже все сделал. Вот пример:
Код:
unit Unit1;

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Menus;

type

  { TForm1 }

  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);
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

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
  //restart
  if nl then
    childstream.Position := 0;

 childstream.Read(l,SizeOf(l));       //read stream

 ResStream := TMemoryStream.create;    //copy to new stream
 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.
п.с. каждый раз узнаю что-то новое, например что в процедуру можно передать элементы в виде масива))
п.п.с. код сложный и скорее всего кривой
Ответить с цитированием