Meet Me in Philly at the CodeCamp

Philly.NET CodeCampI’m joining Nick Hodges in King of Prussia, Pennsylvania for the Philly.NET Code Camp 2014 Refactored. I’ll be showing off the latest version of Appmethod, including the Free Forever C++ for Android version. Astute readers may have noticed that my sessions are not on .NET, and the conference isn’t actually in Philadelphia. I’m guessing that is the “Refactored” part.

If you are in the area, stop by and say hi. They still have tickets for the two day event where you can catch all three of Nick and my sessions, and maybe a few others if you are interested.


 

Unit Testing: What it is, Why you should be doing it, and how to do it

Saturday, June 21st, 2014 at 7:30 pm on 

Michael Feathers defines “legacy code” as “code that has no unit tests”. Without unit tests your code is fragile, hard to change, and unreliable. Unit testing is the only way that you can be sure that your code does what it is supposed to do.

This talk discusses the basics of Unit Testing by defining terms, discussing what Unit Testing is and is not, and talking about the best techniques and practices for writing unit tests.

All the demos will be in Delphi code, but the principles all remain the same: There no longer is an excuse for not writing unit tests.


Is Thought the Future of Mobile Input?

Sunday, June 22nd, 2014 at 10:30 am on 

The Brain-Computer Interface (BCI) is a mainstay of science fiction, but devices are appearing today to use our brainwaves as a computer input. Is it practical? How far away is it? What sort of input is possible and where is it being used?

We will look at the roots of the technologies that allow a view of the inner functions of the human mind, as well as the possibilities for direct input to, and augmentation of the mind, perception and thought processes. The process includes real-world examples and a demonstration with volunteers controlling software and hardware with only their thoughts and feelings. Gain an understanding of how this still evolving and largely unknown technology really works, how it can be used, and its longer-term implications.


Sharing Code and UI between iOS and Android

Saturday, June 21st, 2014 at 12:00 pm on 

You want to develop on Android and iOS, but rather not have to recreate your app or UI for each platform. This session shows you how to reuse up to 100% of your code and user interface to create native iOS and Android apps using Appmethod and C++. This isn’t your daddy’s C++ either; it has ARC, enhanced RTTI, visual designer, components and no pointer arithmetic (unless you are really into that).

Examples covering access to device sensors, local data storage and remote services. Also how to create a mobile app that extends the functionality of your desktop apps.


I plan on finding a good authentic Philly Cheesesteak Sandwich while I’m there too!

Philly Cheesesteak Sandwhich

Know Your Alignments

FireMonkey offers a lot more alignment options than those offered in the VCL. The Alignment aligns the control within its parent, setting anchors, size and position. The Default is None. To make it easier to think about them, you can group the different types of alignments.

  • Anchor and fill along edge – these are 4 of the alignments you are most likely familiar with.
    • Top, Bottom, Left, Right
  • Like the above, but takes precedence over other alignments
    • MostBottom, MostTop, MostLeft, MostRight
  • Fill parent, but preserve aspect ratio – very powerful, especially when applied to one of the new layouts, like the TScaledLayout.
    • Fit, FitLeft, FitRight
  • Resize only on one axis (width or height) to fill that axis of the parent and optionally centered
    • Vertical, VertCenter, Horizontal, HorzCenter
  • Miscellaneous
    • Client – Fills remaining space not occupied by other pinned controls.
    • Contents – Fills entire client area of the parent overlapping other controls.
    • Center – Just moves to the center without resizing.
    • Scale – Maintains relative size and position relative to the parent as it resizes.

Checkout the full DocWiki pages for more details on FMX.Types.TAlignLayout and Vcl.Controls.TAlign.

Clone from GitHub in Delphi IDE

There are a lot of interesting Delphi projects showing up on GitHub. GitHub offers a convenient Download ZIP function, not to mention a very easy to use Windows Desktop Client that has full support for managing local repositories, syncing them to GitHub and accessing GitHub projects via Cloning in Desktop.

Sometimes it is nice to just open the project in your IDE of choice directly from GitHub. Turns out this is just as easy as 1-2-3. Right above the Clone in Desktop and Download ZIP buttons there is a checkout URL with support for Subversion. Simple click Subversion, then click copy URL and your can then open the GitHub project directly from the Delphi or RAD Studio IDE.

github-subversion

This maintains the revision history locally so you can browse it from the history tab, but it doesn’t appear to allow checking changes back in.

You probably want to update the SVN client RAD Studio uses. This is easy enough too. Just download and install the Colab SVN 32-bit Windows client (don’t get 64-bit or Edge) and install it normally. Then edit your Registry and browse to “HKEY_CURRENT_USER\Software\Embarcadero\BDS\14.0\Subversion” and add a string value named SvnDllDir. This value of SvnDllDir should be the path to your SVN client install. Something like “C:\Program Files (x86)\Subversion Client” (without the quotes).

If you don’t like the fact the Colab Subversion site requires a login, there are other sources for download the Subversion command-line client. Just be sure you get the 32-bit version since the IDE is 32-bit. You may have luck with with the command-line tools that come with TortoiseSVN, or I’ve tested it with the Command-line client from Assembla and found it worked fine.

Delphi Sensors on Windows 8 Tablet

New in XE6 is support for VCL Sensors. What better way to show these off then on the 8″ Dell Venue 8 Pro Windows 8.1 Tablet. The VCLSensors sample ships with RAD Studio XE6. I simply deployed it to the Dell Venue 8 Pro and it runs great.

VCL Sensors on Dell Venue 8 Pro

 

I added one of the VCL Styles to it as well. You can see it running here with my favorite wallpaper. It shows the Latitude & Longitude from the GPS via the TLocationSensor, the motion from the accelerometer via the TMotionSensor and the compass heading + tilt from the compass and gyroscope via the TOrientationSensor.

These sensors behave exactly the same way as the FireMonkey mobile ones do on Android and iOS, but now you can take advantage of them with your desktop applications.

You can also use the Metropolis UI and the tablet optimized styles for a full screen tablet experience on the Dell tablet. Both with VCL and FireMonkey.

 

Parrot AR.Drone 2.0 Delphi Component

githubI took my code I previously used to control the Parrot AR.Drone and turned it into a reusable component. I added some more functionality to it as well, although there is a lot more to cover. The component is available on GitHub.

It should work with Delphi, C++Builder, Appmethod and RAD Studio on iOS, Android, Windows and OS X. I’d love to hear how it works for you and what you use it for!

Delphi XE6 is on Fire

Remember the demonstration I did showing how Delphi works great with Ouya? Well, there is a new set top box in town, the Amazon Fire TV. Just like the Ouya, it is a Android powered set top box. So, does it support everyone’s favorite Android development tool? Turns out it works great with Delphi XE6. It uses a wireless ADB connection, so you just need to follow their simple steps to Connect ADB and it shows up in the IDE as the Android device AFTB (not sure what that stands for). After that you can develop and deploy to it just like any other Android device.

When you run your app from the IDE it will popup and run on the Fire TV, but after you exit your app you won’t see it anymore. It appears Fire TV only displays apps that are loaded from their app store on the home screen. Not to worry, you can easily launch it from the Settings -> Applications screen. Simply select your app and choose Launch application.

By default your only input device is the Amazon Fire TV remote.

firetvremote

Simply handle the OnKeyUp event on your form and you will receive events with the key codes vkLeft, vkRight, vkUp, vkDown, vkMenu, vkHardwareBack, vkMediaPlayPause and a key value of 0 for the select, fast forward or rewind buttons. The Home and Voice Search buttons are always handled by the OS. If you choose to handle the vkHardwareBack then set the key value to 0 (or any other value) and the system will ignore it, otherwise your app will exit.

Fire TV also supports a gamepad as well as various other bluetooth input devices, like a bluetooth keyboard, which greatly expands the input options. You also could use App Tethering to tether a mobile or desktop/laptop app to your Fire TV app to provide input and display it on the big screen. Like an image receiver that receives pictures from your mobile device to display them to everyone in the room.

If you download the Fire TV SDK it exposes Game Controller and Notification classes. If there is interest I can post some Object Pascal wrappers for those later on.

 

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.