Jump to content

GoToForm to same form


Recommended Posts

  • Moderators

GoToForm('Form-X') transfers control to 'Form-X' but only if the name of the current form is different from 'Form-X'.

 

This is a problem when the same form needs to be accessed more than once.

An example would be a header with a button linking to a search form, where users may want to execute their searches more than once.

 

A very inelegant solution is to duplicate 'Form-X' into 'Form-Y', query the name of the current form and transfer accordingly.

Something like 'if application.currentform.name = 'Form-X' then gotoForm('Form-Y') ...

 

Any better solutions ?

 

Link to post
Share on other sites
  • Moderators
Hi warleyalex

 

Sorry, obviously my question is not very well articulated.

 

I have an application with a header bar and some forms underneath :

 

procedure TApplication.ApplicationStarting;

var

   mForm: TW3CustomForm;

begin

  FHeader:=TW3Panel.create(display);

...

  mForm := TForm3.Create(display.view);

  mForm.name := 'Form3';                  // Form3

  RegisterFormInstance(mForm, False);

 

The headerpanel contains a number of menu labels, something like :

//

  FMenu01:=TW3Label.create(FHeader);

  FMenu01.Caption := 'Search';

  FMenu01.OnClick :=

    procedure (Sender: TObject)

    begin

          Application.GotoForm('Form3', TFormEntryEffect.feToLeft);

    end;

 

So if a user taps the 'Search' label, control is transferred to 'Form3'.

However if the user taps this label a second time, without using another form first, nothing happens. 

This is sort of logical, the GotoForm proc checks if the destination form is different from the current form and if not it does nothing.

However in this case Form3  is a search-form, and users may well want to do multiple searches consecutively.

 

I needed a quick solution so I copied Form3 to Form3B, identical copies, and changed the OnClick handler to

 

         If Application.CurrentForm.Name = 'Form3'

           then Application.GotoForm('Form3B', TFormEntryEffect.feToLeft)

           else Application.GotoForm('Form3', TFormEntryEffect.feToLeft);

 

That works, but obviously having identical forms is not the way to go, so I was asking for opinions on how to do this better. 
Link to post
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.

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