Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-10

libtar Question

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hello all,

The question is " how to use the create function for adding a new file to an existing archive without deleting all it contents ?"

Here is a piece of code which always replace the first file by the second one. (and I dont want to open only once the tarfile).
Any help is welcome

*********************snip*********************
unit Unit1;
{$mode objfpc}{$H+}
interface

uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,

  StdCtrls, RichMemo,LibTar;
type
  { TForm1 }
  TForm1 = class(TForm)
    Button1: TButton;
    RichMemo1: TRichMemo;
    RichMemo2: TRichMemo;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
var
  Form1: TForm1;
implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
TA : TTArWriter;
Memo1Str,Memo2Str : TMemoryStream;
begin
  Memo1Str:=   TMemoryStream.create;
  Memo2Str:=   TMemoryStream.create;
  if RichMemo1.SaveRichText(Memo1Str)then ShowMessage('Memo1 saved');
   TA:=TTarWriter.Create('c:\test.tar');
  TA.AddStream(  Memo1Str, 'c:\Mmo1',now);
  TA.free;
    TA:=TTarWriter.Create('c:\test.tar',fmOpenReadWrite);
  TA.AddStream(  Memo2Str, 'c:\MMo2',now);
  if RichMemo2.SaveRichText(Memo2Str)then ShowMessage('Memo2 saved');
   TA.free;
   Memo1Str.free;
  Memo2Str.free;
end;
initialization
  {$I unit1.lrs}
end.