簡體   English   中英

TColumnGrid的OnColumnChanged和OnRowChanged事件

[英]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繼承的(通過TDrawGridTCustomDrawGrid ),在此屬性定義為

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;

因此,每次更改RowCol時都會調用OnSelectCell ,如Skamradt在評論中所寫。

是的,在選擇新單元格之前會調用此事件,但是我們有

FOnSelectCell: TSelectCellEvent;

哪里

type
  TSelectCellEvent = procedure (Sender: TObject; ACol, ARow: Longint;
var CanSelect: Boolean) of object;

AColARow包含新的“ ARow的價值”。 您甚至可以通過將CanSelect設置為false來禁止更改選定的單元格。 因此,無需覆蓋任何內容。

(此外,您不能覆蓋SetRow因為它不是虛擬的 。非常有可能覆蓋私有成員和受保護的成員,但是只能覆蓋虛擬方法。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM