1
votes

We have a Delphi application which is also a COM server, the application has a main form. When started in automation mode (smAutomation) we need to create the main form as parented. For several reasons outside the scope of this question we can't create the application and then execute a COM method to reparent the main form, namely reparenting has to be done very early in the process - right after the main form is created. Appreciate ideas thx.

Edit: Clarification

// Initialized as as an Application
if COMserver.startmode = smStandalone
begin
   Application.Initialize;
   Application.MainFormOnTaskbar := True;
   Application.CreateForm(TForm1, Form1);
   Application.Run;
End
Else
// Initialized as an automation server
if COMserver.startmode = smAutomation
Begin
// How do I set a Parent window handle property - this is called imediately after the    COM client initializes the server
// how do I modify this call to create Form1 with a parent? 
   Application.CreateForm(TForm1, Form1);
End; 
1
I mean, can't you just test ComServer.StartMode at the point you need to know how to create the main form?David Heffernan
Thanks for the prompt reply, clarified (hopefully)user2046977
Precisely what do you want to set. ParentWindow or Parent? Why can't you assign to those properties after calling CreateForm? It's still far from clear to me.David Heffernan
Need to set form1.parentwindow := WHandle where Whandle is obtained from the COM interface. During the application initialization Video capture windows are placed on the form. These do not work properly if the parentwindow is changed after their placement. The sequence I am looking for is the following: 1. Create the COM server, 2. Set the handle property, 3. create the form with the parent, 4. Continue with the regular initialization. How should the initialization in the DPR change? Thanks a lot!user2046977
Why can't you do ParentWindow := WHandle immediately following Application.CreateForm? If that's too late, then you will need to override TForm1.CreateParams and set it in there.David Heffernan

1 Answers

0
votes

I can see two options:

  1. Set Form1.ParentWindow := WHandle immediately following Application.CreateForm.
  2. If that's too late, then you will need to override TForm1.CreateParams and set it in there.