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

Add a new form to my application

Posted on 05.01.2012 by Jon Lennart Posted in Documentation

Adding a new form to a visual application is a piece of cake. Start by opening your project (or create a new visual project), then click the “add form” button in the IDE or add form from the project menu.

Adding a new form is very simple

Adding a new form is very simple

This will present you with a brand new unit, ready to be used by your application. Now switch over to your project unit (in this example, the project was automatically called “project7”, and thus the project unit is called “project7″). The project units looks something like this:

[sourcecode language=”delphi”]
unit Project7;

interface

uses w3system, w3ctrls, w3forms, w3application,
form1;

type

TApplication=class(TW3CustomApplication)
private
{ Private methods }
public
{ protected methods }
procedure ApplicationStarting;override;
end;

Implementation

//############################################################################
// TApplication
//############################################################################

procedure TApplication.ApplicationStarting;
var
mForm: TW3CustomForm;
Begin
//Add code above this line
mForm:=TForm1.Create(display.view);
mForm.name:=’Form1′;
RegisterFormInstance(mForm,true);
inherited;
End;

end.
[/sourcecode]

Before you can actually display and work with your form, the application must know about the form’s existance. So we need to register an instance of the form with the form manager inside TApplication (remember to add “form2″ to your uses section). Simply create an instance of your form by copying the code already present. We alter the name ofcourse so we dont get any conflicts, and we send False rather than True as the last parameter:

[sourcecode language=”delphi”]
procedure TApplication.ApplicationStarting;
var
mForm: TW3CustomForm;
Begin
//Add code above this line
mForm:=TForm1.Create(display.view);
mForm.name:=’Form1′;
RegisterFormInstance(mForm,true);

mForm:=TForm2.Create(display.view);
mForm.name:=’Form2′;
RegisterFormInstance(mForm,false);

inherited;
End;
[/sourcecode]

The reason we pass in “false” as the second parameter is because this value defines the “main” form of the application. All visual applications must have a main form, which is also the form the application displays when you start it.

We can now use the methods GotoForm or GotoFormByRef to navigate between forms. Both these commands (which are members of TCustomApplication) takes a second parameter which controls the special effect. As of writing you can only slide the new form in from either the left or right, but more interesting effects are planned.

« How do i create a class
How do i create and use a timer? »

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