TVirtualDrawTree.GetOptionsClass Method

Virtual Tree View

Customization helper to determine which options class the tree should use.

Pascal
function GetOptionsClass: TTreeOptionsClass; override;
Description

GetOptionsClass is a special purpose method to return a certain class which is used by the tree for its options. TVirtualBaseTree always returns TCustomVirtualTreeOptions but descendants can override this method to return own classes. 

 

For ease of use it makes much sense to always use the same name for the tree's options (which is TreeOptions). By using a customized options class, however, the wrong type is returned by this property. Hence it is meaningful to override TreeOptions and return the derived options class. To make this work the tree descendant must additionally provide new access methods for this property. An example can be seen in TVirtualStringTree: 

 

  TVirtualStringTree = class(TCustomVirtualStringTree)
  private
    function GetOptions: TStringTreeOptions;
    procedure SetOptions(const Value: TStringTreeOptions);
  protected
    function GetOptionsClass: TTreeOptionsClass; override;
  public
    property Canvas;
  published
    ...
    property TreeOptions: TStringTreeOptions read GetOptions write SetOptions;
    ...
  end;

  ...

//----------------- TVirtualStringTree ---------------------------------------------------------------------------------

function TVirtualStringTree.GetOptions: TStringTreeOptions;

begin
  Result := FOptions as TStringTreeOptions;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TVirtualStringTree.SetOptions(const Value: TStringTreeOptions);

begin
  FOptions.Assign(Value);
end;

//----------------------------------------------------------------------------------------------------------------------

function TVirtualStringTree.GetOptionsClass: TTreeOptionsClass;

begin
  Result := TStringTreeOptions;
end;
Class
Links
What do you think about this topic? Send feedback!