Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

Forms and navigation

Forms

Forms

Under Smart, a form is a lot simpler than what we are used to under delphi. The class TW3CustomForm which all forms derive from inherits directly from TW3CustomControl and is basically nothing more than a visual control. It introduces only 3 new members which are:

  • Caption property
  • FormActivated method
  • FormDeactivated method

The method FormActivated() is executed after the form has come into view, and FormDeactivated() before the form move out of view.

When you create a visual application, Smart will create main unit and main form and prepare the code that initializes and displays the main form while the application is being started. This initialization happens in the method TApplication.ApplicationStarting in the main unit.

procedure TApplication.ApplicationStarting;
begin
  //Add code above this line 
  FFormMain := TFormMain.Create(Display.View);
  FFormMain.Name := 'Main';
  RegisterFormInstance(FFormMain, True);

  inherited;
end;

This initialization code creates the form object, sets its name and registers the form object in the internal list.

Creating Secondary Forms

To create additional form, you first have to create it in the IDE by using the Add Form button. This will create new unit which will implement the new form, but will not create the form object and so the form will not be usable. You will have to do it in the code.

You should initialize additional units in the ApplicationStarting method, just like the main form is instantiated. The example below shows how to create and register Help form for the MandlebrotExplorer demo project.

procedure TApplication.ApplicationStarting;
begin
  //Add code above this line 
  FFormMain := TFormMain.Create(Display.View);
  FFormMain.Name := 'Main';
  RegisterFormInstance(FFormMain, True);

  FFormHelp := TFormHelp.Create(Display.View);
  FFormHelp.Name := 'Help';
  RegisterFormInstance(FFormHelp, False);

  inherited;
end;

There’s an important difference between the two RegisterFormInstance calls. When creating main form, second parameter is True and when creating all other forms it must be False.

Navigating Between Forms

Even when created, secondary form is not automatically visible (this makes a lot of sense if you think about it). To display a different form, use Application.GotoForm or Application.GotoFormByRef. They are functionally the same except that the former accepts a form name and the latter a form object.

procedure GotoForm(aName: String; Effect: TFormEntryEffect = feNone);
procedure GotoFormByRef(aForm: TW3CustomForm; 
  Effect: TFormEntryEffect = feNone);

Both take an optional parameter governing how the new form will be displayed. Following effects can be applied:

  • feNone
    No effect, new form just *pops up* over the old form.
  • feFromRight
    New form slides in from the right.
  • feToLeft
    New form slides in from the left.

To return to the primary form you have again to call GotoForm or GotoFormByRef.

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS