tags:

views:

67

answers:

2

After much searching, it looks like I have to assign RegisterComponentsProc and RegisterPropertyEditorProc, which I have done.

However, I thought that I could call my design time Register function, i.e. <myComponentUnit>.Register();.

When I do I get stack overflow, because, well ...

procedure myComponentUnit.Regiter;
begin
  RegisterPropertyEditor(TypeInfo(Integer), 
                         TMyComponent, 'myProperty',   TMyProperty);

end;

procedure RegisterPropertyEditor(PropertyType: PTypeInfo;
  ComponentClass: TClass; const PropertyName: string;
  EditorClass: TPropertyEditorClass);
begin
  if Assigned(RegisterPropertyEditorProc) then
    RegisterPropertyEditorProc(PropertyType, ComponentClass, PropertyName,
      EditorClass);
end;

So, I call .Register();
which calls RegisterPropertyEditor()
which call RegisterPropertyEditorProc()
which calls RegisterPropertyEditor() <=== aaargh!!

So, what should I have in the body of my RegisterPropertyEditorProc ?

After further searching, it looks like I want to call DesignEditors.RegisterPropertyEditor() directly, but it is not in the interface section ...

+4  A: 

There is no point in trying to register a property editor at run-time, as it is not usable at run-time to begin with. It is only usable within the IDE during design-time.

Remy Lebeau - TeamB
not if you write your own property editor, I hope. Unfortunately, there is no answer at http://www.drbob42.com/delphi/property.htm or http://delphi.about.com/library/bluc/text/uc092501a.htm etc
Mawg
sigh, I guess you are correct. I'll find another way.
Mawg
Again, property editors (and component editors) are only usable at design-time, as they are implemented in design-time packages only, and you are not allowed to use design-time packages in run-time executables. What are you trying to accomplish in the first place?
Remy Lebeau - TeamB
+3  A: 

Delphi does not include the source for the DesignEditors unit; its implementation is provided solely in the DesignIDE package. That package has access to IDE internals, such as the list of registered property editors. The IDE assigns values to the RegisterComponentsProc and RegisterPropertyEditorProc callback functions. As you noticed, RegisterPropertyEditor calls RegisterPropertyEditorProc. The IDE provides its own function to handle that event.

If you want to register a property editor at run time, then your program plays the role of the IDE. You need to provide implementations for those callback functions to register the property-editor classes with your own property-editing framework. You could probably just keep everything in a simple list. Then, when you want to know what kind of editor to display for a certain type of property, consult the list to find the best match.

You're correct that you should call your units' Register procedures. But that's how you initiate the registration process, not how you implement it. That part's up to you; Delphi doesn't provide any of this for you.

Rob Kennedy
+1 Thanks, Rob.
Mawg