Link to home
Start Free TrialLog in
Avatar of omarmf
omarmf

asked on

delphi and interbase

Dear experts

  is there any way to make an installar for my application that installs my softwar + interbase so the user do not need to install interbase then the software separetly

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
unit Unit1_Q_21334438;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Registry, IdGlobal, ShellAPI, ComCtrls;

type
  TForm1 = class(TForm)
      spb_Install: TSpeedButton;
      Edit_Target: TEdit;
      Edit_Result: TEdit;
      spb_FireBird: TSpeedButton;
      Memo: TMemo;
      rbt_Overwrite: TRadioButton;
      chbx_Details: TCheckBox;
      ProgressBar: TProgressBar;
      procedure FormCreate(Sender: TObject);
      function  InstallApp: Boolean;
      procedure spb_InstallClick(Sender: TObject);
      procedure spb_FireBirdClick(Sender: TObject);
      procedure chbx_DetailsClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function  CheckAboutFireBird: Boolean;
var
  S:      string;
  Reg:    TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    Reg.LazyWrite := False;
    Reg.OpenKey('SOFTWARE\Firebird Project\Firebird Server\Instances', False);
    S := Reg.ReadString('DefaultInstance');
  finally
    Result := DirectoryExists(S);
    Reg.CloseKey;
    Reg.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if not CheckAboutFireBird then
  begin
    ShellExecute(handle, 'open', PChar('Firebird-1.5.2.4731-Win32.exe'), '', '', SW_SHOWNORMAL);
  end;
end;

function  TForm1.InstallApp: Boolean;
var
  Bexe:   Boolean;
  Bgdb:   Boolean;
  SPath:  string;
  SFile:  string;
  TPath:  string;
  TFile:  string;
begin
  Bexe := True;
  Bgdb := True;
  try
    Memo.Clear;
    ProgressBar.Position := 0;
    SPath := ExtractFilePath(Application.ExeName);
    SFile := SPath + 'App.exe';
    TPath := Edit_Target.Text;
    while (TPath[Length(TPath)]='\') do
      Delete(TPath, Length(TPath), 1);
    ForceDirectories(TPath);
    TFile := TPath + '\App.exe';
    if not FileExists(TFile) then
      Memo.Lines.Add('App.exe is not installed ')
    else
    begin
      Memo.Lines.Add('App.exe is already installed ');
      if (DeleteFIle(TFile)) then
        Memo.Lines.Add('App.exe is deleted ');
    end;
    if not FileExists(TFile) or rbt_Overwrite.Checked then
    begin
      Bexe := CopyFileTo(SFile, TFile);
      case Bexe of
        True: Memo.Lines.Add('Installation of App.exe is successfull');
        else  Memo.Lines.Add('Installation of App.exe is not successfull');
      end;
    end;
    ProgressBar.Position := (ProgressBar.Max div 2);
    SFile := SPath + 'MTV.GDB';
    TFile := TPath + '\MTV.GDB';
    if FileExists(TFile) then
      Memo.Lines.Add('MTV.GDB already exists')
    else
    begin
      Memo.Lines.Add(TFile);
      Bgdb := CopyFileTo(SFile, TFile);
      case Bgdb of
        True: Memo.Lines.Add('Installation of MTV.GDB is successfull');
        else  Memo.Lines.Add('Installation of MTV.GDB is not successfull');
      end;
    end;
  finally
    Result := Bexe and Bgdb;
    ProgressBar.Position := ProgressBar.Max;
  end;
end;

procedure TForm1.spb_InstallClick(Sender: TObject);
var
  S:      string;
begin
  if not CheckAboutFireBird then
  begin
    S := 'Firebird is not Installed. Please install it first.';
  end
  else
  begin
    case InstallApp of
      True: S := 'Installation of App.exe is successfull';
      else  S := 'Installation of App.exe is not successfull';
    end;
    Edit_Result.Text := S;
  end;
end;

procedure TForm1.spb_FireBirdClick(Sender: TObject);
begin
  ShellExecute(handle, 'open', PChar('Firebird-1.5.2.4731-Win32.exe'), '', '', SW_SHOWNORMAL);
end;

procedure TForm1.chbx_DetailsClick(Sender: TObject);
begin
  case chbx_Details.Checked of
    True: Height := 256;
    else  Height := 128;
  end;
end;

end.