给rar文件加个自定义头

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    edt2: TEdit;
    lbl1: TLabel;
    dlgOpen1: TOpenDialog;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
  i:Integer;
  sFile:string;
  ms:TMemoryStream;
  buf:string;
begin
  ms:= TMemoryStream.Create;
  try
  if dlgOpen1.Execute then
  begin
    sfile:= dlgOpen1.FileName;
    ms.LoadFromFile(sFile);
    //ms.Position:=ms.Size;
    buf:= edt2.Text;

    ms.Seek(0,soFromBeginning);
    ms.WriteBuffer(buf,SizeOf(buf));
    ms.SaveToFile(ChangeFileExt(sFile,'.a'));
  end;
  finally
    ms.Free;
  end;
end;

procedure TForm1.btn2Click(Sender: TObject);
var
  i:Integer;
  sFile:string;
  ms1,ms2:TMemoryStream;
  buf:string;
begin
  ms1:= TMemoryStream.Create;
  ms2:= TMemoryStream.Create;
  try
    if dlgOpen1.Execute then
    begin
      sfile:= dlgOpen1.FileName;
      ms1.LoadFromFile(sFile);
      ms1.Seek(SizeOf(edt2.Text),soFromBeginning);
      ms1.WriteBuffer(buf,SizeOf(buf));
      ms2.Position:=0;
      ms2.ReadBuffer(buf,SizeOf(buf));
     
      ms2.SaveToFile(ChangeFileExt(sFile,'.b'));
    end;
  finally
    ms1.Free;
    ms2.Free;
  end;
end;

end.
posted @ 2020-01-09 09:33  创新创造学习整合套路  阅读(258)  评论(0编辑  收藏  举报