Search Results for

    Show / Hide Table of Contents

    Database component

    The following component is TfrxIBXDatabase one. It represents a wrapper over TIBDatabase.

      TfrxIBXDatabase = class(TfrxCustomDatabase)
      private
        FDatabase: TIBDatabase;
        FTransaction: TIBTransaction;
        function GetSQLDialect: Integer;
        procedure SetSQLDialect(const Value: Integer);
      protected
        procedure SetConnected(Value: Boolean); override;
        procedure SetDatabaseName(const Value: String); override;
        procedure SetLoginPrompt(Value: Boolean); override;
        procedure SetParams(Value: TStrings); override;
        function GetConnected: Boolean; override;
        function GetDatabaseName: String; override;
        function GetLoginPrompt: Boolean; override;
        function GetParams: TStrings; override;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        class function GetDescription: String; override;
        procedure SetLogin(const Login, Password: String); override;
        property Database: TIBDatabase read FDatabase;
      published
        { list TIBDatabase properties. Note – some properties are already exist in base class }
        property DatabaseName;
        property LoginPrompt;
        property Params;
        property SQLDialect: Integer read GetSQLDialect write SetSQLDialect;
        {  Connected property should be placed last! }
        property Connected;
      end;
    
    constructor TfrxIBXDatabase.Create(AOwner: TComponent);
    begin
      inherited;
      { create component – connection }
      FDatabase := TIBDatabase.Create(nil);
      { create component - transaction (specificity of  IBX) }
      FTransaction := TIBTransaction.Create(nil);
      FDatabase.DefaultTransaction := FTransaction;
      { do not forget this line! }
      Component := FDatabase;
    end;
    
    destructor TfrxIBXDatabase.Destroy;
    begin
      { delete  transaction }
      FTransaction.Free;
      { connection will be deleted automatically in parent class }
      inherited;
    end;
    
    { component description will be displayed next to icon in objects toolbar }
    class function TfrxIBXDatabase.GetDescription: String;
    begin
      Result := 'IBX Database';
    end;
    
    { redirect component properties to  cover properties and vice versa }
    function TfrxIBXDatabase.GetConnected: Boolean;
    begin
      Result := FDatabase.Connected;
    end;
    
    function TfrxIBXDatabase.GetDatabaseName: String;
    begin
      Result := FDatabase.DatabaseName;
    end;
    
    function TfrxIBXDatabase.GetLoginPrompt: Boolean;
    begin
      Result := FDatabase.LoginPrompt;
    end;
    
    function TfrxIBXDatabase.GetParams: TStrings;
    begin
      Result := FDatabase.Params;
    end;
    
    function TfrxIBXDatabase.GetSQLDialect: Integer;
    begin
      Result := FDatabase.SQLDialect;
    end;
    
    procedure TfrxIBXDatabase.SetConnected(Value: Boolean);
    begin
      FDatabase.Connected := Value;
      FTransaction.Active := Value;
    end;
    
    procedure TfrxIBXDatabase.SetDatabaseName(const Value: String);
    begin
      FDatabase.DatabaseName := Value;
    end;
    
    procedure TfrxIBXDatabase.SetLoginPrompt(Value: Boolean);
    begin
      FDatabase.LoginPrompt := Value;
    end;
    
    procedure TfrxIBXDatabase.SetParams(Value: TStrings);
    begin
      FDatabase.Params := Value;
    end;
    
    procedure TfrxIBXDatabase.SetSQLDialect(const Value: Integer);
    begin
      FDatabase.SQLDialect := Value;
    end;
    
    { this method is used by DB connection wizard }
    procedure TfrxIBXDatabase.SetLogin(const Login, Password: String);
    begin
      Params.Text := 'user_name=' + Login + #13#10 + 'password=' + Password;
    end;
    

    As you can see, this is not that complicated. We create FDatabase: TIBDatabase object, and then define properties we want the designer to have. “Get” and “Set” methods are written for each property.

    Back to top © 1998-2022 Copyright Fast Reports Inc.