Search Results for

    Show / Hide Table of Contents

    Property editors

    It is recommended to place property editors code in a separate file with Editor suffix. In our case, it was necessary to write editors for TfrxIBXDatabase.DatabaseName, TfrxIBXTable.IndexName, TfrxIBXTable.TableName properties. See more about writing properties editors in corresponding chapter. Below is example of such file:

    unit frxIBXEditor;
    
    interface
    {$I frx.inc}
    
    implementation
    
    uses
      Windows, Classes, SysUtils, Forms, Dialogs, frxIBXComponents, frxCustomDB,
      frxDsgnIntf, frxRes, IBDatabase, IBTable
    {$IFDEF Delphi6}
    , Variants
    {$ENDIF};
    
    type
      TfrxDatabaseNameProperty = class(TfrxStringProperty)
      public
        function GetAttributes: TfrxPropertyAttributes; override;
        function Edit: Boolean; override;
      end;
    
      TfrxTableNameProperty = class(TfrxStringProperty)
      public
        function GetAttributes: TfrxPropertyAttributes; override;
        procedure GetValues; override;
      end;
    
      TfrxIndexNameProperty = class(TfrxStringProperty)
      public
        function GetAttributes: TfrxPropertyAttributes; override;
        procedure GetValues; override;
      end;
    
    { TfrxDatabaseNameProperty }
    function TfrxDatabaseNameProperty.GetAttributes: TfrxPropertyAttributes;
    begin
      { this property possesses  editor }
      Result := [paDialog];
    end;
    
    function TfrxDatabaseNameProperty.Edit: Boolean;
    var
      SaveConnected: Bool;
      db: TIBDatabase;
    begin
      { get link to TfrxIBXDatabase.Database }
      db := TfrxIBXDatabase(Component).Database;
      { create standard OpenDialog }
      with TOpenDialog.Create(nil) do
      begin
        InitialDir := GetCurrentDir;
        { we are interested in *.gdb files }
        Filter := frxResources.Get('ftDB') + ' (*.gdb)|*.gdb|' + frxResources.Get('ftAllFiles') + ' (*.*)|*.*';
        Result := Execute;
        if Result then
        begin
          SaveConnected := db.Connected;
          db.Connected := False;
          { if dialogue is completed successfully, assign new DB name }
          db.DatabaseName := FileName;
          db.Connected := SaveConnected;
        end;
        Free;
      end;
    end;
    
    { TfrxTableNameProperty }
    function TfrxTableNameProperty.GetAttributes: TfrxPropertyAttributes;
    begin
      {  property represents list of values }
      Result := [paMultiSelect, paValueList];
    end;
    
    procedure TfrxTableNameProperty.GetValues;
    var
      t: TIBTable;
    begin
      inherited;
      { get link to  TIBTable  component }
      t := TfrxIBXTable(Component).Table;
      { fill list of tables available }
      if t.Database <> nil then
        t.DataBase.GetTableNames(Values, False);
    end;
    
    { TfrxIndexProperty }
    function TfrxIndexNameProperty.GetAttributes: TfrxPropertyAttributes;
    begin
      {  property represents list of values }
      Result := [paMultiSelect, paValueList];
    end;
    
    procedure TfrxIndexNameProperty.GetValues;
    var
      i: Integer;
    begin
      inherited;
      try
        { get link to TIBTable component }
        with TfrxIBXTable(Component).Table do
          if (TableName <> '') and (IndexDefs <> nil) then
          begin
            { update indexes }
            IndexDefs.Update;
            { fill list of indexes available }
            for i := 0 to IndexDefs.Count - 1 do
              if IndexDefs[i].Name <> '' then
                Values.Add(IndexDefs[i].Name);
          end;
      except
      end;
    end;
    
    initialization
      frxPropertyEditors.Register(TypeInfo(String), TfrxIBXDataBase, 'DatabaseName', TfrxDataBaseNameProperty);
      frxPropertyEditors.Register(TypeInfo(String), TfrxIBXTable, 'TableName', TfrxTableNameProperty);
      frxPropertyEditors.Register(TypeInfo(String), TfrxIBXTable, 'IndexName', TfrxIndexNameProperty);
    end.
    
    Back to top © 1998-2022 Copyright Fast Reports Inc.