Overview
I am creating a component that comes from TCustomTreeView, I want to add a property that displays the Object Inspector (paValueList?) In the drop-down list. This list should be dynamically populated based on another list (TStrings) that is attached to my control, for example, it can be elements from TComboBox, TListBox or strings from TStringList, etc.
I have a few problems, although I could really make some recommendations and tips.
Code Layout
I cut the code to make it easier to read, but the layout is essentially the same as mine.
I divided my components into two groups (one project group), Package1 consists of component code (for example, my component obtained from TCustomTreeView) and Package2 contains the registration procedure and design units (designide.dcp, DesignIntf, DesignEditors, etc.) .
Package2 I believe that I need to add a property editor that will be used for my component derived from TCustomTreeView in Package1 .
Package1
unit MyTreeViewUnit; implementation uses ... Classes, SysUtils; type TMyTreeView = class(TCustomTreeView) private FSomeList: TStringList; // property editor should be filled using this list procedure SetSomeList(const Value: TStringList); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property SomeList: TStringList read FSomeList write SetSomeList; end; ....
Package2
unit MyTreeViewPropUnit; implementation uses DesignIntf, DesignEditors, Classes; type TMyTreeViewProperty = class(TStringProperty) public function GetAttributes: TPropertyAttributes; override; procedure GetValues(Proc: TGetStrProc); override; procedure Edit; override; end; implementation uses MyTreeViewUnit; function TMyTreeViewProperty.GetAttributes: TPropertyAttributes; begin Result := [paValueList]; ? end; procedure TMyTreeViewProperty.GetValues(Proc: TGetStrProc); begin inherited; // These cannot be added here!! // This list should be populated based on SomeList found in Package1 - MyTreeViewUnit.pas Proc('Item1'); Proc('Item2'); end; procedure TMyTreeViewProperty.Edit; begin inherited; // ? end;
unit MyCompsRegister; interface uses Classes; procedure Register; implementation uses MyTreeViewUnit; MyTreeViewPropUnit; procedure Register; begin RegisterComponents('MyTree', TMyTreeView); RegisterPropertyEditor(TypeInfo(String), TMyTreeView 'Test', TMyTreeView); // does not seem to add to object inspector for the component TMyTreeView end; end.
Problem
The first problem is that I donβt know what I'm doing, is this the right approach or not, my component installs, and I can use it without problems, although my property editor βTestβ does not appear!
The second problem is how GetValues ββwill populate. Looking at some articles on the Internet, I gave me a general idea of ββwhat I still have in terms of filling out my property editors, etc. It is impossible to add this way, although for what I need, in this example I need GetValues ββto be filled based on the lines assigned by SomeList in the first block (as I said before FSomeList could be a TListBox, for example).
This relates to Problem 2 in how I can get my property editor (when working) to bind to my tree tree so that I can populate it appropriately?
I would be sincerely grateful if someone could give me some pointers, or, rather, direct me to a good article / guide on writing property editors. The ones I read, for example, on Delphi.about, DelphiDabbler, etc., It is not easy for me to understand and follow (I am confused and bogged down in problems quite easily).
Thank you very much!