📄 newdbgrids.~pas
字号:
if cvImeMode in FAssignedValues then
Result := FImeMode
else
Result := DefaultImeMode;
end;
function TColumn.GetImeName: TImeName;
begin
if cvImeName in FAssignedValues then
Result := FImeName
else
Result := DefaultImeName;
end;
function TColumn.GetParentColumn: TColumn;
var
Col: TColumn;
Fld: TField;
I: Integer;
begin
Result := nil;
Fld := Field;
if (Fld <> nil) and (Fld.ParentField <> nil) and (Collection <> nil) then
for I := Index - 1 downto 0 do
begin
Col := TColumn(Collection.Items[I]);
if Fld.ParentField = Col.Field then
begin
Result := Col;
Exit;
end;
end;
end;
function TColumn.GetPickList: TStrings;
begin
if FPickList = nil then
FPickList := TStringList.Create;
Result := FPickList;
end;
function TColumn.GetReadOnly: Boolean;
begin
if cvReadOnly in FAssignedValues then
Result := FReadOnly
else
Result := DefaultReadOnly;
end;
function TColumn.GetShowing: Boolean;
var
Col: TColumn;
begin
Result := not Expanded and Visible;
if Result then
begin
Col := Self;
repeat
Col := Col.ParentColumn;
until (Col = nil) or not Col.Expanded;
Result := Col = nil;
end;
end;
function TColumn.GetVisible: Boolean;
var
Col: TColumn;
begin
Result := FVisible;
if Result then
begin
Col := ParentColumn;
Result := Result and ((Col = nil) or Col.Visible);
end;
end;
function TColumn.GetWidth: Integer;
begin
if not Showing then
Result := -1
else if cvWidth in FAssignedValues then
Result := FWidth
else
Result := DefaultWidth;
end;
function TColumn.IsAlignmentStored: Boolean;
begin
Result := (cvAlignment in FAssignedValues) and (FAlignment <> DefaultAlignment);
end;
function TColumn.IsColorStored: Boolean;
begin
Result := (cvColor in FAssignedValues) and (FColor <> DefaultColor);
end;
function TColumn.IsFontStored: Boolean;
begin
Result := (cvFont in FAssignedValues);
end;
function TColumn.IsImeModeStored: Boolean;
begin
Result := (cvImeMode in FAssignedValues) and (FImeMode <> DefaultImeMode);
end;
function TColumn.IsImeNameStored: Boolean;
begin
Result := (cvImeName in FAssignedValues) and (FImeName <> DefaultImeName);
end;
function TColumn.IsReadOnlyStored: Boolean;
begin
Result := (cvReadOnly in FAssignedValues) and (FReadOnly <> DefaultReadOnly);
end;
function TColumn.IsWidthStored: Boolean;
begin
Result := (cvWidth in FAssignedValues) and (FWidth <> DefaultWidth);
end;
procedure TColumn.RefreshDefaultFont;
var
Save: TNotifyEvent;
begin
if cvFont in FAssignedValues then Exit;
Save := FFont.OnChange;
FFont.OnChange := nil;
try
FFont.Assign(DefaultFont);
finally
FFont.OnChange := Save;
end;
end;
procedure TColumn.RestoreDefaults;
var
FontAssigned: Boolean;
begin
FontAssigned := cvFont in FAssignedValues;
FTitle.RestoreDefaults;
FAssignedValues := [];
RefreshDefaultFont;
FPickList.Free;
FPickList := nil;
ButtonStyle := cbsAuto;
Changed(FontAssigned);
end;
procedure TColumn.SetAlignment(Value: TAlignment);
var
Grid: TCustomDBGrid0;
begin
if IsStored then
begin
if (cvAlignment in FAssignedValues) and (Value = FAlignment) then Exit;
FAlignment := Value;
Include(FAssignedValues, cvAlignment);
Changed(False);
end
else
begin
Grid := GetGrid;
if Assigned(Grid) and (Grid.Datalink.Active) and Assigned(Field) then
Field.Alignment := Value;
end;
end;
procedure TColumn.SetButtonStyle(Value: TColumnButtonStyle);
begin
if Value = FButtonStyle then Exit;
FButtonStyle := Value;
Changed(False);
end;
procedure TColumn.SetColor(Value: TColor);
begin
if (cvColor in FAssignedValues) and (Value = FColor) then Exit;
FColor := Value;
Include(FAssignedValues, cvColor);
Changed(False);
end;
procedure TColumn.SetField(Value: TField);
begin
if FField = Value then Exit;
if Assigned(FField) and (GetGrid <> nil) then
FField.RemoveFreeNotification(GetGrid);
if Assigned(Value) and (csDestroying in Value.ComponentState) then
Value := nil; // don't acquire references to fields being destroyed
FField := Value;
if Assigned(Value) then
begin
if GetGrid <> nil then
FField.FreeNotification(GetGrid);
FFieldName := Value.FullName;
end;
if not IsStored then
begin
if Value = nil then
FFieldName := '';
RestoreDefaults;
end;
Changed(False);
end;
procedure TColumn.SetFieldName(const Value: String);
var
AField: TField;
Grid: TCustomDBGrid0;
begin
AField := nil;
Grid := GetGrid;
if Assigned(Grid) and Assigned(Grid.DataLink.DataSet) and
not (csLoading in Grid.ComponentState) and (Length(Value) > 0) then
AField := Grid.DataLink.DataSet.FindField(Value); { no exceptions }
FFieldName := Value;
SetField(AField);
Changed(False);
end;
procedure TColumn.SetFont(Value: TFont);
begin
FFont.Assign(Value);
Include(FAssignedValues, cvFont);
Changed(False);
end;
procedure TColumn.SetImeMode(Value: TImeMode);
begin
if (cvImeMode in FAssignedValues) or (Value <> DefaultImeMode) then
begin
FImeMode := Value;
Include(FAssignedValues, cvImeMode);
end;
Changed(False);
end;
procedure TColumn.SetImeName(Value: TImeName);
begin
if (cvImeName in FAssignedValues) or (Value <> DefaultImeName) then
begin
FImeName := Value;
Include(FAssignedValues, cvImeName);
end;
Changed(False);
end;
procedure TColumn.SetIndex(Value: Integer);
var
Grid: TCustomDBGrid0;
Fld: TField;
I, OldIndex: Integer;
Col: TColumn;
begin
OldIndex := Index;
Grid := GetGrid;
if IsStored then
begin
Grid.BeginLayout;
try
I := OldIndex + 1; // move child columns along with parent
while (I < Collection.Count) and (TColumn(Collection.Items[I]).ParentColumn = Self) do
Inc(I);
Dec(I);
if OldIndex > Value then // column moving left
begin
while I > OldIndex do
begin
Collection.Items[I].Index := Value;
Inc(OldIndex);
end;
inherited SetIndex(Value);
end
else
begin
inherited SetIndex(Value);
while I > OldIndex do
begin
Collection.Items[OldIndex].Index := Value;
Dec(I);
end;
end;
finally
Grid.EndLayout;
end;
end
else
begin
if (Grid <> nil) and Grid.Datalink.Active then
begin
if Grid.AcquireLayoutLock then
try
Col := Grid.ColumnAtDepth(Grid.Columns[Value], Depth);
if (Col <> nil) then
begin
Fld := Col.Field;
if Assigned(Fld) then
Field.Index := Fld.Index;
end;
finally
Grid.EndLayout;
end;
end;
inherited SetIndex(Value);
end;
end;
procedure TColumn.SetPickList(Value: TStrings);
begin
if Value = nil then
begin
FPickList.Free;
FPickList := nil;
Exit;
end;
PickList.Assign(Value);
end;
procedure TColumn.SetPopupMenu(Value: TPopupMenu);
begin
FPopupMenu := Value;
if Value <> nil then Value.FreeNotification(GetGrid);
end;
procedure TColumn.SetReadOnly(Value: Boolean);
var
Grid: TCustomDBGrid0;
begin
Grid := GetGrid;
if not IsStored and Assigned(Grid) and Grid.Datalink.Active and Assigned(Field) then
Field.ReadOnly := Value
else
begin
if (cvReadOnly in FAssignedValues) and (Value = FReadOnly) then Exit;
FReadOnly := Value;
Include(FAssignedValues, cvReadOnly);
Changed(False);
end;
end;
procedure TColumn.SetTitle(Value: TColumnTitle);
begin
FTitle.Assign(Value);
end;
procedure TColumn.SetWidth(Value: Integer);
var
Grid: TCustomDBGrid0;
TM: TTextMetric;
DoSetWidth: Boolean;
begin
DoSetWidth := IsStored;
if not DoSetWidth then
begin
Grid := GetGrid;
if Assigned(Grid) then
begin
if Grid.HandleAllocated and Assigned(Field) and Grid.FUpdateFields then
with Grid do
begin
Canvas.Font := Self.Font;
GetTextMetrics(Canvas.Handle, TM);
Field.DisplayWidth := (Value + (TM.tmAveCharWidth div 2) - TM.tmOverhang - 3)
div TM.tmAveCharWidth;
end;
if (not Grid.FLayoutFromDataset) or (cvWidth in FAssignedValues) then
DoSetWidth := True;
end
else
DoSetWidth := True;
end;
if DoSetWidth then
begin
if ((cvWidth in FAssignedValues) or (Value <> DefaultWidth))
and (Value <> -1) then
begin
FWidth := Value;
Include(FAssignedValues, cvWidth);
end;
Changed(False);
end;
end;
procedure TColumn.SetVisible(Value: Boolean);
begin
if Value <> FVisible then
begin
FVisible := Value;
Changed(True);
end;
end;
procedure TColumn.SetExpanded(Value: Boolean);
const
Direction: array [Boolean] of ShortInt = (-1,1);
var
Grid: TCustomDBGrid0;
WasShowing: Boolean;
begin
if Value <> FExpanded then
begin
Grid := GetGrid;
WasShowing := (Grid <> nil) and Grid.Columns[Grid.SelectedIndex].Showing;
FExpanded := Value;
Changed(True);
if (Grid <> nil) and WasShowing then
begin
if not Grid.Columns[Grid.SelectedIndex].Showing then
// The selected cell was hidden by this expand operation
// Select 1st child (next col = 1) when parent is expanded
// Select child's parent (prev col = -1) when parent is collapsed
Grid.MoveCol(Grid.Col, Direction[FExpanded]);
end;
end;
end;
function TColumn.Depth: Integer;
var
Col: TColumn;
begin
Result := 0;
Col := ParentColumn;
if Col <> nil then Result := Col.Depth + 1;
end;
function TColumn.GetExpandable: Boolean;
var
Fld: TField;
begin
Fld := Field;
Result := (Fld <> nil) and (Fld.DataType in [ftADT, ftArray]);
end;
{ TDBGridColumns }
constructor TDBGridColumns.Create(Grid: TCustomDBGrid0; ColumnClass: TColumnClass);
begin
inherited Create(ColumnClass);
FGrid := Grid;
end;
function TDBGridColumns.Add: TColumn;
begin
Result := TColumn(inherited Add);
end;
function TDBGridColumns.GetColumn(Index: Integer): TColumn;
begin
Result := TColumn(inherited Items[Index]);
end;
function TDBGridColumns.GetOwner: TPersistent;
begin
Result := FGrid;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -