⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbgrideh.pas

📁 Dbgrid 增强(附源码):支持多表头,多固定列,按表头排序,支持合计列,并支持直接打印
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    property  Increment: Extended read FIncrement write FIncrement stored IsIncrementStored;
    //\\\
  end;

  TColumnEhClass = class of TColumnEh;


  TDBGridColumnsEh = class(TCollection)
  private
    FGrid: TCustomDBGridEh;
    function GetColumn(Index: Integer): TColumnEh;
    function GetState: TDBGridColumnsState;
    procedure SetColumn(Index: Integer; Value: TColumnEh);
    procedure SetState(NewState: TDBGridColumnsState);
  protected
    function GetOwner: TPersistent; override;
    procedure Update(Item: TCollectionItem); override;
  public
    constructor Create(Grid: TCustomDBGridEh; ColumnClass: TColumnEhClass);
    function  Add: TColumnEh;
    procedure LoadFromFile(const Filename: string);
    procedure LoadFromStream(S: TStream);
    procedure RestoreDefaults;
    procedure RebuildColumns;
    procedure SaveToFile(const Filename: string);
    procedure SaveToStream(S: TStream);
    property State: TDBGridColumnsState read GetState write SetState;
    property Grid: TCustomDBGridEh read FGrid;
    property Items[Index: Integer]: TColumnEh read GetColumn write SetColumn; default;
    //ddd
    function  ExistFooterValueType(AFooterValueType:TFooterValueType):Boolean;
    //\\\
  end;

  //ddd
  TColumnsEhList = class(TList)
  private
    function GetColumn(Index: Integer): TColumnEh;
    procedure SetColumn(Index: Integer; const Value: TColumnEh);
  public
    property Items[Index: Integer]: TColumnEh read GetColumn write SetColumn; default;
  end;
  //\\\

  TGridDataLinkEh = class(TDataLink)
  private
    FGrid: TCustomDBGridEh;
    FFieldCount: Integer;
    FFieldMapSize: Integer;
    FFieldMap: Pointer;
    FModified: Boolean;
    FInUpdateData: Boolean;
    FSparseMap: Boolean;
    function GetDefaultFields: Boolean;
    function GetFields(I: Integer): TField;
  protected
    procedure ActiveChanged; override;
    procedure DataSetChanged; override;
    procedure DataSetScrolled(Distance: Integer); override;
    procedure FocusControl(Field: TFieldRef); override;
    procedure EditingChanged; override;
    procedure LayoutChanged; override;
    procedure RecordChanged(Field: TField); override;
    procedure UpdateData; override;
    function  GetMappedIndex(ColIndex: Integer): Integer;
  public
    constructor Create(AGrid: TCustomDBGridEh);
    destructor Destroy; override;
    function AddMapping(const FieldName: string): Boolean;
    procedure ClearMapping;
    procedure Modified;
    procedure Reset;
    property DefaultFields: Boolean read GetDefaultFields;
    property FieldCount: Integer read FFieldCount;
    property Fields[I: Integer]: TField read GetFields;
    property SparseMap: Boolean read FSparseMap write FSparseMap;
  end;

  TBookmarkListEh = class
  private
    FList: TStringList;
    FGrid: TCustomDBGridEh;
    FCache: TBookmarkStr;
    FCacheIndex: Integer;
    FCacheFind: Boolean;
    FLinkActive: Boolean;
    function GetCount: Integer;
    function GetCurrentRowSelected: Boolean;
    function GetItem(Index: Integer): TBookmarkStr;
    procedure SetCurrentRowSelected(Value: Boolean);
    procedure StringsChanged(Sender: TObject);
  protected
    function CurrentRow: TBookmarkStr;
    function Compare(const Item1, Item2: TBookmarkStr): Integer;
    procedure LinkActive(Value: Boolean);
  public
    constructor Create(AGrid: TCustomDBGridEh);
    destructor Destroy; override;
    procedure Clear;           // free all bookmarks
    procedure Delete;          // delete all selected rows from dataset
    function  Find(const Item: TBookmarkStr; var Index: Integer): Boolean;
    function  IndexOf(const Item: TBookmarkStr): Integer;
    function  Refresh: Boolean;// drop orphaned bookmarks; True = orphans found
    //d
    procedure SelectAll;
    //d\
    property Count: Integer read GetCount;
    property CurrentRowSelected: Boolean read GetCurrentRowSelected
      write SetCurrentRowSelected;
    property Items[Index: Integer]: TBookmarkStr read GetItem; default;
  end;


// For MultiTigtle

  THeadTreeNode = class;
  TDBGridEh = class;

  LeafCol = record
    FLeaf:THeadTreeNode;
    FColumn:TColumnEh;
  end;

  PLeafCol = ^LeafCol;
  TLeafCol = array[0..MaxListSize - 1] of LeafCol;
  PTLeafCol = ^TLeafCol;


{  THeadTreeNode }

  THeadTreeProc = procedure (node:THeadTreeNode) of object;
  THeadTreeNode = class(TObject)
  public
    Host:THeadTreeNode;
    Child:THeadTreeNode;
    Next:THeadTreeNode;
    Text:String;
    Height:Integer;
    Width:Integer;
    WIndent:Integer;
    VLineWidth:Integer;
    Drawed:Boolean;
    HeightPrn:Integer;
    WidthPrn:Integer;
    Column:TColumnEh;
    constructor Create;
    constructor CreateText(AText:String;AHeight,AWidth:Integer);
    destructor Destroy; override;
    function Add(AAfter:THeadTreeNode;AText:String;AHeight,AWidth:Integer):THeadTreeNode ;
    function AddChild(ANode:THeadTreeNode;AText:String;AHeight,AWidth:Integer):THeadTreeNode ;
    function Find(ANode:THeadTreeNode):Boolean;
    procedure Union(AFrom,ATo :THeadTreeNode; AText:String;AHeight:Integer);
    procedure FreeAllChild;
    procedure CreateFieldTree(AGrid:TCustomDBGridEh);
    procedure DoForAllNode(proc:THeadTreeProc);
  end;

  TDBGridEhSumList = class(TDBSumListProducer)
  private
    function GetActive: Boolean;
    procedure SetActive(const Value: Boolean);
  public
    constructor Create(AOwner:TComponent);
  published
    property Active: Boolean read GetActive write SetActive default False;
    property ExternalRecalc default False;
    property VirtualRecords default False;
    property SumListChanged;
    property OnRecalcAll;
  end;

  TDBGridEhScrollBar = class(TPersistent)
  private
    FDBGridEh: TCustomDBGridEh;
    FKind: TScrollBarKind;
    FVisible: Boolean;
    FTracking: Boolean;
    procedure SetVisible(Value: Boolean);
  public
    constructor Create(AGrid: TCustomDBGridEh; AKind: TScrollBarKind);
    procedure Assign(Source: TPersistent); override;
    property Kind: TScrollBarKind read FKind;
    function IsScrollBarVisible: Boolean;
  published
    property Tracking: Boolean read FTracking write FTracking default False;
    property Visible: Boolean read FVisible write SetVisible default True;
  end;


// For TCustomDBGridEh

  TDBGridEhOption = (dghFixed3D, dghFrozen3D, dghFooter3D, dghData3D, dghResizeWholeRightPart,
                     dghHighlightFocus, dghClearSelection, dghFitRowHeightToText, dghAutoSortMarking,
                     dghMultiSortMarking);
  TDBGridEhOptions = set of TDBGridEhOption;

  TDBGridEhSelectionType = (gstNon, gstRecordBookmarks, gstRectangle, gstColumns, gstAll);

  TDBCell = record
    Col : Longint;
    Row : TBookmarkStr;
  end;

  TDBGridEhSelectionRect = class(TObject)
  private
    FGrid:TCustomDBGridEh;
    FAnchor:TDBCell;
    FShiftCell:TDBCell;
    function CheckState:Boolean;
    function GetBottomRow: TBookmarkStr;
    function GetLeftCol: Longint;
    function GetRightCol: Longint;
    function GetTopRow: TBookmarkStr;
    function BoxRect(ALeft:Longint; ATop:TBookmarkStr; ARight:Longint; ABottom:TBookmarkStr): TRect;
  public
    constructor Create(AGrid:TCustomDBGridEh);
    procedure Clear;
    procedure Select(ACol :Longint; ARow :TBookmarkStr; AddSel:Boolean);
    function DataCellSelected(DataCol :Longint; DataRow :TBookmarkStr):Boolean;
    property LeftCol : Longint read GetLeftCol;
    property RightCol: Longint read GetRightCol;
    property TopRow   : TBookmarkStr read GetTopRow;
    property BottomRow: TBookmarkStr read GetBottomRow;
  end;

  TDBGridEhSelectionCols = class(TColumnsEhList)
  private
    FGrid:TCustomDBGridEh;
    FAnchor:TColumnEh;
    FShiftCol:TColumnEh;
//    function Get(Index: Integer): TColumnEh;
//    procedure Put(Index: Integer; const Value: TColumnEh);
    procedure Add(ACol: TColumnEh);
  public
    constructor Create(AGrid:TCustomDBGridEh);
    procedure InvertSelect(ACol: TColumnEh);
    procedure Select(ACol: TColumnEh; AddSel:Boolean);
    procedure SelectShift(ACol: TColumnEh; Clear:Boolean);
{$IFDEF EH_LIB_4}
    procedure Clear; override;
{$ELSE}
    procedure Clear;
{$ENDIF}
    procedure Refresh;
//    property Items[Index: Integer]: TColumnEh read Get write Put; default;
  end;

  TDBGridEhSelection = class
  private
    FGrid:TCustomDBGridEh;
    FRect:TDBGridEhSelectionRect;
    FColumns:TDBGridEhSelectionCols;
    FSelectionType:TDBGridEhSelectionType;
    function GetRows: TBookmarkListEh;
    procedure LinkActive(Value: Boolean);
    procedure SetSelectionType(ASelType:TDBGridEhSelectionType);
  public
    constructor Create(AGrid:TCustomDBGridEh);
    destructor Destroy; override;
    function DataCellSelected(DataCol :Longint; DataRow :TBookmarkStr):Boolean;
//    function CellSelected(ACol :Longint; ARow :Longint):Boolean;
    procedure Clear;
    procedure SelectAll;
    procedure Refresh;
    procedure UpdateState;
    property Columns: TDBGridEhSelectionCols read FColumns;
    property SelectionType:TDBGridEhSelectionType read FSelectionType;
    property Rect: TDBGridEhSelectionRect read FRect;
    property Rows: TBookmarkListEh read GetRows;
  end;

  TDBGridEhState = (dgsNormal, dgsRowSelecting, dgsColSelecting, dgsRectSelecting,
                    dgsPosTracing, dgsTitleDown);

  TDBGridEhAllowedOperation = (alopInsertEh, alopUpdateEh, alopDeleteEh, alopAppendEh);
  TDBGridEhAllowedOperations = set of TDBGridEhAllowedOperation;

  { The DBGridEh's DrawDataCell virtual method and OnDrawDataCell event are only
    called when the grid's Columns.State is csDefault.  This is for compatibility
    with existing code. These routines don't provide sufficient information to
    determine which column is being drawn, so the column attributes aren't
    easily accessible in these routines.  Column attributes also introduce the
    possibility that a column's field may be nil, which would break existing
    DrawDataCell code.   DrawDataCell, OnDrawDataCell, and DefaultDrawDataCell
    are obsolete, retained for compatibility purposes. }
(*  TDrawDataCellEvent = procedure (Sender: TObject; const Rect: TRect; Field: TField;
    State: TGridDrawState) of object; *)

  { The DBGridEh's DrawColumnCell virtual method and OnDrawColumnCell event are
    always called, when the grid has defined column attributes as well as when
    it is in default mode.  These new routines provide the additional
    information needed to access the column attributes for the cell being
    drawn, and must support nil fields.  }


  TDrawColumnEhCellEvent = procedure (Sender: TObject; const Rect: TRect;
    DataCol: Integer; Column: TColumnEh; State: TGridDrawState) of object;
  TDBGridEhClickEvent = procedure (Column: TColumnEh) of object;
  TDrawFooterCellEvent = procedure (Sender: TObject; DataCol, Row: Longint;
    Column: TColumnEh; Rect: TRect; State: TGridDrawState) of object;
  TGetFooterParamsEvent = procedure (Sender: TObject; DataCol, Row: Longint;
    Column: TColumnEh; AFont: TFont; var Background: TColor;
    var Alignment : TAlignment; State: TGridDrawState; var Text:String) of object;

  TTitleEhClickEvent = procedure (Sender: TObject; ACol: Longint;
    Column: TColumnEh) of object;
  TCheckTitleEhBtnEvent = procedure (Sender: TObject; ACol: Longint;
    Column: TColumnEh; var Enabled: Boolean) of object;
  TGetBtnEhParamsEvent = procedure (Sender: TObject; Column: TColumnEh;
    AFont: TFont; var Background: TColor; var SortMarker: TSortMarkerEh;
    IsDown: Boolean) of object;
  TGetCellEhParamsEvent = procedure (Sender: TObject; Column: TColumnEh;
    AFont: TFont; var Background: TColor; State: TGridDrawState) of object;

  TCustomDBGridEh = class(TCustomGrid)
  private
    FIndicators: TImageList;
    FTitleFont: TFont;
    FReadOnly: Boolean;
    FOriginalImeName: TImeName;
    FOriginalImeMode: TImeMode;
    FUserChange: Boolean;
    FLayoutFromDataset: Boolean;
    FOptions: TDBGridOptions;
    FTitleOffset, FIndicatorOffset: Byte;
    FUpdateLock: Byte;
    FLayoutLock: Byte;
    FInColExit: Boolean;
    FDefaultDrawing: Boolean;
    FSelfChangingTitleFont: Boolean;
    FSelecting: Boolean;
    FSelRow: Integer;
    FDataLink: TGridDataLinkEh;
    FOnColEnter: TNotifyEvent;
    FOnColExit: TNotifyEvent;
    FOnDrawDataCell: TDrawDataCellEvent;
    FOnDrawColumnCell: TDrawColumnEhCellEvent;
    FEditText: string;
    FColumns: TDBGridColumnsEh;
    FOnEditButtonClick: TNotifyEvent;
    FOnColumnMoved: TMovedEvent;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -