Jump to content

about login form


lucksjb

Recommended Posts

Hi 

my name is Luciano, I´m from Brazil,  and I begining develop using uniGUI.

 

First of all congratulations by this excelent tool ... this is realy good tool...

that´s a dream... 

 

 

I don´t know understand how work callback functions ... 

 

I need a running sample of callback function to a login form 

 

 

tnx a lot guys 

 

 

Luciano 

Link to comment
Share on other sites

Hi !! .. 

 

Please, let me explain imho the 'call back 'concept'. Thank you !

 

The concept behind 'call back functions' is in fact very simple .. but .. very different compared with the 'classic' way.

 

Consider this:

 

TForm.ButtonOnClick(Sender: TObject)

begin

  .

  

  with TLogginDialog.Create(nil) do

  try

     ShowModal() // Here is the problem !!  

  finally

    Free;

  end;

  .

 

end;

 

Why is there a problem with ShowModal() ? ..  because you normally expect the 'modal behaviour' .. TLogginDialog instance will 'wait' until the operator close the form (apparently 'waiting' in modal state) then the flow of logic will return .. and ... 'finally' the instance will be destroyed (finally free)

 

But that will not happen

 

What actually will happen is .. the instance will be created .. then showed .. and the logic will return inmediatly !! .. so, inmediatly destroying the instance just created (excuting, 'finally free')

 

That of course, will probably lead to some kind of error .. 

 

Why this happens ?

 

Because the TLogginDialog instanciated continues running in another thread ..

 

The point here, is that the caller Form (TForm) .. cannot know 'when' the called Form (TLogginDialog) will 'stop' (in the actual sample, that will happen when the operator close the form)

 

 

But the called Form does know when it ends

 

Because as any Form, has it's own 'OnClose' event .. (probably this event has a 'flag' TCloseAction=caFree, so after its close, will be free .. check out this !)

 

So the 'idea' here is to 'invert the logic' .. instead of the caller Form knowing whe the called Form returns (in fact cannot know) the called Form, 'informs' the caller when it stops.

 

So:

 

TCallerForm <calls> TCalledForm .. TCalledForm <informs 'something'> TCallerForm

 

How to do this ?

 

To put it simply, the caller, call the 'other' form .. passing some 'special parameter .. wich in fact is a pointer to a function .. 

  

TForm.ButtonOnClick(Sender: TObject)

begin

   oLoginDialog:=LoginDialog.Create(LoginDialogCallBack);

   oLoginDialog.ShowModal();

end;

 

TForm.LoginDialogCallBack;

begin

   if oLoginDialog.LogginOkey then

    .

    .

end;

 

And .. in the OnClose event of the TLoginDialog ..

 

TLoginDialog.OnClose(Sender: TObject; var Action: TCloseAction);

begin

   if Assigned(pCallBack) then

     pCallBack;

end;

 

(Attention ! .. after the TLoginDialog.OnClose .. the TLogginDialog instance will probably be destroyed !)

 

And that's it !

 

:)

 

Regards

 

Rober

  • Upvote 1
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...