Smart mobile studio runs under Windows XP or later. It has been tested on the following operative systems in our lab:
▪ | Memory requirements: Smart does not have any special needs but we do suggest that your PC has at least 1 gigabyte of ram and 50MB of free space for the installation. |
|
· | Please add System.Types in your unit clause. Real can be represented as a Float. See type mapping. |
|
A byte type is not necessary with JavaScript, as it will be translated to an integer type anyway. Thus the benefit of little memory overhead as in a compiled project does not really exists and thus there is no need for a byte type.
However, in case you want to mimic byte type, you can create a function:
function myByte(i : Integer) : Integer;
begin
if i < 256 then
result := i and $FF;
end;
Please, add the unit "SmartCL.Buffers" if you're processing a large number of bytes, you can use a buffer.
You can allocate a native array with UINT8/16/32 but those are usually used with buffers.
|
Yes. All events are ordinary methods, for instance, when you declare a method with the OnClick signature (ie: procedure MyOnClickMethod (Sender: TObject); ), you can assign that method to any event handler with the same method signature, and thus trigger the same method from several components.
Create a new Visual Project and add one button and one combobox on the form.
Add this line to the forms private section:
procedure MyOnClickMethod(Sender: TObject);
…and this implementation of that method:
procedure TForm1.MyOnClickMethod(Sender: TObject);
begin
WriteLn('Method invoked by ' + TW3TagObj(Sender).ClassName);
end;
And finally add these lines to the TForm1.InitializeObject method:
W3Button1.OnClick := MyOnClickMethod;
W3ComboBox1.OnClick := MyOnClickMethod;
|
Please add SmartCL.CookieStorage unit.
For instance
Cookies.Values['test'] := 'hello';
will write ‘hello’ to a cookie named ‘test’. You can read a cookie in a similar fashion, or use the methods WriteString/ReadString (WriteString also allows to specify the cookie expiration).
Finally the Erase method will erase a given cookie.
|
You can create a class under Smart Mobile Studio the exact same way as you would under Delphi or free-pascal. Just like ordinary object pascal, classes, custom types and functions are stored in a unit file. Below is an example of a very simple class which has one public member:
unit myobject;
interface
uses SmartCL.System;
type
TMyObject = Class(TObject)
public
procedure dosomething;
End;
implementation
procedure TMyObject.dosomething;
Begin
ShowMessage('you called me');
end;
end.
To add a new unit to your project, click the menu "File > New > New unit" in the IDE, or select add unit from the project menu "Project > New unit". You can then proceed to type in the code you want. By default the IDE provides some skeleton code for your unit, so you don’t have to type everything.
To use the unit you have just created – simply add the name of the unit to the uses section in an already existing unit. All unit have a uses section which makes the code in other units visible to that particular unit.
|
Smart Pascal have several differences that clearly separate the dialect from standard Object Pascal:
Code structure is essentially standard Pascal with the following changes:
· | variables, constants, types and procedures can be declared inline. |
· | begin/end is optional for main program code. |
· | var, const and type keywords have to be explicit before any var or type declaration in the main program (var/const blocks are allowed in procedure, before the first begin). |
· | methods can be implemented inline (in the class declaration). |
Character case and syntax: Smart follows the standard Object Pascal text formatting, which is not case sensitive. Your procedure, variable, class and type names can be defined in any case your wish.
Unit variables: This is fully supported, however object instances must be initiated from an existing instance (TApplication being the obvious initiator).
Unit initialization and finalization: Under Delphi and free pascal these two procedures are typically used to initialize unit variables, they are not supported at this time
Unit / Program
If the source is a unit, ie. if it begins with unit clause, and has an interface section, then an implementation section will be required, and it will follow classic structure:
· | you can have variable, constant and type blocks |
· | code cannot be inline and has to be in procedures |
· | implementation are only accepted in the implementation section |
Similarly a main program, ie. if source begins with a program clause, it will follow classic structure.
Variables
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;
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'];
Contracts Programming
Contracts programming is supported with a syntax similar to the Oxygene language, procedures can have "require" and "ensure" sections, the "ensure" sections also support the "old" keyword.
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);
Delegates
Function pointers are unified, there is no distinction between standalone function and method pointers.
For instance the following code is valid:
type TMyFunction = function (i : Integer) : String;
var v : TMyFunction;
v := IntToStr;
v := someObject.SomeMethod;
v := somInterface.SomeMethod;
As long as the function or method prototype matches.
You can use the '@' operator to explicit a function reference to remove ambiguity.
See more:
▪ | Lack of generics (please, see next question) |
|
Smart Pascal does not support generics. The original syntax of Delphi Web Script, from which Smart Pascal derives, was compatible with Delphi 7. Although the DWScript codebase and language has evolved considerably over the past six years, generics represents a monumental change that might require a complete re-write of the entire parser and AST ("abstract symbolic tree" in compiler science) technology.
|
The Smart Pascal IDE have some similarities with Adobe Flash in that you essentially build object-oriented, high-speed, modular applications designed to live in a HTML document. The graphical capabilities of the Smart run-time library is more than up to the task of replicating some of the features Adobe Flash is famous for - but Smart Pascal is ultimately a toolkit for creating HTML5 mobile applications. There is very little in terms of visual automation provided by the Smart IDE. Smart Pascal was simply not designed to be a multimedia composer and remains a clear-cut HTML5 development platform for Object Pascal programmers. The learning curve for Smart Pascal is considerably higher than for Adobe ActionScript. Pascal is a language primarily used by engineers.
|
Smart is presently able to import TypeScript libraries, but with some manual adaptation required. Typescript as a concept is very close to Smart Pascal. Both systems abstract the somewhat tedious labour of writing large-scale JavaScript applications; both systems introduce inheritance and object orientation to a platform which lacks all notions of class datatypes and VMT (virtual method table) execution. In this case Smart Pascal was created before TypeScript and have the upper hand technically, but just like with Adobe Flash, Smart Pascal and TypeScript represent ultimately two very different ideologies. TypeScript also benefits from a large userbase provided by Microsoft - where Smart Pascal is limited to Object Pascal Programmers. But both are capable of much the same.
|
Yes. The Smart pascal run-time library supports all the browser database engines presently in circulation. Access to these are achieved via classes rather than components, which breaks with how Object Pascal traditionally deals with data. As of writing, the following engines are supported:
The Smart IDE also imports and allows access to Embarcadero DataSnap, which is a remote-data-access framework popular with Delphi and C++ builder. Using these import libraries allows Smart Pascal applications to read, write and update remote datasets. Smart Pascal is itself written in Embarcadero Delphi.
The run-time library includes classes for RemObjects SDK, a remote procedure call framework along the lines of Microsoft RPC. JSON RPC and Web Sockets are likewise a part of the class library.
|
Visual Smart Pascal applications are based on forms; Separate windows which can be populated with controls, and code events can be connected to these and respond to user activity. Smart Mobile Studio does come with a visual form designer and property editor - but the designer is simply an aid for ordinary user-interfaces and lacks any support for visual effects.
On the level of architecture the Smart Pascal run-time library have full support for advanced graphical expressions, including dynamically created CSS3 styles, "tweening", display redraw synchronization, GPU powered 2D and 3D sprites and WebGL. One could say that Smart Pascal is "something like Flash", but that is where the parallel ends. Linguistically and conceptually these software methodologies are worlds apart. They were built for different things even though they can achieve much the same results. Smart Pascal has one advantage over Flash in that HTML5 applications have no dependencies. A Smart Pascal program does not rely on plugins, browser extensions or third party libraries. But Flash is ultimately more polished, representing over a decade of continuous evolution and multimedia excellence.
|
All standard structured Pascal statements are supported with the exception of
with¹, goto and label.
Note: Statement with is partial supported in SMS version 2.1
Four forms of loops are supported:
· | for in do : loop on elements in a sequence |
· | for to/downto do : loop on an integer variable |
· | repeat until : loop on a final condition |
· | while do : loop on an initial condition |
All these loops can also be controlled by the following statements:
· | break : exits the current loop |
· | continue : jump to the next iteration of loop |
Note that break and continue are statements and reserved names. They're not functions like in classic Delphi. It means that they're always and unambiguously loop control instructions, and can't be overloaded by user functions or variables.
The exit statement will also exit a loop as well as the whole function.
Note: statement Exit
The exit statement will immediately exit the function where the execution is. It can take an optional parameter or operand which can be used to specify the return value for the current function.
The three following lines are equivalent
exit(value);
exit value;
Result:=value; exit;
If exit is used from within a try..finally statement, the code in the finally block will be executed before leaving the function.
Note that exit is a statement, and not a function like in classic Delphi. It means that it's always and unambiguously specifies an exit, and can't be overloaded by user functions or variables.
Others supported statements are:
• if then else
• raise
• repeat until
• try except/finally
• while do
|
Pascal and C/C++ style comments are supported:
// denotes a single line comment
(* and *) mark a multi-line comment
{ and } mark a multi-line comment
/* and */ mark a multi-line comment
Note: Comments cannot be nested.
|
DWScript is an object-oriented Delphi scripting language for Delphi, despite its name, it is general purpose and not limited to websites. An extensive unit tests suite ensures high quality and robustness. DWScript allows to use as well as define whole classes (with polymorphism, meta-class and interfaces support, etc.). The scripting language is based on Delphi, but also supports syntax and features similar to Prism and FreePascal, as well as various language extensions. Scripts can be executed from Delphi applications (in a safe, sand-boxed fashion), you can also compile and execute them with JavaScript-capable engine using Smart Mobile Studio. An experimental JIT compiler is available for Win32.
▪ | supports classes, interfaces, records |
▪ | supports static and dynamic arrays |
▪ | sand-boxed, automatic memory management |
▪ | full support for meta-classes |
▪ | support function & methods pointers |
▪ | generalized "case of" and "in [...]" syntax |
▪ | scoped, inline variable declaration |
▪ | compound assignment operators |
▪ | extensive exposure, declaration, inspection & debugging features |
▪ | inline implementations of class methods |
▪ | Automated exposure of Delphi types via RTTI |
▪ | Optional COM/OLE capability (via COM Connector) |
▪ | Optional RTTI direct connectivity (via RTTI Connector) |
▪ | Optional asm capability (32 bits, via NASM) |
▪ | Optional JavaScript code generation (compile to JavaScript) |
|
Yes, of course. Several functions and types are built into the language and don't have to be declared
· | Abs, Assert, Assigned, ConditionalDefined, DebugBreak, Dec, Declared, Defined, Exclude, High, Inc, Include, Length, Low, Ord, Pred, SizeOf, Succ, Swap |
· | DateTime functions : current date/time, conversions, offsets. See more: DateTime |
|
Run-time type information is in-part supported by DWScript, including the ability to enumerate properties and class members. But RTTI is presently not implemented by the Smart Pascal JavaScript compiler.
Yes, there is already some low level support for RTTI, but no higher level "easy to use" functions yet.
TObject does have a class type property and you can also use the is keyword. So, you can check if a class inherits from another, for instance, in Delphi: if (someObject.InheritsFrom (TMyObject)) then
InheritsFrom with SmartMS
if (someobject is TMyObject) then
Begin
//do something
end;
Code example: Display properties of a object
procedure PrintPropertiesForType(obj : TObject);
begin
var rtti := RTTIRawAttributes;
var aClass := obj.ClassType;
PrintLn(aClass.ClassName+':');
while Assigned(aClass) do
begin
var typeID := TypeOf(aClass);
var j : Integer;
for j:=Low(rtti) to High(rtti) do
begin
var attrib := rtti[j];
asm
console.dir(attrib);
end;
if (attrib.T = TypeID) and (attrib.A is RTTIPropertyAttribute) then
begin
var prop := RTTIPropertyAttribute(attrib.A);
Print('- '+prop.Name);
Print(', '+IntToStr(prop.Capabilities));
Print(' : ');
Print(prop.Typ.Name);
Print(' = ');
var v := prop.Getter(obj);
PrintLn(v);
prop.Setter(obj, v+v);
end;
end;
aClass:=aClass.ClassParent;
end;
end;
procedure TForm1.W3Button1Click(Sender: TObject);
begin
PrintPropertiesForType(self);
end;
// And attributes are supported too:
type
MyAttrib = class (TCustomAttribute);
type
[MyAttrib]
TTest1 = class
end;
type
[TCustomAttribute]
TTest2 = class
end;
procedure PrintAttributesForType(typeID : TRTTITypeInfo);
begin
var rtti := RTTIRawAttributes;
var j : Integer;
for j:=Low(rtti) to High(rtti) do
if rtti[j].T = typeID then
PrintLn(rtti[j].A.ClassName);
end;
PrintAttributesForType(TypeOf(TTest1));
PrintAttributesForType(TypeOf(TTest2));
|
|
|