Jump to content

Forms creation/KeyEvents


Recommended Posts

I am getting further in having my app actually do something useful. I have 5 questions that are probably simple to answer, but since I'm a NEWBIE, I don't know the answers to them.

I see two ways to create forms...
    1. MyForm := TUniForm5.Create(UniApplication)
    2. Result := TFormAnchor(UniMainModule.GetFormInstance(TFormAnchor));

Since method #2 is more commonly used everywhere, why do #1? Which is better?

I also noticed that a bunch of forms have this sort of thing at the end...

I presume this is so that the...
   FrC := TUniFrameClass(FindClass(FClassName));
line of code will find the class and be able to instantiate it onto a Tab in the page control, when the user clicks on the TreeView node?

I noticed that you mentioned that the SHOW/SHOWMODAL should be in the same procedure that creates the form object, in an earlier post.

Why should it be shown in the same event that creates the form object?

What makes a form a "FreeForm" ? The forum said in an earlier post...
     Free form should be created in code manually. It is not managed by framework.
What does that mean?

Why is there a unitTimer? is TTimer not any good?


From an earlie post, I saw...

For example several times I've seen that developers do things like below:

procedure TMainForm.UniEdit1KeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);
  if Key = 13 then
  // do somthing
Which doesn't make sense at all when you deploy your app on the web. It would make sense only in a gigabit LAN, but certainly makes no sense on the internet.

I do this EXACT thing when the user presses the ESC key so I can exit the form. Why is that a bad idea? How else would I close the form when the user presses the ESC key?


Link to comment
Share on other sites


You have "Free Form" and "UniGUI managed Form". Free Form you must create/free by yourself, you can have more than one instance of it per session at a time. With UniGui Form you have only one per session, create and free will be done by uniGUI. accessing the form (function) will create it, close will free it. The difference to Delphi/VCL is that it can't use global vars for that, because each user/session wants its own instance. So there is a function "MyForm" that delivers the instance for the current session (including create when needed).



So that auto create (on access and show) and auto free (on Close) works correct.



See #1. And be aware that you do not use global vars.



UniTimer fires on client side (browser). That is needed, because browser must first send a request, otherwise Server could not answer (send something to browser).



So every key press is send to the Server -> much traffic. You can use Client Events (JavaScript in browser) and then use AjaxRequest(...) when you must process something on Server.

  • Upvote 1
Link to comment
Share on other sites


Huh, so if I create a form<using the function> and store it in the pubilc area of my main form, and then I do nothing with the object/form until the user clicks the "Display" button... are you saying that if I put the     dynform.showmodal    statement in the buttonclick event, that it would not show the form correctly?


It seems to me that once an form object is created, that it should be able to be accessed at a much later point in time, provided I don't "free" it. Am I missing something?



So, if I have a TTimer and every second I change the caption of a label, you are saying that changing the caption property will NOT SEND then brower the appropriate commands to change the caption?




SO, if I do NOT have a OnKey event, then there is LESS traffic? IE: The browser will not send every keystroke?

Is there a TuniForm class that has the js/aj commands built into it so that the ESC key will close the form? It would seem a populare thing to want to do.


BTW: Thanks for all your answers



Link to comment
Share on other sites


Use "free form" and you are free...

UniGui forms that are not in use (displayed) will be freed for less memory consumption. If you show you them later again they are created again, but so prior changes are lost.



That is how HTTP works: Server can only answer a request - if there is no request, there will be no answer.



Not every keystroke or mouse move will be sent by default. Would be too much traffic.

If you can use such high traffic depends on your own system. Do you have view users in a local network, there should be no Problem. Do you have many users over (slow) internet connection, there is a Problem In second case you should use (client side) JavaScript...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...