📄 jvdbgridfooter.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvDBGridFooter.PAS, released on 2004-08-13.
The Initial Developers of the Original Code are: Fr閐閞ic Leneuf-Magaud
Copyright (c) 2004 Fr閐閞ic Leneuf-Magaud
All Rights Reserved.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
-----------------------------------------------------------------------------
HOW TO USE THIS COMPONENT:
-----------------------------------------------------------------------------
- Put a JvDBGrid or JvDBUltimGrid onto your form;
- Link this component to your grid with the DBGrid property (the DataSource
property is automatically set);
- Open the columns property editor;
- Add any column you need and set the Fieldname property for every column;
- Assign the OnCalculate event to your calculation function.
-----------------------------------------------------------------------------
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvDBGridFooter.pas,v 1.5 2005/02/25 14:37:49 obones Exp $
unit JvDBGridFooter;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNIT_VARIANTS}
Variants,
{$ENDIF HAS_UNIT_VARIANTS}
Sysutils, Classes, ComCtrls,
DB, DBGrids, Grids, JvDBGrid;
type
TJvDBGridFooter = class;
TFooterDataLink = class(TDataLink)
private
FGridFooter: TJvDBGridFooter;
protected
procedure ActiveChanged; override;
procedure DataSetChanged; override;
procedure DataSetScrolled(Distance: Integer); override;
procedure LayoutChanged; override;
public
constructor Create(AFooter: TJvDBGridFooter);
destructor Destroy; override;
end;
TFooterColumn = class(TCollectionItem)
private
FAlignment: TAlignment;
FBevel: TStatusPanelBevel;
FBiDiMode: TBiDiMode;
FDisplayMask: string;
FFieldName: string;
FParentBiDiMode: Boolean;
FStyle: TStatusPanelStyle;
FWidthIfIgnore: Integer;
FCurrentValue: Variant;
procedure SetAlignment(Value: TAlignment);
procedure SetBevel(Value: TStatusPanelBevel);
procedure SetBiDiMode(Value: TBiDiMode);
procedure SetDisplayMask(Value: string);
procedure SetFieldName(Value: string);
procedure SetParentBiDiMode(Value: Boolean);
procedure SetStyle(Value: TStatusPanelStyle);
procedure SetWidthIfIgnore(Value: Integer);
protected
function GetDisplayName: string; override;
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
published
property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
property Bevel: TStatusPanelBevel read FBevel write SetBevel default pbLowered;
property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode default bdLeftToRight;
property DisplayMask: string read FDisplayMask write SetDisplayMask;
property FieldName: string read FFieldName write SetFieldName;
property ParentBiDiMode: Boolean read FParentBiDiMode write SetParentBiDiMode
default True;
property Style: TStatusPanelStyle read FStyle write SetStyle default psText;
property WidthIfIgnore: Integer read FWidthIfIgnore write SetWidthIfIgnore default 64;
end;
TFooterColumns = class(TCollection)
private
FFooterBar: TJvDBGridFooter;
function GetItem(Index: Integer): TFooterColumn;
procedure SetItem(Index: Integer; Value: TFooterColumn);
protected
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(FooterBar: TJvDBGridFooter);
function Add: TFooterColumn;
property Items[Index: Integer]: TFooterColumn read GetItem write SetItem;
end;
TCalculateEvent = procedure(Sender: TJvDBGridFooter; const FieldName: string;
var CalcValue: Variant) of object;
TDisplayTextEvent = procedure(Sender: TJvDBGridFooter; Column: TFooterColumn;
const Value: Variant; var Text: string) of object;
TJvDBGridFooter = class(TStatusBar)
private
FColumns: TFooterColumns;
FDataLink: TFooterDataLink;
FDBGrid: TJvDBGrid;
FIgnoreHorzScrolling: Boolean;
FIgnoreResizing: Boolean;
FOnCalculate: TCalculateEvent;
FOnDisplayText: TDisplayTextEvent;
FJvDBGridLayoutChangeLink: TJvDBGridLayoutChangeLink;
procedure SetColumns(Value: TFooterColumns);
function GetDataSource: TDataSource;
procedure SetDataSource(Value: TDataSource);
procedure SetDBGrid(Value: TJvDBGrid);
procedure SetIgnoreHorzScrolling(Value: Boolean);
procedure SetIgnoreResizing(Value: Boolean);
protected
procedure JvDBGridLayoutChanged(Grid: TJvDBGrid; Kind: TJvDBGridLayoutChangeKind); dynamic;
procedure ReCalc;
procedure DrawPanels; dynamic;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Columns: TFooterColumns read FColumns write SetColumns;
property DataSource: TDataSource read GetDataSource write SetDataSource;
property DBGrid: TJvDBGrid read FDBGrid write SetDBGrid;
property IgnoreHorzScrolling: Boolean read FIgnoreHorzScrolling
write SetIgnoreHorzScrolling default False;
property IgnoreResizing: Boolean read FIgnoreResizing write SetIgnoreResizing
default False;
property Panels stored False; // This property of TStatusBar is hidden
property SizeGrip default False;
property OnCalculate: TCalculateEvent read FOnCalculate write FOnCalculate;
property OnDisplayText: TDisplayTextEvent read FOnDisplayText write FOnDisplayText;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvDBGridFooter.pas,v $';
Revision: '$Revision: 1.5 $';
Date: '$Date: 2005/02/25 14:37:49 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
{ TFooterColumn }
constructor TFooterColumn.Create(Collection: TCollection);
begin
inherited Create(Collection);
FAlignment := taCenter;
FBevel := pbLowered;
FBiDiMode := bdLeftToRight;
FDisplayMask := '';
FFieldName := '';
FParentBiDiMode := True;
FStyle := psText;
FWidthIfIgnore := 64;
FCurrentValue := Null;
end;
procedure TFooterColumn.Assign(Source: TPersistent);
begin
if Source is TFooterColumn then
begin
Alignment := TFooterColumn(Source).Alignment;
Bevel := TFooterColumn(Source).Bevel;
BiDiMode := TFooterColumn(Source).BiDiMode;
DisplayMask := TFooterColumn(Source).DisplayMask;
FieldName := TFooterColumn(Source).FieldName;
ParentBiDiMode := TFooterColumn(Source).ParentBiDiMode;
Style := TFooterColumn(Source).Style;
WidthIfIgnore := TFooterColumn(Source).WidthIfIgnore;
end
else
inherited Assign(Source);
end;
function TFooterColumn.GetDisplayName: string;
begin
Result := FieldName;
if Result = '' then
Result := inherited GetDisplayName;
end;
procedure TFooterColumn.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value Then
begin
FAlignment := Value;
Changed(False);
end;
end;
procedure TFooterColumn.SetBevel(Value: TStatusPanelBevel);
begin
if FBevel <> Value Then
begin
FBevel := Value;
Changed(False);
end;
end;
procedure TFooterColumn.SetBiDiMode(Value: TBiDiMode);
begin
if FBiDiMode <> Value Then
begin
FBiDiMode := Value;
Changed(False);
end;
end;
procedure TFooterColumn.SetDisplayMask(Value: string);
begin
if FDisplayMask <> Value Then
begin
FDisplayMask := Value;
Changed(False);
end;
end;
procedure TFooterColumn.SetFieldName(Value: string);
begin
if FFieldName <> Value Then
begin
FFieldName := Value;
FCurrentValue := Null;
Changed(False);
end;
end;
procedure TFooterColumn.SetParentBiDiMode(Value: Boolean);
begin
if FParentBiDiMode <> Value Then
begin
FParentBiDiMode := Value;
Changed(False);
end;
end;
procedure TFooterColumn.SetStyle(Value: TStatusPanelStyle);
begin
if FStyle <> Value Then
begin
FStyle := Value;
Changed(False);
end;
end;
procedure TFooterColumn.SetWidthIfIgnore(Value: Integer);
begin
if FWidthIfIgnore <> Value Then
begin
FWidthIfIgnore := Value;
Changed(False);
end;
end;
{ TFooterColumns }
constructor TFooterColumns.Create(FooterBar: TJvDBGridFooter);
begin
inherited Create(TFooterColumn);
FFooterBar := FooterBar;
end;
function TFooterColumns.Add: TFooterColumn;
begin
Result := TFooterColumn(inherited Add);
end;
function TFooterColumns.GetOwner: TPersistent;
begin
Result := FFooterBar;
end;
procedure TFooterColumns.Update(Item: TCollectionItem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -