Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Create a Stub Program to support Self-Extracting Archives

STUB - Full Source Code

By Zarko Gajic, About.com

How to Create a Stub Program to support Self-Extracting Archives

Here's the full source code to a sample STUB program. Download the heavily documented version.

~~~~~~~~~~~~~~~~~~~~~~~~~
program SelfStub;
{$DEFINE BuildingStub}

uses
   AbArcTyp,
   AbUnzPrc,
   AbUtils,
   AbZipTyp,
   Dialogs,
   SysUtils;

type
   THelper = class
   public
     procedure UnzipProc(Sender : TObject; Item : TAbArchiveItem; const NewName : string) ;
   end;

var
   ZipArchive : TAbZipArchive;
   Helper : THelper;
   PWord: string;
   Entered: Boolean;

procedure THelper.UnzipProc(Sender : TObject; Item : TAbArchiveItem; const NewName : string) ;
begin
   if (Item.IsEncrypted) and (Entered = False) then
     begin
       PWord := InputBox('PCB Zip-Archive Is Password Protected', 'Archive created by PCB Zip' + #13#10 + #13#10 + 'Enter password:' + #13#10 + #13#10 + 'NOTE that PCB Zip ASSUMES that all files were' + #13#10 + 'archived with the same password!!!','') ;
       Entered := True;
     end;
   ZipArchive.Password := PWord;
   AbUnzip(Sender, TAbZipItem(Item), NewName) ;
end;

begin //program starts here
   Entered := False;
   PWord := '';
   ZipArchive := TAbZipArchive.Create(ParamStr(0), fmOpenRead or fmShareDenyNone) ;
   ChDir(ExtractFilePath(ParamStr(0))) ;

   Helper := THelper.Create;
   try
     ZipArchive.Load;
     ZipArchive.ExtractHelper := Helper.UnzipProc;
     ZipArchive.ExtractFiles('*.*') ;
   finally
     Helper.Free;
     ZipArchive.Free;
   end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. How to Create a Stub Program to support Self-Extracting Archives

©2009 About.com, a part of The New York Times Company.

All rights reserved.