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: August 2012

Rethinking navigation, random rant from SMS development

Posted on 09.08.2012 by Jon Lennart Posted in Developers log

In the previous update of Smart Mobile Studio (not the summer hotfix) we added support for CTRL + CLICK navigation inside the editor. So if you hold down the CTRL key and click a symbol (a method name for example) it would navigate to the declaration or implementation section for that symbol.

Getting this function to work as expected (i.e “like Delphi does it”) is actually quite tricky. Depending on the type of method for instance, being marked as either virtual or abstract, the navigation could result the IDE showing the ancestor implementation rather than the current overridden implementation. In other words, if you have written a class that inherits from a standard class – and then do a CTRL + CLICK on a method declaration – it can actually confuse the IDE and you end up looking at the implementation for the original base class.

Navigation should be linear and recursive. So if you inherit from a class, click a method you have overridden, you should end up at your own implementation. If you further click on your implemented method – you should go directly to the original implementation.

This has now been fixed, and I’ve also started on the reverse navigation (SHIFT + CTRL + CLICK should bring you from implementation to declaration). Once the reverse is in place we can add keyboard shortcuts like SHIFT + Up/Down as well, since that is more or less the same function in a non recursive form. Of-course, the reverse navigation will stop at the interface section of the baseclass since we don’t want to remember the top-level starting point (that could cause some confusion between units). Keep it simple and clean.

Battle for the sun

While we are busy chewing through the fogbugz list of reported issues (and adding new RTL features) we came across a very interesting side effect with relation to graphics. As you probably know modern browsers have a very tight security system built into it. One of the rules is that you cannot call or use resources from other domain (cross domain communication). The exception is JSONP or when the server provides a special header which tells the browser that you can, indeed, use any resources you want.

What I did not know was that the same security system (worthy of Alcatraz) also applies to graphics (!). In fact, your browser regards itself as one domain (127.0.0.1 or machine name to be precise) and the server where you download index.html and other files – as a distinctly separate domain. This is of-course all true in network terms. Your local PC, iPhone or iPad is not the same as your server (hence the concept of “sessions” – which is server controlled due to the fact that HTTP is stateless).

What does this mean? It means that if your app has images stored in your resource folder (added to the project via the IDE, or manually copied into the res folder), there will be limits to how you extract and move the pixeldata. For instance this example:

procedure TForm1.ButtonClick(Sender:TObject);
begin
  FImage.OnLoad := procedure(Sender:TObject)
    var
      mData: TW3ImageData;
      x, y: Integer;
    begin
      try
        //Get the pixel buffer directly
        mData := FImage.ToImageData;
        if mData <> NIL then
        begin
          //Dump info to stdout
          WriteLn('Data is valid object');
          WriteLn('Width='  + IntToStr(mData.Width));
          WriteLn('Height=' + IntToStr(mData.Height));

          //Set all pixels to red
          for y := 0 to mData.height-1 do
            for x := 0 to mData.Width-1 do
              mData.Colors[x,y] := clRed;

          //Apply as background to form
          Self.Background.FromURL(mData.ToDataUrl);

          //Release pixel buffer
          mData.Free;
        end 
        else begin
          Raise Exception.Create('Image was NIL!');
        end;
      except
        on e: exception do
          ShowMessage(e.Message);
      end;
    end;

  FImage.LoadFromURL('res/parallax.png');
end;

.. will work fine for desktop browsers (safari, chrome and firefox), but fail due to security reasons on the iPhone and iPad (which enforce CORS to the extreme). I’m not sure how beneficial such extreme security measures are to be frank, but that’s another story.

Solutions

In those rare cases where “security exception 18” will cause havoc, the obvious solution is to use the image converter (Tools -> Image converter) to turn your image into a constant and include it as source instead of as an external file. But for normal use (display, move around, rotate etc. ) you wont run into that problem. So it’s only for hard core programmers that like to fiddle with bits and bytes (like myself) that this will be a potential case.

The second solution, which is also what Smart was made to target, is to use phonegap. When you compile your app with phonegap all the security restraints go away, and you can pretty much do everything an ordinary .exe file can  – including file access, camera access and the like.

Clearly, one does not simply waka waka into mordor 🙂

Making a slider control

Posted on 07.08.2012 by Jon Lennart Posted in Developers log 3 Comments

In this mini article we are going to create a normal slider control. It is actually very simple and hardly deserves a full article, but since HTML and the DOM (document object model) have a long and bumpy trail of evolution behind it – some explanation is in order.

Setting it up

Under the DOM, a slider is actually a text-box in disguise. So to create a slider, you simply alter some properties of a normal TW3Editbox and it magically turns into a range-based slider instead. I’m not sure what the programmers behind the DOM thought when they made this rule, but I’m sure they had their reasons.

So, start by creating a new visual application. This also creates a default form for us. Now click the editbox icon from the component palette – and then click on the form. Resize and position the box as you see fit.

Editbox sized and ready

Editbox sized and ready

Now that we have our editbox lined up, make sure you click CTRL + S (save shortcut) so that the form design data is stored in your project file. Once you have done so, switch over to the code tab. Alter the initializeObject() method by adding the following text:

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
  W3EditBox1.InputType:=itRange;
  W3EditBox1.setMin(0);
  W3EditBox1.setMax(100);
  w3EditBox1.OnChanged:=Procedure (sender:TObject)
  var
    mValue: Integer;
  begin
    mValue:=TVariant.asInteger(w3EditBox1.handle.value);
    writeln(mValue);
  end;
end;

Why the esoteric handle stuff?

The reason we have to access the value property of the DOM element directly (handle always points to the actual HTML element), is because of an old difference in browser API. FireFox supports the older “range” property of the element, but the modern API supported by nearly all browsers today is to obtain the value via the.. well, value property. The Smart RTL sadly used the older variation when it was written, but the next update will have the correct range property.

Voila, sliders galore

Voila, sliders galore

Cooperation with Barnsten

Posted on 03.08.2012 by Smart Mobile Studio Team Posted in News
Barnsten

Barnsten

We are very happy to report that Barnsten, the leading provider of development tools and components in the Benelux region, is now selling Smart Mobile Studio. This is very exciting news and we look forward to further cooperation with Barnsten, especially with regards to seminars and courses on Smart Pascal and mobile development.

We urge those living within the Benelux region to support Barnsten by ordering Smart Mobile Studio via their website.

Sincerely

The Smart Mobile Team

announcement Barnsten cooperation reseller

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