How to focus a visual .NET-Component in Delphi ObjectInspector

320 views Asked by At

I'm including a visual .NET-Component into a Delphi Project. Using this component at runtime works fine while the Delphi designer does not cooperate properly. Every click on this component in the designer sends a message to the component itself (the impact can be seen).
But what I want is to see the published properties of this component in the IDE designer's object inspector as well as resize and drag and drop the component on a form.

I considered to inherit from TWinControl.WndProc method and catch the WM_MOUSEACTIVATE and WM_PARENTNOTIFY messages (those messages are sent when clicking the component in designer) and do something like this...

procedure TMyComponent.WndProc(var Message: TMessage);
  case Message.Msg of
    WM_PARENTNOTIFY, WM_MOUSEACTIVATE:
    begin
      Self.SetFocus;
      Self.BorderWidth := 15;
    end;
  else
    inherited;
  end;
end;

Clicking the component in designer is setting its BorderWidth to 15 now. But it is still not focused in the IDE's Object Inspector.

Additional information to this project:

I am using Delphi XE7 and Visual Studio 2013... In .NET I'm using a ClassLibrary project for my Component. I inherit a class from UserControl that contains my visual c# component. This ClassLibrary is compiled to a DLL file that I register via "regasm /tlb /codebase ClassLibrary.dll". I use furthermore tlibimp.exe to generate the pas-file for Delphi. I have written a Wrapperclass TDotNetControl that is derived from TOleControl and that overrides/implements the procedure WndProc.

From that class TDotNetControl I derive a class TMyDotNetControl that overrides InitControlData and CreateInstance (from TOleControl). TMyDotNetControl is packed to a package which I build and install within the Delphi IDE. After the installation I can choose my class TMyDotNetControl from ToolBox of the Designer and I can drag and drop it to the WinForm. Because this is a compiled class from the DLL file, the component is displayed in designer just like it would be displayed at runtime (in case we don't call procedures or set properties).

And that is when things get confusing. I can drag and resize this only once. Clicking the compiled component again triggers a MouseEvent on the component itself. That means, if a mouseEvent handler is implemented in .NET, that handler method is called and performed (even in the designer). What I want to do therefore is catching the IDE's click message and make that method focussing the component to edit in Object inspector at Design time. (the object inspector shows the published properties of TMyDotNetControl)

0

There are 0 answers