I'm writing a TCustomDBGrid
descendent component which need to access the protected property Options(TGridOptions
), which is part of the parent class (TCustomGrid
) of the TCustomDBGrid object. the issue is which exist a property with the same name reintroduced in the TCustomDBGrid
class but with another type (TDBGridOptions).
Check simplified this declaration
TCustomGrid= = class(TCustomControl)
protected
//I need to access this property
property Options: TGridOptions read FOptions write SetOptions
default [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
goRangeSelect];
end;
TCustomDBGrid = class(TCustomGrid)
protected
//a property with the same name is reintroduced in this class
property Options: TDBGridOptions read FOptions write SetOptions
default [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines,
dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit, dgTitleClick, dgTitleHotTrack];
end;
TDBGridEx = class(TCustomDBGrid)
protected
//inside of this method I need to access the property TCustomGrid.Options
procedure FastDraw(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
end;
I figured out how access this property using a cracker class.
type
TCustomGridClass=class(TCustomGrid);
{ TDBGridEx }
procedure TDBGridEx.FastDraw(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState);
var
LOptions: TGridOptions;
LRect : TRect;
begin
......
LOptions := TCustomGridClass(Self).Options; //works fine
LRect := ARect;
if not (goFixedVertLine in LOptions) then
Inc(LRect.Right);
if not (goFixedHorzLine in LOptions) then
Inc(LRect.Bottom);
.....
end;
But just for curiosity I'm wondering if exist another workaround or a better way for resolve this.
Here is another workaround using class helpers
. It is not as good hack as yours but works.
type
TCustomGridHelper = class helper for TCustomGrid
function GetGridOptions: TGridOptions;
end;
function TCustomGridHelper.GetGridOptions: TGridOptions;
begin
Result := Self.Options;
end;
procedure TDBGridEx.FastDraw(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
var
LOptions: TGridOptions;
LRect : TRect;
begin
...
LOptions := Self.GetGridOptions; //works fine
...
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With