Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple forms using a single procedure
#1
Is it possible to have have a two form application and be able to call a procedure in form1 from form2? I have a web socket on form1 and I'd like to have one "sendMsg(string);" on form1 that form2 would call. Standard practice in Delphi itself, but the Intraweb app doesn't seem to let me. Do I need another socket on form2 to have it communicate? I have the units in the 'uses' clause of each other and I can see form1 variables in form2 but not procedures.
Reply
#2
The form instances still exist. From an event in form2, you can call methods in instances of form1.
Reply
#3
That's what I thought as well. But the methods available are only those associated with TIWAppForm, not any that I've declared. Normally I would expect that if I declare a public procedure in iwform1, like "procedure Adjust(s: string);", and somewhere in iwform1 there is
"Procedure TIWform1.Adjust(s: string);
begin
...code...
end;"
that I can call it in iwform2 via "iwform1.Adjust('dog');" Indeed, in plain Delphi, typing just "form1." triggers code completion to list the available procedures and functions. Doing that in my Intraweb app only shows the tiwappform procedures like "SetURL" and gives an error if I enter "iwform1.Adjust('dog');".
I apologize if this is still not clear or that it's a case of some simple setting that "everybody knows".
Reply
#4
"only those associated with TIWAppForm"

That's because you arent accessing them correctly. Where are you getting the instance from? If its from a session list or other then you will need to typecast it just as you would in any Delphi app. Otherwise you can store a typed referenced in your session to specific instances to pages just as you would in a Delphi app, but instead of globals they must exist on the session because IW apps are multi user.
Reply
#5
You can also extend the user session for any global routines. If they are truly page specific, then simply store a reference i your user session from the oncreate, constructor or other place when your page1 gets created.
Reply
#6
(12-30-2020, 10:26 PM)davidbaxter Wrote: Is it possible to have have a two form application and be able to call a procedure in form1 from form2? I have a web socket on form1 and I'd like to have one "sendMsg(string);" on form1 that form2 would call. Standard practice in Delphi itself, but the Intraweb app doesn't seem to let me. Do I need another socket on form2 to have it communicate? I have the units in the 'uses' clause of each other and I can see form1 variables in form2 but not procedures.

Don't use sockets like that in an IW application.

Each session (i.e. each connected user) will have a different instance of Form1 and Form2. In that case you would end up with multiple sockets instances probably trying to use the same port. Other than that it would create a huge overhead...

The best thing to do is: refactor your code, move whatever code you want to share to a separate unit (preferably a class). And then you can call the method from any form.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)