Search Results for

    Show / Hide Table of Contents

    Table component

    Next component is TfrxIBXTable. It inherits from TfrxCustomDataSet standard class. All basic functionality (operating with list of fields, master-detail, basic properties) is already realized in basic class. We only need to define properties, which are specific to the given component.

      TfrxIBXTable = class(TfrxCustomTable)
      private
        FDatabase: TfrxIBXDatabase;
        FTable: TIBTable;
        procedure SetDatabase(const Value: TfrxIBXDatabase);
      protected
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
        procedure SetMaster(const Value: TDataSource); override;
        procedure SetMasterFields(const Value: String); override;
        procedure SetIndexFieldNames(const Value: String); override;
        procedure SetIndexName(const Value: String); override;
        procedure SetTableName(const Value: String); override;
        function GetIndexFieldNames: String; override;
        function GetIndexName: String; override;
        function GetTableName: String; override;
      public
        constructor Create(AOwner: TComponent); override;
        constructor DesignCreate(AOwner: TComponent; Flags: Word); override;
        class function GetDescription: String; override;
        procedure BeforeStartReport; override;
        property Table: TIBTable read FTable;
      published
        property Database: TfrxIBXDatabase read FDatabase write SetDatabase;
      end;
    
    constructor TfrxIBXTable.Create(AOwner: TComponent);
    begin
      { create component – table }
      FTable := TIBTable.Create(nil);
      { assign link to  DataSet property from  basic class – do not forget this string! }
      DataSet := FTable;
      { assign link to connection to DB by default }
      SetDatabase(nil);
      { after that basic constructor may be called in}
      inherited;
    end;
    
    { this constructor is called at moment of adding components to report. It connects table to TfrxIBXDatabase component automatically, if it is already present. }
    constructor TfrxIBXTable.DesignCreate(AOwner: TComponent; Flags: Word);
    var
      i: Integer;
      l: TList;
    begin
      inherited;
      l := Report.AllObjects;
      for i := 0 to l.Count - 1 do
        if TObject(l[i]) is TfrxIBXDatabase then
        begin
          SetDatabase(TfrxIBXDatabase(l[i]));
          break;
        end;
    end;
    
    class function TfrxIBXTable.GetDescription: String;
    begin
      Result := 'IBX Table';
    end;
    
    { trace TfrxIBXDatabase component deleting. We address this component in FDatabase property. Otherwise we can get error. }
    procedure TfrxIBXTable.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      inherited;
      if (Operation = opRemove) and (AComponent = FDatabase) then
        SetDatabase(nil);
    end;
    
    procedure TfrxIBXTable.SetDatabase(const Value: TfrxIBXDatabase);
    begin
      {  Database property of TfrxIBXDatabase type, and not of TIBDatabase one! }
      FDatabase := Value;
      { if value <> nil, connect table to selected component }
      if Value <> nil then
        FTable.Database := Value.Database
      { otherwise, try to connect to DB by default, defined in TfrxIBXComponents component }
      else if IBXComponents <> nil then
        FTable.Database := IBXComponents.DefaultDatabase
      { if there were no TfrxIBXComponents for some reason, reset to nil }
      else
        FTable.Database := nil;
      { if connection was a success DBConnected flag should be put }
      DBConnected := FTable.Database <> nil;
    end;
    
    function TfrxIBXTable.GetIndexFieldNames: String;
    begin
      Result := FTable.IndexFieldNames;
    end;
    
    function TfrxIBXTable.GetIndexName: String;
    begin
      Result := FTable.IndexName;
    end;
    
    function TfrxIBXTable.GetTableName: String;
    begin
      Result := FTable.TableName;
    end;
    
    procedure TfrxIBXTable.SetIndexFieldNames(const Value: String);
    begin
      FTable.IndexFieldNames := Value;
    end;
    
    procedure TfrxIBXTable.SetIndexName(const Value: String);
    begin
      FTable.IndexName := Value;
    end;
    
    procedure TfrxIBXTable.SetTableName(const Value: String);
    begin
      FTable.TableName := Value;
    end;
    
    procedure TfrxIBXTable.SetMaster(const Value: TDataSource);
    begin
      FTable.MasterSource := Value;
    end;
    
    procedure TfrxIBXTable.SetMasterFields(const Value: String);
    begin
      FTable.MasterFields := Value;
      FTable.IndexFieldNames := Value;
    end;
    
    { we need to implement this method in some cases }
    procedure TfrxIBXTable.BeforeStartReport;
    begin
      SetDatabase(FDatabase);
    end;
    
    Back to top © 1998-2022 Copyright Fast Reports Inc.