0

I want to edit published property in the Object Inspector via dropdown list. Let's say it's DataSet: TDataSet.

I'm not started yet, but using this http://delphi.about.com/library/bluc/text/uc092501c.htm I will create a property editor and in GetValues method I should do some job to find out which components, that are descendats of TDataSet, are already on the Form that I'm designing now.

Yet didn't find any examples of it. How should I provide access to the current form inside my PropertyEditor.GetValues method or there is another approach?

Why it is NOT this: How to create a component property that lists other components?

Because at certain times in a drop-down list should be listed components of two or more types. At last - I need to hold in the Property a pointer to certain component, which would be not the same type, as it is declared.

I repeat: Property: TClassNone and shoud be listed there: TClassOne, TClassTwo and TClass Three, which are not descendatns of TClassNone.

Community
  • 1
  • 1
notricky
  • 179
  • 1
  • 2
  • 18

2 Answers2

5

All I think you need to do is make it a published property of your component and let Delphi's default property editor do its work:

type
  TMyComponent = class(TComponent)
  ...
  published
    property DataSet: TDataSet read GetDataSet write SetDataSet;
  end;

For example, I think TDataSource works like this without registering any special property editor for it.

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • thanks. But I need to be more complex. That's why I said `Let's say it's DataSet: TDataSet` - I mean i.e. - in example. Ofcourse this can be something else as I'm writing a new component. – notricky Apr 11 '14 at 12:45
  • This should work automatically for published properties of any TComponent descendant type. – Ondrej Kelle Apr 11 '14 at 12:56
  • Well, try it: don't write any property editor, just publish a property on your component. Register your component and try it in the IDE. – Ondrej Kelle Apr 11 '14 at 13:13
  • well, I suppose. But you know - if you have `Images` property is would search for `TImageList` in this module and other related on dropdown. As well as if you have `DataSet` property IDE would search and list all `TDataSet` and its descendants in the module and related ones. If I need to put a value into a property `MyBrandNewClass: TMyBrandNewClass` - I need to search all the descendants of `TMyBrandNewClass` in the module. And I'm looking for a method to do that. Hope this is clear now. But thanks. – notricky Apr 11 '14 at 13:16
  • 1
    Yes, what I'm saying the IDE will do this automatically, there's no need for a special property editor. Assuming your TMyBrandNewClass is a descendant of TComponent. – Ondrej Kelle Apr 11 '14 at 13:18
  • Okay. Let's make it more complex. At a certain times MyBrandNewClass property should grab components in it's list, that are of `TThisClass` and `TOtherClass`. And both of them are only descendants of `TComponent`, and I want MyBrandNewClass property to show me components only of these two classes. How would IDE do that automatically? – notricky Apr 11 '14 at 13:31
  • That's a different question, and I posted a different answer. – Ondrej Kelle Apr 11 '14 at 13:46
1

Sorry, I was too hasty in writing the original answer. Here's an edit:

Write a descendant of TComponentProperty and override GetValues. Have a look at the TInterfaceProperty implementation in DesignEditors which filters the selection only to instances of components supporting the interface assignable to the property.

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • Oh that's it! I will do it right now and report back. Any other suggestions are welcome. Not yet clearly see what I actually should do. But already found `GetProperties` and working on it in blind ;) – notricky Apr 11 '14 at 14:00
  • I suppose that I should override `GetSelections`? Am I right or I should look deeper? – notricky Apr 11 '14 at 15:31
  • Just figured out, that _GetProperties Should be overridden to call PropertyProc for every sub-property (or nested property) of the property begin edited and passing a new TPropertyEdtior for each sub-property. By default, PropertyProc is not called and no sub-properties are assumed. TClassProperty will pass a new property editor for each published property in a class. TSetProperty passes a new editor for each element in the set._ I guess this is not the thing I need. Or did I misunderstand something? – notricky Apr 11 '14 at 15:35
  • This works out! I did as you suggested by looking upon `TInterfaceProperty` in `DesignEditors` unit. Just have copied the code for `GetValues` and `RecieveComponentNames` and instead of code `Supports(...)` in last one proc, I've inserted `and (Temp.InheritsFrom(X) or Temp.InheritsFrom(Y))`. Now only left changes, that should be made on changing the property with a certain component. Is there any event, where I can test the assigning component's type? Or better to create another question? – notricky May 08 '14 at 13:55
  • Please, refer to the [link here](http://stackoverflow.com/questions/23544367/delphi-override-an-assignment-proc-for-components-property-in-object-inspector) for further discussion of last topic. Thanks a lot! – notricky May 08 '14 at 14:16
  • Depends on what you need. Perhaps you could use the setter method for the property. – Ondrej Kelle May 08 '14 at 14:16
  • If this is possible to you, I have made a new question and it's here: [link ](http://stackoverflow.com/questions/23544367/delphi-override-an-assignment-proc-for-components-property-in-object-inspector). I did my best to explain. And setter method doen't fit well as I see. – notricky May 08 '14 at 14:18