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

Monthly Archives: November 2011

OP4JS: Project file format

Posted on 29.11.2011 by Jon Lennart Posted in Developers log 3 Comments
Embed or reference, now you chose

Embed or reference, now you chose

In the olden days of 16 bit computing, most programming languages saved their projects in a single binary format. In short: all the files pertaining to your project was housed in a single file. The benefits were of-course that making backups was easier, and it was also easier to keep track of a project.

This is something that I have really missed in the age of modern computing. I have had some experiences with Delphi where i misplaced packages and source files and actually lost quite a bit of work. I don’t blame Delphi for this of-course, it has been completely my own fault and it all has to do with keeping 5 Mac’s and 3 PC’s in sync 😛

But still, i do miss being able to save an entire project – and I mean everything – in a single file. It was so easy when sending a project to a friend to just ship one single file (today we use SVN naturally but still), and also so much easier when making backups. You have a projects folder that contain X number of project-files, rather than a folder containing thousands of files, including the SVN revisions.

You can clearly see what file is on disk and which is resident

You can clearly see what file is on disk and which is resident by it's glyph

With OP4JS I’m bringing this old trend back. So you can finally mix and match between the “normal” way of organizing your project (one file per unit + project file + dependencies) or the old school “packaged” way (all files stored inside the project file). You can also keep some files resident and others external. Good if you want to share a unit with someone or just downloaded something from the net.

Import versus reference

Under vanilla Delphi you don’t import files, you reference them (explicit or implicit). I made a small twist to this concept so that if your project contains a file with the same name as an RTL file – it will always use that instead. If you chose to open an RTL file you are always given the option to create a duplicate – inside the project file. That way you can create your very own version of the RTL file without screwing up the system. It’s also invaluable during the development of new RTL files and bug-fixing the system.

Or good fun if you want to “mod” the RTL 🙂

delphi OP4JS

Asm sections? You betcha!

Posted on 28.11.2011 by Jon Lennart Posted in Developers log 6 Comments
OP4JS about to go Alpha

OP4JS about to go Alpha

I posted a picture of the OP4JS pre-Alpha testbed to my Facebook group, and a member found it interesting that it had an ASM section in the code. How can there be an ASM section in a system that targets JavaScript you wonder?

Well, assembler for OP4JS is basically what assembler would be to a real Delphi application. In this case: raw JavaScript. Eric Grange, my friend and author of our compiler, has done a great job on transposing classical Object Pascal terminology onto the (let’s face it) bewildering typology of JavaScript.

Take this simple procedure for instance:

procedure TMyObject.Testing;
var
  mRef: TObject;
begin
  mRef := tagRef;
  asm
    (@mRef).style.width=100 + "px";
  end;
end;

What we do here is to first get a handle to the our tag (the tagRef is a public property of TW3TagObject, the class TW3CustomControl inherits from). We then enter the ASM section, use that reference to access and alter the width style property. Ofcourse you dont have to deal with this stuff unless you want to, because OP4JS will ship with a rich set of controls ready to be used. And rolling your own controls is so simple it’s almost ridicules.

The squiglies

But why the @ prefix you wonder? Well, when we obfuscate our code (make it unreadable, or less “stealable” for the average hacker), all the names of variables and methods are altered. As such, the compiler needs to be able to quickly figure out if you are using a JS based variable or an Object Pascal variable. So all Object Pascal variables have to be prefixed with the @ character. Due to the nature of Javascript you also need to isolate direct references to object fields and native fields inside ( [ .. ] ) sections, like in this example:

asm
  (@self.FWidth) = parseInt( (@mRef).style.width );
end;

Where did my pointers go?

JavaScript don’t have pointers, at least not in the proper sense of addresses and memory buffers. What it does have are object references and data references (it also has a weak reference counted garbage collector). So under OP4JS we dont have a type called “pointer” because it would screw up the reality of compiling to JavaScript. Instead, TObject serves the function of a universal object reference, and variant serves as a universal data reference. Variants are special however, because we dont have any operators dealing with it directly (so you cant write: A:=1 + someVariant). The variant type is just used to transport data from one method to another.

But, all the standard types are there: string, boolean, float, integer and so on. You also have records, interfaces and enumerations to play with. It really is a neat system once you get the hang of it.

  function getSomeData: Variant;
  begin
    asm
      /* return a data structure */
      @result = {first:"hello",second:"hello2"}
    end;
  end;

  procedure handleSomeData(aValue: Variant);
  begin
    asm
      /* access the data structure passed in */
      alert(@aValue.first); //will show "hello"
    end;
  end;

Super simple custom control

To demonstrate how extremely simple it is to create your own controls under OP4JS, let’s make a scroll-text. As you probably know HTML have a tag called marquee that scrolls text in a variety of ways. It has been called an evil tag because it consumes a lot of CPU speed (and that part is very true), but just for the hell of it – let’s make a super-simple OP4JS version of it:


unit myscroller;

interface

uses w3system, w3components;

type

TW3Marquee = Class(TW3CustomControl)
private
  FText:    String;
  procedure SetText(aValue:String);
public
  Property  Text:String read FText write SetText;
End;

implementation

procedure TW3Marquee.SetText(aValue:String);
Begin
  //Keep the text
  Ftext:=aValue;

  // Cheat and inject the tag into our innerHTML
  // This works because TCustomControl has already created
  // a tag for us. So we just inject the content
  innerHtml:='<marquee style="'
  + 'font-family: verdana;'
  + 'width: 100%;'
  + 'height: 100%;'
  + '-webkit-marquee-increment:3px;'
  + '-webkit-marquee-speed:fast;'
  + '-webkit-marquee-direction:backwards;'
  + '-webkit-marquee-repetition:infinite;'
  + '">' + FText + '</marquee>';
end;

end.

Naturally this is just a quick example. A fully functional and quality control would have a slightly different layout. There we would isolate the marquee in it’s own tag object. But the approach is perfectly valid, although a bit slap-dash 🙂

OP4JS does not work by injecting text into the DOM, that is to slow. We create tag objects via the Javascript API and access our objects by reference. This is why OP4JS apps are much faster than those produced by other JS compilers. We try to avoid the use of getElementById() because it results in poor performance.

Console and gaming applications under OP4JS

Posted on 10.11.2011 by Jon Lennart Posted in Developers log 5 Comments
A simple console app

A simple console app

OP4JS is getting near to completion for each day that passes. We are currently implementing the final project types which are: console and gaming. Yes you read right – console.

Console

A console application under OP4JS is basically a visual project, but where an instance of TW3Console occupies the majority of the screen. It is meant for testing purposes (for now) where you want a quick and easy project type just to test out theories and play around with routines that doesn’t require forms.

We do have more plans for the console in future versions of OP4JS:

  • Command registration (think TActions but with params)
  • Built in REST command for testing http services
  • Pipe output to email

At present the console application supports WriteLn() which outputs both to the screen and to the actual console javascript object. This is handy because it means you can use XCode to see the output “live” if you want to (or any other remote debugger).

Gaming

The generic gaming project type is very simple, basically it puts safari mobile into full-screen, plasters a canvas in the view-port and uses a high-speed timer to force maximum redraw-rate. It is up to you to load in pictures and draw them using the methods in the canvas object.

Since i have coded a lot of 2d platform games earlier, you can expect to see a game library coming out as soon as the product has shipped. In fact it’s one of the things i’m eagerly looking forward to working on.

 

Console HTTP Log OP4JS REST

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