Saturday, March 25, 2006

Advanced Xailer Techniques, The Application starting code (II)

[Original post by José F. Giménez]

In the previous article we studied how to change the starting code of a Xailer application, in order to execute a function where we can do anything we want. Now we're going to see what stuff should we put inside that function, to show an entry window, at the same time that the program's main Window is shown, also, and before letting the user go into the main Window, we'll show the typical validation Window, you know, the one that asks for the user name and the password.

For the entry windows, the easier way is to create a form (called TEntrada) set its property nBorderStyle to bsSPLASH. Then choose a nice image, place inside the form, and rezise the form to fit the image's size (no image is included in the sample file). Now we need that this form be shown and removed few seconds later (let's say 4). To do so, just add a TTimer component into the form, set the nInvertval := 4000 (milisecs), lEnabled := .T., and write the event OnTimer, that looks like this:

METHOD Timer1Timer( oSender ) CLASS TEntrada

::Close()

RETURN Nil

For the main form, in this sample, we are going to use a single form, without any control or component inside (TPrincipal) with its property nShowMode := smMAXIMIZE. Now let's write the Empezar() function, we will place this function (procedure) in our program's entry module, just as we studied in the previous article:

Procedure Empezar()

TEntrada():New( Application ):Show()
TPrincipal():New( Application ):Show()

Return

If we compile an run this program, now we can see that the entry window shows itself and right after, the main window is shown, but thanks to the bsSPLASH style, the entry window remains on top, and after 4 seconds it closes itself.

A single detail is missing.... you may think: "ok, but as long as the entry window is runing, the user can do anything in the main window", you are right. We are going to solve this little "issue", but first, we are going to add a third window to get the user name and the password.

For this third windows, the style will be nBorderSyle := bsDIALOG, and we are going to place the need controls to get the user name and the password, 2 Tlabel objects, 2 TEdit objects and 2 TButton objects, one for "OK" and one for "Cancel"

Please notice that the "Ok" button has the properties lDefault := .T. and nModalResult := mrOK, and the "Cancel" button has the property lCancel := .T.

Also the "Ok" button will this in its OnClick event:

METHOD Button1Click( oSender ) CLASS TIdentificacion

RETURN ::oEdit1:Value == "User" .AND.;
::oEdit2:Value == "Password"

As you can see, the only thing done is to return .T. if you write "User" and "Password" in the TEdit boxes, .F. is returned if you miss with one of these words. Now we just have to modify the Empezar() function (procedure):

Procedure Empezar()

LOCAL oEntrada

oEntrada := TEntrada():New( Application )
oEntrada:Show()

TPrincipal():New( Application ):Show()
oEntrada:ShowModal()

IF TIdentificacion():New( Application ):ShowModal() != mrOK
Application:oMainForm:Close()
ENDIF

Return

Ok, here comes the magic, be very very aware on what's going on here: First oEntrada is shown, right after, the main window, TPrincipal, is shown, both are been shown at the same time, and, as explained before, the oEntrada remains on top due to the bsSPLASH style, but the insteresting thing comes right afte the call to TPrincipal:New(Application):Show(), the oEntrada window is shown AGAIN, well this is not really truth, in spite the call to the oEntrada:ShowModal(), which it supposes to show the entry window again, what it really does, is to change the show style of the entry window into a MODAL style, the entry window is not shown twice, as you may suppose, just the showing style is changed, from no-modal, to modal, this avoids the user to take control of the main window, until the entry screen closes.

But.... what about the Identification dialog ?, well, please notice that AFTER changing the style of the entry window from non-modal, to modal, in the very next line, the TIdentificacion:New(Application):ShowModal() is launched, this means that right after the entry window closes itself (4 seconds), the new window will appear, asking for user name and password and as it has the Modal style set, the user still won't be able of touch the main window until he gives the proper data. Once pressed the OK button and if the data is correct, the main window will catch the focus.

That's all by now, as you can see, is very easy to control the application start in Xailer, and you don't have to write almost any line of code.

The project source can be downloaded from here

1 Comments:

Anonymous Anonymous said...

Wow, that's what I was seeking for, what a material! present here
at this weblog, thanks admin off this site.

Look at my site Online Marketing Agencies ()

12:22 PM  

Post a Comment

<< Home