📄 jvdbgridfooter.pas
字号:
begin
FFooterBar.DrawPanels;
end;
function TFooterColumns.GetItem(Index: Integer): TFooterColumn;
begin
Result := TFooterColumn(inherited GetItem(Index));
end;
procedure TFooterColumns.SetItem(Index: Integer; Value: TFooterColumn);
begin
inherited SetItem(Index, Value);
end;
{ TFooterDataLink }
constructor TFooterDataLink.Create(AFooter: TJvDBGridFooter);
begin
inherited Create;
FGridFooter := AFooter;
VisualControl := True;
end;
destructor TFooterDataLink.Destroy;
begin
FGridFooter := nil;
inherited Destroy;
end;
procedure TFooterDataLink.DataSetScrolled(Distance: Integer);
begin
// Don't remove this empty procedure. It prevents DataSetChanged
// from recalculating the footer values for every cursor move.
end;
procedure TFooterDataLink.ActiveChanged;
begin
DataSetChanged;
end;
procedure TFooterDataLink.DataSetChanged;
begin
if FGridFooter <> nil then
FGridFooter.ReCalc;
end;
procedure TFooterDataLink.LayoutChanged;
begin
if FGridFooter <> nil then
FGridFooter.DrawPanels;
end;
{ TJvDBGridFooter }
constructor TJvDBGridFooter.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FJvDBGridLayoutChangeLink := TJvDBGridLayoutChangeLink.Create;
FJvDBGridLayoutChangeLink.OnChange := JvDBGridLayoutChanged;
FColumns := TFooterColumns.Create(Self);
FDataLink := TFooterDataLink.Create(Self);
FDBGrid := nil;
FIgnoreHorzScrolling := False;
FIgnoreResizing := False;
SizeGrip := False;
end;
destructor TJvDBGridFooter.Destroy;
begin
if Assigned(FDBGrid) then
FDBGrid.UnregisterLayoutChangeLink(FJvDBGridLayoutChangeLink);
FJvDBGridLayoutChangeLink.Free;
FDataLink.Free;
FDataLink := nil;
FColumns.Free;
inherited Destroy;
end;
procedure TJvDBGridFooter.SetColumns(Value: TFooterColumns);
begin
FColumns.Assign(Value);
end;
function TJvDBGridFooter.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TJvDBGridFooter.SetDataSource(Value: TDataSource);
begin
if Assigned(DBGrid) then
if Value <> DBGrid.DataSource then
Value := DBGrid.DataSource;
FDataLink.DataSource := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
procedure TJvDBGridFooter.SetDBGrid(Value: TJvDBGrid);
begin
if FDBGrid <> Value then
begin
if Assigned(FDBGrid) then
FDBGrid.UnregisterLayoutChangeLink(FJvDBGridLayoutChangeLink);
FDBGrid := Value;
if Assigned(FDBGrid) then
begin
DataSource := FDBGrid.DataSource;
FDBGrid.RegisterLayoutChangeLink(FJvDBGridLayoutChangeLink);
end;
end;
end;
procedure TJvDBGridFooter.SetIgnoreHorzScrolling(Value: Boolean);
begin
if FIgnoreHorzScrolling <> Value then
begin
FIgnoreHorzScrolling := Value;
DrawPanels;
end;
end;
procedure TJvDBGridFooter.SetIgnoreResizing(Value: Boolean);
begin
if FIgnoreResizing <> Value then
begin
FIgnoreResizing := Value;
DrawPanels;
end;
end;
procedure TJvDBGridFooter.JvDBGridLayoutChanged(Grid: TJvDBGrid; Kind: TJvDBGridLayoutChangeKind);
begin
case Kind of
lcLayoutChanged:
DrawPanels;
lcSizeChanged:
DrawPanels;
lcTopLeftChanged:
DrawPanels;
end;
end;
procedure TJvDBGridFooter.ReCalc;
var
C: Integer;
begin
for C := 0 to Columns.Count - 1 do
if FDataLink.Active and Assigned(OnCalculate) then
OnCalculate(Self, Columns.Items[C].FieldName, Columns.Items[C].FCurrentValue)
else
Columns.Items[C].FCurrentValue := Null;
DrawPanels;
end;
procedure TJvDBGridFooter.DrawPanels;
procedure CreatePanel(const GCol: Integer);
var
C: Integer;
Found: Boolean;
CurrentValue: Variant;
NewText: string;
begin
if DBGrid.Columns[GCol].Visible then
with Panels.Add do
begin
Found := False;
for C := 0 to Columns.Count - 1 do
if AnsiSameText(Columns.Items[C].FieldName, DBGrid.Columns[GCol].FieldName) then
begin
Found := True;
Alignment := Columns.Items[C].Alignment;
Bevel := Columns.Items[C].Bevel;
BiDiMode := Columns.Items[C].BiDiMode;
ParentBiDiMode := Columns.Items[C].ParentBiDiMode;
Style := Columns.Items[C].Style;
CurrentValue := Columns.Items[C].FCurrentValue;
if (CurrentValue = Null) and Assigned(OnCalculate) then
OnCalculate(Self, Columns.Items[C].FieldName, CurrentValue);
if CurrentValue = Null then
Text := ''
else
if Trim(Columns.Items[C].DisplayMask) <> '' then
begin
case VarType(CurrentValue) of
varSmallint,
varInteger:
Text := Format(Columns.Items[C].DisplayMask, [Integer(CurrentValue)]);
varSingle,
varDouble:
Text := Format(Columns.Items[C].DisplayMask, [Double(CurrentValue)]);
varCurrency:
Text := Format(Columns.Items[C].DisplayMask, [Currency(CurrentValue)]);
varDate:
Text := Format(Columns.Items[C].DisplayMask, [TDateTime(CurrentValue)]);
else
Text := string(CurrentValue);
end;
end
else
Text := string(CurrentValue);
if IgnoreResizing then
Width := Columns.Items[C].WidthIfIgnore
else
Width := DBGrid.Columns[GCol].Width;
if Assigned(OnDisplayText) then
begin
NewText := Text;
OnDisplayText(Self, Columns.Items[C], CurrentValue, NewText);
Text := NewText;
end;
Break;
end;
if not Found then
begin
Bevel := pbNone;
Style := psText;
Text := '';
if IgnoreResizing then
Width := 0
else
Width := DBGrid.Columns[GCol].Width;
end;
if dgColLines in DBGrid.Options then
Width := Width + TDrawGrid(DBGrid).GridLineWidth;
end;
end;
var
I,
FirstPanel,
LastPanel: Integer;
begin
Panels.Clear;
if Assigned(DBGrid) and not SimplePanel then
begin
Panels.BeginUpdate;
try
// Datasource checking
if DataSource <> DBGrid.DataSource then
DataSource := DBGrid.DataSource;
// Indicator panel
if dgIndicator in DBGrid.Options then
with Panels.Add do
begin
Bevel := pbNone;
Style := psText;
Text := '';
Width := IndicatorWidth;
if dgColLines in DBGrid.Options then
Width := Width + TDrawGrid(DBGrid).GridLineWidth;
end;
// Fixed cols panels
for I := 0 to DBGrid.FixedCols - 1 do
CreatePanel(I);
// Movable cols panels
if IgnoreHorzScrolling then
begin
FirstPanel := DBGrid.FixedCols;
LastPanel := DBGrid.Columns.Count - 1;
end
else
begin
if dgIndicator in DBGrid.Options then
FirstPanel := DBGrid.LeftCol - 1
else
FirstPanel := DBGrid.LeftCol;
LastPanel := FirstPanel + DBGrid.VisibleColCount;
if LastPanel >= DBGrid.Columns.Count then
LastPanel := DBGrid.Columns.Count - 1;
end;
for I := FirstPanel to LastPanel do
CreatePanel(I);
// Ending panel
with Panels.Add do
begin
Bevel := pbNone;
Style := psText;
Text := '';
Width := 1;
end;
finally
Panels.EndUpdate;
end;
end;
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -