Jump to content

Forms creation/KeyEvents


vbdavie

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.

QUESTION #1:
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...
   initialization
      RegisterClass(TUniMaskEdit);

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?

QUESTION #2:
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?

QUESTION #3:
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?

QUESTION #4:
Why is there a unitTimer? is TTimer not any good?

 

QUESTION #5:
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);
begin
  if Key = 13 then
  begin
  // do somthing
  end;
end;
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

#1:

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

 

#2:

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

 

#3:

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

 

#4:

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

 

#5:

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

#2:

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?

 

#4:

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?

 

 

#5:

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

 

Davie

Link to comment
Share on other sites

#2

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.

 

#4

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

 

#5

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...