Forms and navigation

Top  Previous  Next

Forms - Forms and navigation

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.

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.