[英]OnColumnChanged and OnRowChanged events to TStringGrid
我需要知道何時更改了網格的行/列屬性才能進行一些處理。 在TStringGrid行屬性是
property Row: Longint read FCurrent.Y write SetRow;
但是,不幸的是我無法覆蓋SetRow,因為它是私有的。 SelectCell不是私有的,但在設置新的列和行屬性之前將其稱為。 唯一的解決方案是將所有對Row屬性的調用替換為我自己的屬性
property MyRow: Longint read Row write SetMyRow;
但這不是最優雅的解決方案。 有任何想法嗎?
Delphi 7,Win 7 32位
我只是看了一下TStringGrid
的來源。 Row
屬性是從TCustomGrid
繼承的(通過TDrawGrid
和TCustomDrawGrid
),在此屬性定義為
property Row: Longint read FCurrent.Y write SetRow;
正如你所說。 SetRow
調用FocusCell
后者調用MoveCurrent
。 這稱為SelectCell
。 這是一個虛函數,盡管在TCustomGrid
非常簡單, TCustomGrid
在其中將其定義為
function TCustomGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
Result := True;
end;
在TCustomDrawGrid
,我們有
function TCustomDrawGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
Result := True;
if Assigned(FOnSelectCell) then FOnSelectCell(Self, ACol, ARow, Result);
end;
因此,每次更改Row
或Col
時都會調用OnSelectCell
,如Skamradt在評論中所寫。
是的,在選擇新單元格之前會調用此事件,但是我們有
FOnSelectCell: TSelectCellEvent;
哪里
type
TSelectCellEvent = procedure (Sender: TObject; ACol, ARow: Longint;
var CanSelect: Boolean) of object;
ACol
和ARow
包含新的“ ARow
的價值”。 您甚至可以通過將CanSelect
設置為false
來禁止更改選定的單元格。 因此,無需覆蓋任何內容。
(此外,您不能覆蓋SetRow
因為它不是虛擬的 。非常有可能覆蓋私有成員和受保護的成員,但是只能覆蓋虛擬方法。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.