adbgrid.pas
来自「delphi编程控件」· PAS 代码 · 共 2,096 行 · 第 1/5 页
PAS
2,096 行
end;
{TAutoGridGroups}
constructor TAutoGridGroups.Create(AGridLayout : TAutoGridLayout);
begin
inherited Create(TAutoGridGroup);
FGridLayout := AGridLayout;
Add;
end;
destructor TAutoGridGroups.Destroy;
begin
inherited Destroy;
end;
{$IFDEF DELPHI4}
function TAutoGridGroups.GetOwner: TPersistent;
begin
Result := GridLayout;
end;
{$ENDIF}
function TAutoGridGroups.Add : TAutoGridGroup;
begin
GridLayout.BeginDrawGrid;
Result := TAutoGridGroup(inherited Add);
GridLayout.EndDrawGrid;
end;
procedure TAutoGridGroups.Assign(Source: TPersistent);
Var
AGroups : TAutoGridGroups;
AGroup : TAutoGridGroup;
i : Integer;
begin
if(Source is TAutoGridGroups) then begin
AGroups := Source as TAutoGridGroups;
Clear;
for i := 0 to AGroups.Count - 1 do begin
AGroup := Add;
AGroup.Assign(AGroups[i]);
end;
GridLayout.UpdateCustomizingFields;
end else inherited Assign(Source);
end;
function TAutoGridGroups.GetLeftVis : Integer;
begin
Result := 0;
if(Owner <> Nil) And (Owner is TCustomAutoDBGrid) then
Result := TCustomAutoDBGrid(Owner).FLeftVis;
end;
function TAutoGridGroups.GetHeight : Integer;
begin
Result := GridLayout.FGroupFontHeight;
end;
function TAutoGridGroups.GetItem(Index : Integer) : TAutoGridGroup;
begin
Result := TAutoGridGroup(inherited Items[Index]);
end;
function TAutoGridGroups.GetGridOwner : TComponent;
begin
Result := FGridLayout.FOwner;
end;
procedure TAutoGridGroups.SetItem(Index : Integer; Value : TAutoGridGroup);
begin
Items[Index].Assign(Value);
end;
{TAutoGridField}
constructor TAutoGridField.Create(Collection : TCollection);
begin
inherited Create(Collection);
FCaption := LoadStr(ACDB_GRIDNEWFIELD);
FColumn := Nil;
FCustomized := True;
FFont := TFont.Create;
FFont.Assign(DefaultFont);
FFont.OnChange := FontChanged;
FTitleFont := TFont.Create;
FTitleFont.Assign(DefaultTitleFont);
FTitleFont.OnChange := TitleFontChanged;
RestoreDefaults;
end;
destructor TAutoGridField.Destroy;
begin
if (FColumn <> Nil) And (GridLayout.Owner <> Nil)
And Not (csDestroying in GridLayout.Owner.ComponentState) then begin
FColumn.FGridField := Nil;
FColumn.Free;
end;
FFont.Free;
FTitleFont.Free;
inherited Destroy;
end;
procedure TAutoGridField.Assign(Source : TPersistent);
Var
AField : TAutoGridField;
begin
if(Source is TAutoGridField) then begin
AField := Source as TAutoGridField;
FField := AField.FField;
FFieldName := AField.FFieldName;
FColor := AField.FColor;
AssignGridFont(FFont, AField.FFont);
FAlignment := AField.FAlignment;
FReadonly := AField.FReadonly;
FCaption := AField.FCaption;
FTitleColor := AField.FTitleColor;
AssignGridFont(FTitleFont, AField.FTitleFont);
FTitleAlignment := AField.FTitleAlignment;
FAssignedValues := AField.FAssignedValues;
FCustomized := AField.FCustomized;
end else inherited Assign(Source);
end;
procedure TAutoGridField.FontChanged(Sender : TObject);
begin
GridLayout.BeginDrawGrid;
Include(FAssignedValues, gfvFont);
GridLayout.EndDrawGrid;
end;
procedure TAutoGridField.TitleFontChanged(Sender : TObject);
begin
GridLayout.BeginDrawGrid;
Include(FAssignedValues, gfvTitleFont);
GridLayout.EndDrawGrid;
end;
function TAutoGridField.DefaultAlignment : TAlignment;
begin
if Assigned(Field) then
Result := FField.Alignment
else
Result := taLeftJustify;
end;
function TAutoGridField.DefaultCaption : String;
begin
if Assigned(Field) then
Result := FField.DisplayLabel
else Result := FCaption;
end;
function TAutoGridField.DefaultColor : TColor;
begin
if(GridLayout <> nil) then
Result := GridLayout.Color
else Result := clWindow;
end;
function TAutoGridField.DefaultFont : TFont;
begin
Result := GridLayout.Font;
end;
function TAutoGridField.DefaultReadOnly : Boolean;
begin
if Assigned(Field) then
Result := FField.ReadOnly
else Result := False;
end;
function TAutoGridField.DefaultTitleAlignment : TAlignment;
begin
Result := taLeftJustify;
end;
function TAutoGridField.DefaultTitleColor : TColor;
begin
Result := clBtnFace;
end;
function TAutoGridField.DefaultTitleFont : TFont;
begin
Result := GridLayout.ColumnFont;
end;
procedure TAutoGridField.RestoreDefaults;
var
FontAssigned: Boolean;
begin
FontAssigned := gfvFont in FAssignedValues;
FAssignedValues := [];
RefreshDefaultFont;
RefreshDefaultTitleFont;
FAlignment := DefaultAlignment;
FTitleAlignment := DefaultTitleAlignment;
FColor := DefaultColor;
FTitleColor := DefaultTitleColor;
FReadOnly := DefaultReadonly;
Changed(FontAssigned);
end;
function TAutoGridField.GetGridLayout : TAutoGridLayout;
begin
Result := TAutoGridFields(Collection).GridLayout;
end;
procedure TAutoGridField.RefreshDefaultFont;
begin
if (gfvFont in FAssignedValues) then exit;
AssignGridFont(FFont, DefaultFont);
end;
procedure TAutoGridField.RefreshDefaultTitleFont;
begin
if (gfvTitleFont in FAssignedValues) then exit;
AssignGridFont(FTitleFont, DefaultTitleFont);
end;
function TAutoGridField.GetAlignment : TAlignment;
begin
if gfvAlignment in FAssignedValues then
Result := FAlignment
else Result := DefaultAlignment;
end;
function TAutoGridField.GetCaption : String;
begin
if gfvCaption in FAssignedValues then
Result := FCaption
else Result := DefaultCaption;
end;
function TAutoGridField.GetColor : TColor;
begin
if gfvColor in FAssignedValues then
Result := FColor
else Result := DefaultColor;
end;
function TAutoGridField.GetField : TField;
begin
if (FField = Nil) And (Length(FFieldName) > 0)
And Assigned(GridLayout.FDataLink.DataSet) then
with GridLayout.FDatalink.Dataset do
if Active Or (Not DefaultFields) then
SetField(FindField(FieldName));
Result := FField;
end;
function TAutoGridField.GetFont : TFont;
begin
if (gfvFont in FAssignedValues)
or (csLoading in GridLayout.Owner.ComponentState) then
Result := FFont
else Result := DefaultFont;
end;
function TAutoGridField.GetReadOnly : Boolean;
begin
if gfvReadOnly in FAssignedValues then
Result := FReadOnly
else Result := DefaultReadOnly;
end;
function TAutoGridField.GetTitleAlignment : TAlignment;
begin
if gfvTitleAlignment in FAssignedValues then
Result := FTitleAlignment
else Result := DefaultTitleAlignment;
end;
function TAutoGridField.GetTitleColor : TColor;
begin
if gfvTitleColor in FAssignedValues then
Result := FTitleColor
else Result := DefaultTitleColor;
end;
function TAutoGridField.GetTitleFont : TFont;
begin
if gfvTitleFont in FAssignedValues then
Result := FTitleFont
else Result := DefaultTitleFont;
end;
function TAutoGridField.GetDBDefControl : TAutoDBDefControl;
begin
if Not TAutoGridFields(Collection).FGetDefControlFast then
Result := adefctrl.GetDBDefControl(GridLayout.Repository, Field)
else Result := FDBDefControl;
end;
function TAutoGridField.IsAlignmentStored : Boolean;
begin
Result := (gfvAlignment in FAssignedValues) And (FAlignment <> DefaultAlignment);
end;
function TAutoGridField.IsCaptionStored: Boolean;
begin
Result := (gfvCaption in FAssignedValues) and
(FCaption <> DefaultCaption);
end;
function TAutoGridField.IsColorStored : Boolean;
begin
Result := (gfvColor in FAssignedValues) And (FColor <> DefaultColor);
end;
function TAutoGridField.IsFontStored : Boolean;
begin
Result := (gfvFont in FAssignedValues) And (FFont <> DefaultFont);
end;
function TAutoGridField.IsReadOnlyStored : Boolean;
begin
Result := (gfvReadOnly in FAssignedValues) And (FReadOnly <> DefaultReadOnly);
end;
function TAutoGridField.IsTitleAlignmentStored : Boolean;
begin
Result := (gfvTitleAlignment in FAssignedValues) And (FTitleAlignment <> DefaultTitleAlignment);
end;
function TAutoGridField.IsTitleColorStored : Boolean;
begin
Result := (gfvTitleColor in FAssignedValues) And (FTitleColor <> DefaultTitleColor);
end;
function TAutoGridField.IsTitleFontStored : Boolean;
begin
Result := (gfvTitleFont in FAssignedValues) and (FTitleFont <> DefaultTitleFont);
end;
procedure TAutoGridField.SetAlignment(Value : TAlignment);
begin
if (gfvAlignment in FAssignedValues) And (Value = FAlignment) then exit;
FAlignment := Value;
Include(FAssignedValues, gfvAlignment);
Changed(False);
end;
procedure TAutoGridField.SetCaption(Value : String);
begin
if (gfvCaption in FAssignedValues) and (Value = FCaption) then exit;
FCaption := Value;
Include(FAssignedValues, gfvCaption);
Changed(False);
end;
procedure TAutoGridField.SetColor(Value : TColor);
begin
if (gfvColor in FAssignedValues) And (Value = FColor) then exit;
FColor := Value;
Include(FAssignedValues, gfvColor);
Changed(False);
end;
procedure TAutoGridField.SetField(Value : TField);
begin
if FField = Value then exit;
FField := Value;
if Assigned(Value) then begin
FFieldName := Value.FieldName;
if not (gfvCaption in FAssignedValues) then
FCaption := Value.DisplayLabel;
end;
Changed(False);
end;
procedure TAutoGridField.SetFieldName(const Value : String);
Var
AField: TField;
begin
AField := nil;
if Assigned(GridLayout.FDataLink.DataSet) And (Length(Value) > 0)
And Not (csLoading in GridLayout.FOwner.ComponentState) then
AField := GridLayout.FDataLink.DataSet.FindField(Value);
FFieldName := Value;
SetField(AField);
Changed(False);
end;
procedure TAutoGridField.SetFont(Value : TFont);
begin
FFont.Assign(Value);
Changed(False);
end;
procedure TAutoGridField.SetReadOnly(Value : Boolean);
begin
if (gfvReadOnly in FAssignedValues) And (Value = FReadOnly) then exit;
FReadOnly := Value;
Include(FAssignedValues, gfvReadOnly);
Changed(False);
end;
procedure TAutoGridField.SetTitleAlignment(Value : TAlignment);
begin
if (gfvTitleAlignment in FAssignedValues) And (Value = FTitleAlignment) then exit;
FTitleAlignment := Value;
Include(FAssignedValues, gfvTitleAlignment);
Changed(False);
end;
procedure TAutoGridField.SetTitleColor(Value : TColor);
begin
if (gfvTitleColor in FAssignedValues) And (Value = FTitleColor) then exit;
FTitleColor := Value;
Include(FAssignedValues, gfvTitleColor);
Changed(False);
end;
procedure TAutoGridField.SetTitleFo
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?