Search Results for

    Show / Hide Table of Contents

    Query component

    Finally, let’s examine the last component, TfrxIBXQuery. It inherits from TfrxCustomQuery basic class, in which necessary properties are already defined. We only need to define Database property and override SetMaster method. Other methods realization is similar to TfrxIBXTable component.

      TfrxIBXQuery = class(TfrxCustomQuery)
      private
        FDatabase: TfrxIBXDatabase;
        FQuery: TIBQuery;
        procedure SetDatabase(const Value: TfrxIBXDatabase);
      protected
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
        procedure SetMaster(const Value: TDataSource); override;
        procedure SetSQL(Value: TStrings); override;
        function GetSQL: TStrings; override;
      public
        constructor Create(AOwner: TComponent); override;
        constructor DesignCreate(AOwner: TComponent; Flags: Word); override;
        class function GetDescription: String; override;
        procedure BeforeStartReport; override;
        procedure UpdateParams; override;
        property Query: TIBQuery read FQuery;
      published
        property Database: TfrxIBXDatabase read FDatabase write SetDatabase;
      end;
    
    constructor TfrxIBXQuery.Create(AOwner: TComponent);
    begin
      { create component – query }
      FQuery := TIBQuery.Create(nil);
      { assign link to it to DataSet property from basic class – do not forget this line! }
      Dataset := FQuery;
      { assign link to connection to DB by default }
      SetDatabase(nil);
      { after that basic constructor may be called in }
      inherited;
    end;
    
    constructor TfrxIBXQuery.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 TfrxIBXQuery.GetDescription: String;
    begin
      Result := 'IBX Query';
    end;
    
    procedure TfrxIBXQuery.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      inherited;
      if (Operation = opRemove) and (AComponent = FDatabase) then
        SetDatabase(nil);
    end;
    
    procedure TfrxIBXQuery.SetDatabase(const Value: TfrxIBXDatabase);
    begin
      FDatabase := Value;
      if Value <> nil then
        FQuery.Database := Value.Database
      else if IBXComponents <> nil then
        FQuery.Database := IBXComponents.DefaultDatabase
      else
        FQuery.Database := nil;
      DBConnected := FQuery.Database <> nil;
    end;
    
    procedure TfrxIBXQuery.SetMaster(const Value: TDataSource);
    begin
      FQuery.DataSource := Value;
    end;
    
    function TfrxIBXQuery.GetSQL: TStrings;
    begin
      Result := FQuery.SQL;
    end;
    
    procedure TfrxIBXQuery.SetSQL(Value: TStrings);
    begin
      FQuery.SQL := Value;
    end;
    
    procedure TfrxIBXQuery.UpdateParams;
    begin
      { in this method it is sufficient to assign values from Params into FQuery.Params }
      { this is performed via standard procedure }
      frxParamsToTParams(Self, FQuery.Params);
    end;
    
    procedure TfrxIBXQuery.BeforeStartReport;
    begin
      SetDatabase(FDatabase);
    end;
    
    Back to top © 1998-2022 Copyright Fast Reports Inc.