Helo.
I cerate my own TTMSFNCGridCell class and i'd like to access to Owner. But FOwner is only private member.
Helo.
I cerate my own TTMSFNCGridCell class and i'd like to access to Owner. But FOwner is only private member.
Why do you need access to the Owner? the Owner is the grid. The cell class is not a real child of the grid it acts as a container for drawing.
I know that owner is the grid. I handle MouseMove metod and i use FOwner to get TTMSFNCGridCellRec.
procedure TMyGridCell.HandleMouseMove(Shift: TShiftState; X, Y: Single; var AHandled: Boolean; var ACursor: TCursor);
var
cellXY: TTMSFNCGridCellRec;
begin
inherited;
if FOwner is TTMSFNCGrid then
begin
cellXY := TTMSFNCGrid(FOwner).XYToCell(X,Y);
... some other code ...
end;
end;
Can you please explain a bit more in detail what it is that you want to achieve?
I create something as a component in a cell. Yes It's mostly drawing, because according to mine knowledge TTMSFNCGrid does not support TComponents in cells. I use TTMSFNCGridCell to achieve this. This object can process all the events which i need (mouse move, mouse down, mouse up etc). And now i need access to TTMSFNCGridData.Objects property for example. That's why I need access to owner. Now i have solution, but it's embarrassing but it's functional.
type
TMyGridCell= class(TTMSFNCGridCell)
private
FAwkwardOwner: TComponent; // :(
public
constructor Create(AOwner: TComponent); override;
end;
constructor TMyGridCell.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAwkwardOwner:= AOwner; // :(
end;
When creating TMyGridCell, and you pass TMyGridCell as a value to the OnGetCellClass, you can afterwards retrieve the instance via the OnGetCellProperties, and then assign whatever object or value you want to reference inside the cell.
TMyGridCell = class(TTMSFNCGridCell)
private
FObject: TObject;
public
property MyObject: TObject read FObject write FObject;
end;
procedure TForm22.TMSFNCGrid1GetCellClass(Sender: TObject; ACol, ARow: Integer;
var CellClassType: TTMSFNCGridCellClass);
begin
CellClassType := TMyGridCell;
end;
procedure TForm22.TMSFNCGrid1GetCellProperties(Sender: TObject; ACol,
ARow: Integer; Cell: TTMSFNCGridCell);
begin
(Cell as TMyGridCell).FObject := MyObject;
end;
Ok, not bad. I can even add there ACol and ARow values if eventually i need it sometimes. But I still don't understand why it's important for you to keep FOwner private.
I'm not a big fan for massive event processing. In fact, I always prefer direct access for data, properties, settings, actions etc. Because if i create really complicated grid (like screenshot below), i will get events hell in the end. And over time it gets worse and worse. Consequently if i get more code in events than in other metods, it is cumbersome and poorly maintained. I really dont like number of events.
FOwner is not always the grid, therefore it is private. In case of auto-sizing a temporary cell is being created, with nil as a parameter. For exporting to PDF or when printing, the owner can change to something else, therefore it is not exposed. Up until now we didn't have a reason to expose it. We'll write it down and see if we can expose the FOwner, but the above approach is valid and will allow you to be more flexible.
Ok. I understand.
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.