Atozed Forums
Multiple forms using a single procedure - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Multiple forms using a single procedure (/thread-2211.html)



Multiple forms using a single procedure - davidbaxter - 12-30-2020

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.


RE: Multiple forms using a single procedure - kudzu - 12-30-2020

The form instances still exist. From an event in form2, you can call methods in instances of form1.


RE: Multiple forms using a single procedure - davidbaxter - 12-31-2020

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".


RE: Multiple forms using a single procedure - kudzu - 12-31-2020

"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.


RE: Multiple forms using a single procedure - kudzu - 12-31-2020

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.


RE: Multiple forms using a single procedure - Alexandre Machado - 01-06-2021

(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.