Where is StringToJString and StrToNSStr in XE6?

The useful helper routines StringToJString and StrToNSStr (and other associated ones) moved between XE5 and XE6. In XE6 you can find them in the units Androidapi.Helpers and Macapi.Helpers respectively. But how to find other useful methods? I’ll tell you what I do: Use Windows Search.

You want to go to Indexing Options to set Windows Search up to be useful.

Windows Search Indexing Options

First select Modify and browse to the Source folder and add it to the list of indexed locations. I like to add the source folder as a favorite in Explorer too, to make it easier to get back there.

C:\Program Files (x86)\Embarcadero\Studio\14.0\source

Next click Advanced and go to the File Types tab and select .PAS file and any other file types you would like to have indexed, and change them to Index Properties and File Contents. It uses the plain text filter, which in my experience is good enough, and your only option (without installing a new one).

Indexing Options - Advanced - File Types

It takes a bit for the index to rebuild, but after that you can quickly search all of the XE6 source to find APIs, Helper Methods or any number of other useful code to aid in your development process. This is where that favorite to the source folder is helpful. Either search from the root of the source folder, or browse into a subfolder to only search specific source files.

There are other indexed searching utilities, and I’ve used many of them in the past. The advantage of Windows Search (probably it’s only advantage) is that it is built in and already running.

BlueTooth Remote Control Car

How to use BlueTooth is one of the most common requests with Delphi. During our Devices and Gadgets webinar David I. showed how to browse paired BlueTooth devices and connect to them.

But wait, there’s more! Daniele Teti & Daniele Spinetti of bit Time Software created an Android client app to control a BeeWi – BBZ201 – Mini Cooper S Bluetooth Car. It may work with other BeeWi Bluetooth remote control vehicles, but has not been tested with any (that I know of).

The Multitouch code is Copyright (c) 2006-2014 Iztok Kacin, Cromis and used under the BSD license.

It currently doesn’t have BlueTooth discovery, so once you pair your device you need to update the source code with the MAC address of your car.

I’ve created a GitHub repository for the project. It should work with XE5 or AppMethod just fine. I’ve got a version updated to XE6 that exposes the controls via App Tethering too, which I will upload later.

OpenGL ES Support on Mobile with XE6

OpenGL ES logoAppmethod, RAD Studio, Delphi and C++Builder XE6 all make it really easy to work with OpenGL ES on mobile devices. Under the covers FireMonkey is implemented with OpenGL ES on mobile (iOS & Android), OpenGL on OS X and DirectX on Windows. It provides a number of useful abstractions for working with 2D and 3D graphics, but sometimes you just want to get down to a lower level.

Here is all you need to access an OpenGL ES rendering context in your FireMonkey mobile application. This example is in Object Pascal, but should be easy enough to adapt to C++.

  1. Create a new FireMonkey Mobile application
  2. Select 3D application
  3. Add FMX.Types3D to the Interface uses clause
  4. In the Object Inspector, create a new event handler for the OnRender event for your form
  5. You now have access to the OpenGL render context.

You can work with the TContext3D that is passed in via a parameter, and your code will work across platforms automatically. If you want to work with the OpenGL ES APIs directly you can do that too with the following uses clause in your Implementation section:

uses
  // Gives you access to the FMX wrappers for GLES
  FMX.Context.GLES, 
{$IFDEF ANDROID}
  // Direct access to the Android GLES implementation
  Androidapi.Gles, FMX.Context.GLES.Android;
  // More useful units for Android
  //, FMX.Platform.Android, Androidapi.Gles2, Androidapi.JNI.OpenGL,
  // Androidapi.Glesext, Androidapi.Gles2ext;
{$ENDIF}
{$IFDEF IOS}
  // Direct access to the iOS GLES implementation
  iOSapi.OpenGLES, FMX.Context.GLES.iOS;
  // More useful units for iOS
  //, iOSapi.GLKIT, FMX.Platform.iOS;
{$ENDIF}

And here is an example event handler with a couple calls to the OpenGL ES APIs:

procedure TForm1.Form3DRender(Sender: TObject; Context: TContext3D);
begin
  glClearColor(1, 1, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT);
end;

This accesses the iOS and Android equivalents of the same OpenGL ES APIs. Thanks to the compiler directives, and the cross platform nature of OpenGL ES, this code just works. I’m not an OpenGL expert, but I looked through the OpenGL ES API and all the routines I tested worked, but I never did anything interesting with them.

Meet Me in Chicago & D.C./Baltimore for a First Look at XE6

I’m joining Bob Swart and Cary Jensen for the U.S. cities of their annual Delphi Developer Days 2014 tour with the keynote and a free evening event. During my keynote and the evening session I’ll show off Google Glass development with XE6, as well as using an EEG Brain-Computer Interface to control a Mini-Cooper via Bluetooth.

I highly recommend you find time to attend the whole two days of training. I always learn a lot.

May 5-6, 2014: Washington DC/Baltimore
SpringHill Suites Arundel Mills BWI Airport
Register for Training in Washington DC/Baltimore
The free evening event starts at 6:30 PM on Monday the 5th with pizza and drinks. Same location. [Register for free event]

May 8-9, 2014: Chicago
Holiday Inn Express Hotel & Suites, Arlington Heights (O’Hare Airport)
Register for Training in Chicago
The free evening event starts at 6:30 PM on Wednesday the 8th with pizza and drinks. Same location. [Register for free event]

Delphi Developer Days are two-day live Delphi events that provide you with the latest information on Delphi as well as practical techniques to help you improve your Delphi development skills. Each event includes both joint sessions, presented by Bob and Cary together, as well as simultaneous tracks, where Cary and Bob break out into separate rooms to present individual sessions. There is also an Embarcadero Technologies Keynote by Jim McKeeth and guest speaker sessions with Nick Hodges (former Delphi product manager) of Veeva Systems in DC/Baltimore, and with Ray Konopka of Raize Software in Chicago.

A wide variety of topics are covered. Some topics, such as FireDAC and mobile development, apply to the latest versions of Delphi, but there are also many topics that apply across many versions of Delphi. See the detailed description and agenda.

All attendees receive:

  • An extensive course book (several hundred pages in length) written by Cary and Bob that includes the material covered in their sessions
  • Source code examples from their sessions
  • A chance to win valuable prizes from sponsors.
  • Lunch on both days

Space is limited to the first 42 people in each city. There is a discount for attendees of previous 2009-2013 tours, and group discounts are available when registering three or more people from the same company.Visit www.DelphiDeveloperDays.com for complete information.Platinum Sponsors: Embarcadero Technologies, Sybase, An SAP Company, and TMS software. Gold Sponsors: Devart, Dr.Explain, Gnostice Information Technologies, and Raize Software.

C++Builder XE6 for Android Wallpaper

Remember the great Delphi for Android wallpaper? Well Dave has a new wallpaper to celebrate the new C++Builder for Android support.

C++Builder for Android

Thanks Dave for the great new wallpaper!

What You Need To Know #1

Do you know the song “Video Killed The Radio Star“? It seems like today it is “Twitter & G+ killed the blog post.” I thought I would summarize some of the recent news I’ve posted elsewhere.

  • bit Time Lab has a video showing off their multi-touch bluetooth app that controls a very small mini-cooper. They developed the libraries for multi-touch support and bluetooth they used with Appmethod (Object Pascal). Very cool!
  • Project Indy has an OpenSSL update for the Heartbleed vulnerability.
  • InterBase uses OpenSSL, but was never vulnerable to Heartbleed.
  • I’ll be at Delphi Developer Days in Chicago and D.C. and we will have free evening events there too. These are great events full of fabulous content (I’ve attended in the past). I highly recommend you check them out. I’ll be showing Delphi working with Google Glass, Brain-Computer Interface, FireDAC, REST, and anything else I can squeeze in.
  • I’m also traveling to India and South Korea this month.
  • I worked with Sarina on this Tutorial for accessing Parse.com from Appmethod Object Pascal with the REST components. Great technology.
  • Eric compiled a partial list of over 100 Delphi apps in the Play Store.
  • Eric Bonilha was featured in the Brazilian News for his work on a DigiFort app for Google Glass that stream live video to and from Google Glass. It is in Portuguese, but you can see some live demos of the app starting at just after 7 minutes in. All the software used to stream video and control cameras in that segment is written in Delphi by Eric and his team.
  • Curious about what is coming in XE6? There is a RAD Studio XE6 Sneak Peak event taking place April 16th. It looks really exciting!
  • I still get people asking about the new upgrade pricing. Check out the new License Recharge Program – if you own the latest version of Delphi, RAD Studio, or C++Builder then you qualify to save a lot of money when a new product is released.
  • David Intersimone and myself are running regular Google Hangout On-Air events. These are informal technical events we share some of the things we’ve been working on recently. Make sure you join the Embarcadero Technologies G+ community so you can be involved in the next one. The first two were experiments, we plan to promote the future ones better (although they will probably remain experimental and informal).

RAD Studio XE6 Preview Event

Thought Controlled Quadcopter

Last night I “controlled” my Parrot AR.Drone Quadcopter with my thoughts through my Emotiv EPOC Brain Computer Interface via an app written in Delphi XE5. I qualify “controlled” in that my flight pattern was a little irregular and short before I crashed it. It was a “look mom, no hands” moment though as the drone was clearly responding to my thoughts for the few seconds before it crashed. I’ve got a lot of work to do in improving the process, so I will be posting code and videos soon. If you want to get a start on it though, it is based on my work from the Devices and Gadgets webinar.

I’m presenting tomorrow at Boise Code Camp on “Is Thought the Future of Wearable Input?” and if all goes well I’ll have a brief demonstration of the tech in action. If you are in the area my presentation is at 11 AM in the Special Events Center at Boise State University.

Setting Android Settings

On the Android platform all the system wide settings that are accessible via the Settings app are also accessible to your app. You just need to add the uses permission WRITE_SETTINGS. Here is a simple Delphi XE5 example for changing the screen timeout.

First you need the following in your uses clause:

Androidapi.JNI.Provider, // JSettings_SystemClass
FMX.Helpers.Android; // SharedActivityContext

Here is the code to read and set the Screen Off Timeout:

function GetScreenOffTimeout: Integer;
begin
  Result := TJSettings_System.JavaClass.getInt(
    SharedActivityContext.getContentResolver,
    TJSettings_System.JavaClass.SCREEN_OFF_TIMEOUT,
    15000);  // 15 seconds is default is not found
end;

function SetScreenOffTimeout(ATimeOut: Integer): Boolean;
begin
  Result := TJSettings_System.JavaClass.putInt(
    SharedActivityContext.getContentResolver,
    TJSettings_System.JavaClass.SCREEN_OFF_TIMEOUT,
    ATimeOut);
end;

In the GetScreenOffTimeout we pass a default value to use if none is found. I passed in 15000, which is 15 seconds, or the smallest value for my phone. The largest value on my phone is 600000, which is 10 minutes. It appears you can set it to any value, even one that the settings app doesn’t explicitly list as an option.

There are lots of other settings available for your adjustment.

CodeRage C++

Tomorrow is the start of CodeRage 8 C++, which is a lot like regular CodeRage, but with an emphasis on C++Builder. This time there is a lot of coverage on the new iOS support, as well as the new REST Components and FireDAC data access.

It all starts with JT’s opening keynote at 6:00 AM Pacific Time, which may also be of interest to Delphi developers who want to get some glimmers of future plans, roadmaps and announcements. Actually most of the sessions will have content of interest to Delphi developers, especially if you’ve missed some of the more recent CodeRage conferences. But if you are a C++ developers, then be sure to make time for all the sessions!

CodeRage C++ - February 25-26, 2014

The Delphi Object Pascal Language

What’s in a name? That which we call a rose
By any other name would smell as sweet;

The other day I noticed Github has a language choice for Pascal, but not Delphi. It turns out originally they had Delphi listed as a language, but some of the Delphi clones were getting marked as Delphi, so they renamed it to the more generic Pascal. Which immediately resulted in people requesting they rolled it back.

This brings up a good question though, “What is Delphi and what is Object Pascal?” Interestingly there were three implementations of Object Pascal that evolved from the original Pascal. The one we are all familiar with was designed at Borland as part of Turbo Pascal. Apple also designed one consulting with Nicholas Wirth. And there was the Think Pascal IDE with it’s own flavor.

The Borland flavor of Object Pascal evolved into the language we see in Delphi today, while the other two faded away. There actually exists a few other variations of Object Pascal, most all of which were inspired by the language that still lives in Delphi today.

Personally I think it is exciting to see so many other tools and languages in the Object Pascal and Pascal space. That is part of what made C & C++ so vibrant: All the other languages wanted to copy them (Java, JavaScript, C#, etc.)

So back to the question, “What is Delphi and what is Object Pascal.” Object Pascal is the language that powers Delphi. Object Pascal can exist without Delphi, but part of what defines Delphi is it’s Object Pascal language. Just in the same way C++Builder isn’t the only implementation of C++, but part of C++Builder is the C++ language. So Delphi and C++Builder are each the whole package: Language + IDE + Compiler + Debugger + Libraries + Tools. You could say they are the definitive implementation of those languages.

Could we see Delphi with a different language? That would be interesting. At one end of the spectrum there was Delphi for PHP (which evolved into HTML5 Builder.) It was Delphi’s Rapid Application Development concept combined with the PHP language. And then Delphi Prism which used the Oxygene language variant of Object Pascal combined with Visual Studio and .NET.

In my opinion, Delphi is a specific version of Object Pascal, if for no other reason than because it has a fabulous runtime library and framework. Using Object Pascal without TStringList and all the other useful types, function and libraries that Delphi comes with wouldn’t be much fun.