|
Smart Mobile Studio is an exciting new development studio for web and pascal programmers. It’s key feature is that it completely replaces javascript with object pascal. Our advanced compiler technology takes your object pascal source code and transforms it into state of the art, cutting edge javascript which can be executed by all modern browsers. The programming language used in the Pas2JS is a dialect of Object Pascal which is derived from DWScript called Smart Pascal.
|
As the name implies Smart Mobile Studio is the first and foremost a tool for building feature rich mobile applications (iPhone, iPad and Android devices). But due to the architecture of the VJL - visual component library it is equally suited for desktop browser apps. In fact some of the games that have already been created with smart run flawlessly on the desktop and can be enjoyed in browsers like Google Chrome, Mozilla FireFox and Apple Safari. Browsers that offer hardware accelerated graphics, 2d and 3d transformations, memory allocation and local storage.
Anatomy of a Smart Mobile Studio Unit
unit Form1;
interface
uses
SmartCL.System, SmartCL.Graphics, SmartCL.Components, SmartCL.Forms,
SmartCL.Fonts, SmartCL.Borders, SmartCL.Application, SmartCL.Controls.Button;
type
TForm1 = class(TW3Form)
procedure W3Button1Click(Sender: TObject);
private
{$I 'Form1:intf'}
protected
procedure InitializeForm; override;
procedure InitializeObject; override;
procedure Resize; override;
end;
implementation
{ TForm1 }
procedure TForm1.W3Button1Click(Sender: TObject);
begin
writeln('Hello'#13#$0D'World');
writeln("Hello
World");
writeln(#"
Hello
World");
end;
procedure TForm1.InitializeForm;
begin
inherited;
// this is a good place to initialize components
end;
procedure TForm1.InitializeObject;
begin
inherited;
{$I 'Form1:impl'}
end;
procedure TForm1.Resize;
begin
inherited;
end;
initialization
Forms.RegisterForm({$I %FILE%}, TForm1);
end.
"Hello World" using static method.
Tips:
· | The directive {$I 'Form1:impl'} converts the design view of the form to code, so make any of your code changes to properties of controls after this. |
· | The directive {$I %FILE%} includes a string containing the current filename where the directive is. See more about directives. |
· | Use F12 to toggle between the code of a form and its design view. |
· | Right click on the design view of the form and select "View XML" to see the properties of all of the components placed on the form. You can edit this settings, see the next tip. |
· | Most of the source code of demonstrations is "hidden" in the project file (.sproj). Once in the IDE you can right click on the unit name and click on "Make item external" to obtain the Pascal source (.PAS) in the project folder and for the unit of a form, this also gives you the external (.SFM), it's a XML file of the form design. So, you can open it and edit in a external editor (Remember to close current project in Pas2JS). It's always a good idea to check "Store new forms and units in external files", see next tip. |
· | Tools > IDE Settings > Project Management > (x) Store new forms and units in external files. You can open your units (.pas) and forms (.sfm) and edit them in an external editor. |
· | You can enclose strings in single quotes as usual or in double quotes. Double-quoted strings can span multiple lines. |
Smart Mobile Studio supports:
· | Variables are guaranteed to always be initialized. Variable declaration can feature an assignment, variable type can be inferred, for instance |
var i := 20;
//is equivalent to
var i : Integer;
i:=20;
//as well as
var i : Integer := 20;var i := 20;
//is equivalent to
var i : Integer;
i:=20;
//as well as
var i : Integer := 20;
|
· | Array Constants Array constants are delimited with square brackets [ ] and not parenthesis ( ). The syntax change was necessary to allow supporting inline static arrays definition, and make provisions for operators operating on arrays and future array comprehension extensions. |
const a1 : array [0..2] of String = ['zero', 'one', 'two'];
var a2 : array [0..2] of String;
a2 := ['zero', 'one', 'two'];
|
· | Constructors classic constructor syntax is supported, but you can also specify a default constructor and use the "new" keyword to instantiate classes. |
//Both lines of code below are equivalent:
obj := TMyObject.Create(parameter);
obj := new TMyObject(parameter);
|
· | Smart Pascal allows you to directly include JavaScript code in ASM Blocks |
· | You can use the in and not in operators to test the presence of an element in an array. See others operators. You can use the C-style compound operators +=, -=, *= and /=. |
· | A dynamic array has useful "pseudo-methods" such as Push, Pop, Clear, Copy, Delete, IndexOf, Swap and Reverse. Pas2JS supports Static and Dynamic arrays. |
· | Case statements can use any data type as a selector (not only an integer as in pure Pascal). See statements. |
· | Support loops support the step parameter, which must be positive. |
· | There are many inbuilt handy functions such as Clamp (to limit a value to an interval), IsPrime, IsDelimiter, StrSplit and StrJoin. |
· | Code structure: code structure is essentially standard Pascal with the following changes. See more here. |
· | RTTI: Some aspects of RTTI are on the drawing board, but as of writing this is not something we support. See more details here. |
· | Exceptions: Smart has full support for exceptions. JavaScript exceptions will surface as ordinary Object Pascal exceptions and can be handled the exact same way. There is one small difference however, see here. |
· | Data Types: Pas2JS supports the following data-types and arrays of these. The range of types is limited by JavaScript. More info, click here. |
· | Common RTL units: Pas2JS does not try to mimic the Delphi unit names, although the list of functionality and component architecture share many similarities. The Smart RTL is in constant growth but as of writing the following units can be concidered "standard". There are of course more units in our runtime library. but these units represent the central hub of our system. See more at RTL |
· | Classes, Constructors and Destructors. |
· | Records and also arrays of records, both dynamic and static. |
· | Pointers: JavaScript does not support pointers but deals exclusively with references , as such the pointer data-type serves no function and does not exist in our flavour of Object Pascal. In short we can say that JavaScript deals with references and values in 3 ways: |
· | references to native objects provided by the browser |
· | variables holding data structures created by JavaScript (including JavaScript prototype objects) |
· | references to JavaScript values or functions (functions can return functions in JavaScript) |
What we have done to clean up this mess – is to map our rigid Object Pascal terminology onto the unstructured and colorful JavaScript mesh. Our goal has not been to make Object Pascal look like JavaScript, but rather to force JavaScript to abide by our rules. This is much more elegant than trying to mimic or fake a datatype that doesnt exist:
· | You handle object references with TObject |
· | you handle data structures with records or variants |
· | you handle values using normal variable types |
· | You handle function references with procedural types (see events and event handlers above) |
|