Writing real estate editors - I need to be guided

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!

+4
source share
1 answer

This is too long for comment, and I want to include some code, so here it will respond. First of all, your question is very broad. You need to slow down so you can ask questions. I really started answering your question number 2, and I wrote something that was unreadable long before the change!

You should start with code that does not require a property editor, i.e. normal runtime code. The property editor may not be central to the development of your user control, because the property editor is only used during development to speed things up. If the changes made by the property editor must be permanent, they are saved in the published properties visible in the Object Inspector in any way (* 1), and these properties, in turn, are saved in the DFM file. The same process returns at runtime, when the form is created, and during development, when you reopen the form (for example: if you close the IDE and reopen it). Since everything needs to go into the Object Inspector, you can skip the fantasy property editors and take control!

Which prompted me to say the following:

 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; 

This comment tells me that you have not yet figured out how to link your component with another component! This is a really trivial step, and once you get this working, you can do this:

 procedure TMyTreeViewProperty.GetValues(Proc: TGetStrProc); var s: string; begin if Assigned(FLinkedCombo) then for s in FLinkedCombo.Items do Proc(s); // Beware, written in Browser! end; 

Even those that are trivial, the answer to the question posed will be incomplete without this part, and this part includes long talk about TComponent.FreeNotification , TComponent.RemoveFreeNotification and TComponent.Notification !

Once you have the most work, you can start working on any Property Editor that you might want to create. This work will also be performed as a regular project: your goal is to create a simple form ( TMyComponentsEditor example) that can edit your property or component. As soon as you get this work, you may ask: how to make this working editor available in DesignTime as the Editor of properties or components.

* 1) Of course, the component editor could come up with material that includes several components; It can also be saved using alternative methods (i.e. do not rely on simple published properties).

+6
source

All Articles