Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to create TIWAppForm.Handle


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: May 27, 2016 12:01 AM Last Post By: Daniel Fields
Kosuke Tsunoda

Posts: 7
Registered: 9/8/08
How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 2:25 AM
Hi, everybody.

I am working on a project to convert vcl-application developed by delphi to web-application with intraweb.
In the vcl-application, we used windows message to implement some operations.
Now, for the purpose to reduce the man-hours of conversion work as much as possible, we would like to
leave these window-message-methods as them are.

As we all know, there are three procedures mainly used to send window messages, TControl.Perform, Windows#SendMessage and Windows#PostMessage.
When we use Windows#SendMessage or Windows#PostMessage, handle is necessary to locate the control.
For TControl.Perform, handle is not necessary in parameters but it may be required by the message-handlers.
So we create some TIWCustomControl-like components inherited from TWinControl. And we call them "CV-component".
But the handle of TIWAppForm, which is the parent of these CV-components, is always 0.
It causes error when we create the CV-components' handle.

So could you tell me how to create TIWAppForm.handle?

I tried two ways next. Could you tell me whether they are ok or not?


1.Override TIWAppForm.CreateParams, and set Application.Handle to Params.WndParent

procedure TIWForm2.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if Parent = nil then  begin
    Params.WndParent := Application.Handle;  
  end;
end;


On this way, it runs well on SA, but it raises excepiton on IIS with the message "Control IWForm2 has no parent window".

2.Create an instance of TForm, and set it to TIWAppForm.Parent on creating the TIWAppForm

type
  TIWForm2 = class(TIWAppForm)
    procedure IWAppFormCreate(Sender: TObject);
    procedure IWAppFormDestroy(Sender: TObject);
  private
    FFrm:TForm;
  public
  end;
 
procedure TIWForm2.IWAppFormCreate(Sender: TObject);
begin
  FFrm := TForm.create(nil);
  Self.Parent := FFrm;
end;
 
procedure TIWForm2.IWAppFormDestroy(Sender: TObject);
begin
  Self.Parent := nil;
  FreeAndNil(FFrm);
end;



In the first place, if there was any way to send/receive windows messages without handle on intraweb, please let me know.

Thank you!!

Edited by: Kosuke Tsunoda on May 26, 2016 11:13 PM

Edited by: Kosuke Tsunoda on May 26, 2016 11:24 PM
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 3:27 AM   in response to: Kosuke Tsunoda in response to: Kosuke Tsunoda
Hi Kosuke,

IntraWeb application controls (including forms) don't have windows handles... Standard VCL form applications use the Windows messaging system, but this is not available in IntraWeb (nor in any other server application) because there are no visible controls in such applications.
I think the best way to convert such code is creating methods where you can simulate that behavior.
Kosuke Tsunoda

Posts: 7
Registered: 9/8/08
Re: How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 10:38 PM   in response to: Alexandre Machado in response to: Alexandre Machado
Thank you for your reply.

Alexandre Machado wrote:
I think the best way to convert such code is creating methods where you can simulate that behavior.

It may be the final solution for me.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 10:37 AM   in response to: Kosuke Tsunoda in response to: Kosuke Tsunoda
What are you passing through the messaging? Is all of the communication internal to a single instance of the application, or are you trying to communicate with something else?
Kosuke Tsunoda

Posts: 7
Registered: 9/8/08
Re: How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 10:33 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
What are you passing through the messaging? Is all of the communication internal to a single instance of the application, or are you trying to communicate with something else?

Thank you for your reply.
All of the communication is internal to a single instance of the application on the server.
Kosuke Tsunoda

Posts: 7
Registered: 9/8/08
Re: How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 11:26 PM   in response to: Kosuke Tsunoda in response to: Kosuke Tsunoda
How about message-only windows?
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632599(v=vs.85).aspx#message_only

procedure TIWForm2.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if Parent = nil then
    Params.WndParent := HWND(HWND_MESSAGE);
end;


It runs well with the CV components both on SA and IIS.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: How to create TIWAppForm.Handle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2016 12:01 AM   in response to: Kosuke Tsunoda in response to: Kosuke Tsunoda
You can add methods and properties to the UserSession to allow communication from one form to another. Anything you do there will be limited to each user's session. By placing the structures and code there they will survive forms being created and destroyed. I would need to know more detail about the usage before I can give you more advice.

It should be very easy to make a replacement specific to the needs of your application. If you can provide a usage example, I can help you get it started.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02