3

Possible Duplicate:
How to invoke a property editor at design time

I'm creating a non-visual component, and I want the user to be able to double click on my component at design-time and have that open a design-time editor.

How can I do it?

Community
  • 1
  • 1
Astervista
  • 211
  • 1
  • 4
  • @David maybe he is trying to create a "global" even handler holder-ish, something like: one component holds the same "double-click" event handler for various visual components, so he might want to have capability of setting it in one non-visual then do something like "applyto([button1, button2, button3, panel5])", could be wrong, but if I'm right, "Astervista" consider a different approach. –  Mar 12 '12 at 14:01
  • I meant double-click in design time. – Astervista Mar 12 '12 at 14:02
  • I want something like double-click on a SaveDialog at design time – Astervista Mar 12 '12 at 14:05
  • 2
    This is a dupe (see comment above). Simple answer is to derive your component editor from `TComponentEditor` and override to the `Edit` method. – David Heffernan Mar 12 '12 at 14:19
  • @David: that was exactly my first reaction. – Rudy Velthuis Mar 12 '12 at 14:35
  • I don't think it's a duplicate. The other question already knew enough to ask about things like property editors, but this question doesn't know the vocabulary. The other question starts off already handling double clicks, and then asks how to invoke the collection editor from there. It turns out that the question was handling double clicks incorrectly, but that's beside the point; the questions are starting from two different places. – Rob Kennedy Mar 12 '12 at 17:19
  • I voted to close and now I see the problem with the linked duplicate; I'm personally on the fence here. I really don't know how to deal with all the possible fuzzy duplication where the actual problems are the same, but the lingo that people use is completely disjoint. – Warren P Mar 12 '12 at 20:03

1 Answers1

4

Double-clicking a component at design time invokes a component editor. The default component editor is one that looks for event properties with certain names and creates a handler for what it finds. You can write your own component editor that does whatever you want.

Create a descendant of TComponentEditor (from the DesignEditors unit) and override the Edit method to handle double-clicks. You can also override the GetVerbCount, GetVerb, and ExecuteVerb methods to add context-menu items to your component. To get a reference to the component your editor is being asked to edit, check the Component property. Call Designer.Modified if your editor modifies the component.

Tell the IDE that your editor should be used with your component by calling RegisterComponentEditor (from DesignIntf) in your Register procedure.

You should put this code in a design-time package, separate from your component's code. Put your run-time package on the "requires" list of the design-time package. If you put everything in a single package, then consumers of your component won't be able to use run-time packages in their projects; they're not allowed to distribute the dependencies of your design-time package, which are only for use by the IDE.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • There are examples of this in the JEDI JVCL codebase. I recently reimplemented just such a thing for `TJvCsvDataSet` for example. – Warren P Mar 12 '12 at 20:00