📄 rxdbctrl.pas
字号:
ftMemo: Result := Ord(gpMemo);
ftGraphic: Result := Ord(gpPicture);
ftTypedBinary: Result := Ord(gpBlob);
ftFmtMemo: Result := Ord(gpMemo);
ftParadoxOle, ftDBaseOle: Result := Ord(gpOle);
{$IFDEF RX_D3}
ftCursor: Result := Ord(gpData);
{$ENDIF}
{$IFDEF RX_D4}
ftReference, ftDataSet: Result := Ord(gpData);
{$ENDIF}
{$IFDEF RX_D5}
ftOraClob: Result := Ord(gpMemo);
ftOraBlob: Result := Ord(gpBlob);
{$ENDIF}
end;
end;
end;
function TRxDBGrid.ActiveRowSelected: Boolean;
var
Index: Integer;
begin
Result := False;
if MultiSelect and Datalink.Active then begin
Result := SelectedRows.Find(Datalink.DataSet.Bookmark, Index);
end;
end;
function TRxDBGrid.HighlightCell(DataCol, DataRow: Integer;
const Value: string; AState: TGridDrawState): Boolean;
begin
Result := ActiveRowSelected;
if not Result then
Result := inherited HighlightCell(DataCol, DataRow, Value, AState);
end;
procedure TRxDBGrid.ToggleRowSelection;
begin
if MultiSelect and Datalink.Active then
with SelectedRows do CurrentRowSelected := not CurrentRowSelected;
end;
function TRxDBGrid.GetSelCount: Longint;
begin
if MultiSelect and (Datalink <> nil) and Datalink.Active then
Result := SelectedRows.Count
else Result := 0;
end;
procedure TRxDBGrid.SelectAll;
var
ABookmark: TBookmark;
begin
if MultiSelect and DataLink.Active then begin
with Datalink.Dataset do begin
if (BOF and EOF) then Exit;
DisableControls;
try
ABookmark := GetBookmark;
try
First;
while not EOF do begin
SelectedRows.CurrentRowSelected := True;
Next;
end;
finally
try
GotoBookmark(ABookmark);
except
end;
FreeBookmark(ABookmark);
end;
finally
EnableControls;
end;
end;
end;
end;
procedure TRxDBGrid.UnselectAll;
begin
if MultiSelect then begin
SelectedRows.Clear;
FSelecting := False;
end;
end;
procedure TRxDBGrid.GotoSelection(Index: Longint);
begin
if MultiSelect and DataLink.Active and (Index < SelectedRows.Count) and
(Index >= 0) then
Datalink.DataSet.GotoBookmark(Pointer(SelectedRows[Index]));
end;
procedure TRxDBGrid.LayoutChanged;
var
ACol: Longint;
begin
ACol := Col;
inherited LayoutChanged;
if Datalink.Active and (FixedCols > 0) then
{$IFDEF RX_D4}
Col := Min(Max(CalcLeftColumn, ACol), ColCount - 1);
{$ELSE}
Col := Min(Max(inherited FixedCols, ACol), ColCount - 1);
{$ENDIF}
end;
procedure TRxDBGrid.ColWidthsChanged;
var
ACol: Longint;
begin
ACol := Col;
inherited ColWidthsChanged;
if Datalink.Active and (FixedCols > 0) then
{$IFDEF RX_D4}
Col := Min(Max(CalcLeftColumn, ACol), ColCount - 1);
{$ELSE}
Col := Min(Max(inherited FixedCols, ACol), ColCount - 1);
{$ENDIF}
end;
function TRxDBGrid.CreateEditor: TInplaceEdit;
begin
Result := inherited CreateEditor;
TEdit(Result).OnChange := EditChanged;
end;
function TRxDBGrid.GetTitleOffset: Byte;
{$IFDEF RX_D4}
var
I, J: Integer;
{$ENDIF}
begin
Result := 0;
if dgTitles in Options then begin
Result := 1;
{$IFDEF RX_D4}
if (Datalink <> nil) and (Datalink.Dataset <> nil) and
Datalink.Dataset.ObjectView then
begin
for I := 0 to Columns.Count - 1 do begin
if Columns[I].Showing then begin
J := Columns[I].Depth;
if J >= Result then Result := J + 1;
end;
end;
end;
{$ENDIF}
end;
end;
procedure TRxDBGrid.SetColumnAttributes;
begin
inherited SetColumnAttributes;
SetFixedCols(FFixedCols);
end;
procedure TRxDBGrid.SetFixedCols(Value: Integer);
var
FixCount, I: Integer;
begin
FixCount := Max(Value, 0) + IndicatorOffset;
if DataLink.Active and not (csLoading in ComponentState) and
(ColCount > IndicatorOffset + 1) then
begin
FixCount := Min(FixCount, ColCount - 1);
inherited FixedCols := FixCount;
for I := 1 to Min(FixedCols, ColCount - 1) do
TabStops[I] := False;
end;
FFixedCols := FixCount - IndicatorOffset;
end;
function TRxDBGrid.GetFixedCols: Integer;
begin
if DataLink.Active then Result := inherited FixedCols - IndicatorOffset
else Result := FFixedCols;
end;
{$IFDEF RX_D4}
function TRxDBGrid.CalcLeftColumn: Integer;
begin
Result := FixedCols + IndicatorOffset;
while (Result < ColCount) and (ColWidths[Result] <= 0) do
Inc(Result);
end;
{$ENDIF}
procedure TRxDBGrid.KeyDown(var Key: Word; Shift: TShiftState);
var
KeyDownEvent: TKeyEvent;
procedure ClearSelections;
begin
if FMultiSelect then begin
if FClearSelection then SelectedRows.Clear;
FSelecting := False;
end;
end;
procedure DoSelection(Select: Boolean; Direction: Integer);
var
AddAfter: Boolean;
begin
AddAfter := False;
BeginUpdate;
try
if MultiSelect and DataLink.Active then
if Select and (ssShift in Shift) then begin
if not FSelecting then begin
FSelectionAnchor := TBookmarks(SelectedRows).CurrentRow;
SelectedRows.CurrentRowSelected := True;
FSelecting := True;
AddAfter := True;
end
else with TBookmarks(SelectedRows) do begin
AddAfter := Compare(CurrentRow, FSelectionAnchor) <> -Direction;
if not AddAfter then CurrentRowSelected := False;
end
end
else ClearSelections;
if Direction <> 0 then Datalink.DataSet.MoveBy(Direction);
if AddAfter then SelectedRows.CurrentRowSelected := True;
finally
EndUpdate;
end;
end;
procedure NextRow(Select: Boolean);
begin
with Datalink.Dataset do begin
DoSelection(Select, 1);
if AutoAppend and EOF and CanModify and (not ReadOnly) and (dgEditing in Options) then
Append;
end;
end;
procedure PriorRow(Select: Boolean);
begin
DoSelection(Select, -1);
end;
procedure CheckTab(GoForward: Boolean);
var
ACol, Original: Integer;
begin
ACol := Col;
Original := ACol;
if MultiSelect and DataLink.Active then
while True do begin
if GoForward then Inc(ACol) else Dec(ACol);
if ACol >= ColCount then begin
ClearSelections;
ACol := IndicatorOffset;
end
else if ACol < IndicatorOffset then begin
ClearSelections;
ACol := ColCount;
end;
if ACol = Original then Exit;
if TabStops[ACol] then Exit;
end;
end;
function DeletePrompt: Boolean;
var
S: string;
begin
if (SelectedRows.Count > 1) then
S := ResStr(SDeleteMultipleRecordsQuestion)
else S := ResStr(SDeleteRecordQuestion);
Result := not (dgConfirmDelete in Options) or
(MessageDlg(S, mtConfirmation, [mbYes, mbNo], 0) = mrYes);
end;
begin
KeyDownEvent := OnKeyDown;
if Assigned(KeyDownEvent) then KeyDownEvent(Self, Key, Shift);
if not Datalink.Active or not CanGridAcceptKey(Key, Shift) then Exit;
with Datalink.DataSet do
if ssCtrl in Shift then begin
if (Key in [VK_UP, VK_PRIOR, VK_DOWN, VK_NEXT, VK_HOME, VK_END]) then
ClearSelections;
case Key of
VK_LEFT:
if FixedCols > 0 then begin
{$IFDEF RX_D4}
SelectedIndex := CalcLeftColumn - IndicatorOffset;
{$ELSE}
SelectedIndex := FixedCols;
{$ENDIF}
Exit;
end;
VK_DELETE:
if not ReadOnly and CanModify and not
IsDataSetEmpty(Datalink.DataSet) then
begin
if DeletePrompt then begin
if SelectedRows.Count > 0 then SelectedRows.Delete
else Delete;
end;
Exit;
end;
end
end
else begin
case Key of
VK_LEFT:
if (FixedCols > 0) and not (dgRowSelect in Options) then begin
{$IFDEF RX_D4}
if SelectedIndex <= CalcLeftColumn - IndicatorOffset then
Exit;
{$ELSE}
if SelectedIndex <= FFixedCols then Exit;
{$ENDIF}
end;
VK_HOME:
if (FixedCols > 0) and (ColCount <> IndicatorOffset + 1) and
not (dgRowSelect in Options) then
begin
{$IFDEF RX_D4}
SelectedIndex := CalcLeftColumn - IndicatorOffset;
{$ELSE}
SelectedIndex := FixedCols;
{$ENDIF}
Exit;
end;
end;
if (Datalink.DataSet.State = dsBrowse) then begin
case Key of
VK_UP:
begin
PriorRow(True); Exit;
end;
VK_DOWN:
begin
NextRow(True); Exit;
end;
end;
end;
if ((Key in [VK_LEFT, VK_RIGHT]) and (dgRowSelect in Options)) or
((Key in [VK_HOME, VK_END]) and ((ColCount = IndicatorOffset + 1)
or (dgRowSelect in Options))) or (Key in [VK_ESCAPE, VK_NEXT,
VK_PRIOR]) or ((Key = VK_INSERT) and (CanModify and
(not ReadOnly) and (dgEditing in Options))) then
ClearSelections
else if ((Key = VK_TAB) and not (ssAlt in Shift)) then
CheckTab(not (ssShift in Shift));
end;
OnKeyDown := nil;
try
inherited KeyDown(Key, Shift);
finally
OnKeyDown := KeyDownEvent;
end;
end;
procedure TRxDBGrid.SetShowGlyphs(Value: Boolean);
begin
if FShowGlyphs <> Value then begin
FShowGlyphs := Value;
Invalidate;
end;
end;
procedure TRxDBGrid.SetRowsHeight(Value: Integer);
begin
if not (csDesigning in ComponentState) and (DefaultRowHeight <> Value) then
begin
DefaultRowHeight := Value;
if dgTitles in Options then RowHeights[0] := Value + 2;
if HandleAllocated then
Perform(WM_SIZE, SIZE_RESTORED, MakeLong(ClientWidth, ClientHeight));
end;
end;
function TRxDBGrid.GetRowsHeight: Integer;
begin
Result := DefaultRowHeight;
end;
function TRxDBGrid.GetOptions: TDBGridOptions;
begin
Result := inherited Options;
if FMultiSelect then Result := Result + [dgMultiSelect]
else Result := Result - [dgMultiSelect];
end;
procedure TRxDBGrid.SetOptions(Value: TDBGridOptions);
var
NewOptions: TGridOptions;
begin
inherited Options := Value - [dgMultiSelect];
NewOptions := TDrawGrid(Self).Options;
{
if FTitleButtons then begin
TDrawGrid(Self).Options := NewOptions + [goFixedHorzLine, goFixedVertLine];
end else
}
begin
if not (dgColLines in Value) then
NewOptions := NewOptions - [goFixedVertLine];
if not (dgRowLines in Value) then
NewOptions := NewOptions - [goFixedHorzLine];
TDrawGrid(Self).Options := NewOptions;
end;
SetMultiSelect(dgMultiSelect in Value);
end;
procedure TRxDBGrid.Paint;
begin
inherited Paint;
if not (csDesigning in ComponentState) and
(dgRowSelect in Options) and DefaultDrawing and Focused then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -