Marco Cantu

Syndicate content
Techie Italian Blogging on Delphi and More
Updated: 51 min 20 sec ago

RAD Studio Quality Update After 10.1 Berlin

Mon, 05/02/2016 - 06:38

The release of RAD Studio 10.1 Berlin marks another step towards improving the overall product quality and the company process of managing customer reported issues.

Issues Fixed in Berlin

Let me focus on 10.1 Berlin first. As we stated publicly (see slide below), in this release the team fixed 744 customer reported issues. The total number of internal issues fixed is more than 2,500 (which includes those 744), as most issues are reported internally.

This is 30% to 50% higher than recent releases, as Malcolm pointed out in his blog. Notice that these 744 are either bugs fixed or that don't reproduce, likely due to some other fix. The count doesn't include duplicates (issues reported by more than one person) or reports we decided not to fix because they are as expected, considered documentation issues, or other cases. With those, the overall number would be over a thousand.

April Hot-fixes to the Rescue

Despite the effort for fixing bugs, some new issues slipped in the release. In particular there were a couple of rather significant regressions for which we have already released two hot fixes:

Bugs Status and Quality Portal

Having said this, it is worth trying to make some assessment about the status of bugs, and particularly publicly reported bugs and feature requests. While not everything has been synchronized between the internal and the public system, most of the information should be updated now. Looking to Quality Portal issues reported as bugs, there are 4,595 entries of which 67% are either closed or resolved. This is good progress. Feature requests are mostly open, as they started coming in a few months back, when plans for 10.1 Berlin had already been done.

Given the project page for RAD Studio on the Quality Portal hasn't got a real picture of the quality status, I've been creating an alternative page, currently at https://quality.embarcadero.com/secure/Dashboard.jspa?selectPageId=13100 (viewing the page requires you to login to the system). A snapshot of the current status is below. The plan is to add similar widgets to the main project page.

Categories: News, Blogs, and Tips

Weak and Unsafe Interface References in Delphi 10.1 Berlin

Thu, 04/28/2016 - 07:45

Delphi 10.1 Berlin adds a couple of features to the Delphi language, bridging gaps between platforms and extending the Win32/Win64 interface reference model. This is not the only change to the language, but clearly the most relevant one. Another, focused on mobile, is the introduction of the native UTF8String type on all platforms, mobile compilers included.

But let me get back to the way references to interfaces work on the desktop compilers. By default, all references to interfaces use reference counting. As you assign a variable to the interface the reference count is increased, as the variable is set to nil or goes out of scope, the reference count is decreased. When the reference count gets to zero the object is deleted from memory. That is not actually always true, as the actual behavior is implemented by each class, so you can write a class that implements an interface and ignores the reference counting mechanism.

Anyway, getting back to the common scenarios in which reference count is active, you can have code like the following, which relies on reference counting to dispose the temporary object:

procedure TForm3.Button2Click(Sender: TObject); var one: ISimpleInterface; begin one := TObjectOne.Create; one.DoSomething; end;

What if the object has a standard reference count implementation and you want to create an interface reference that is kept out of the total count of references? You can now achieve this by adding the [unsafe] attribute to the interface variable declaration, changing the code above to:

procedure TForm3.Button2Click(Sender: TObject); var [unsafe] one: ISimpleInterface; begin one := TObjectOne.Create; one.DoSomething; end;

Not that this is a good idea, as the code above would cause a memory leak. By disabling the reference counting, when the variable goes out of scope nothing happens. There are some scenarios in which this is beneficial, as you can still use interfaces and not trigger the extra reference. In other words, an unsafe reference is treated just like... a pointer, with no extra compiler support.

Now before you consider using the unsafe attribute for having a reference without increasing the count, consider that in most cases there is another better option, that is the use of weak references. Weak references also avoid increasing the reference count, but they are managed. This means that the system keeps track of weak references, and in case the actual object gets deleted, it will set the weak reference to nil. With an unsafe reference, instead, you have no way to know the status of the target object (a scenario called dangling reference).

In which scenarios are weak reference useful? A classic case is that of two object with cross-references. In such a case, in fact, the object would artificially inflate the reference count of the other objects, and they'll basically remain in memory forever (with reference count set to 1), even when they become unreachable.

As an example consider the following interface, accepting a reference to another interface of the same time, and a class implementing it with an internal reference:

type ISimpleInterface = interface procedure DoSomething; procedure AddObjectRef (simple: ISimpleInterface); end; TObjectOne = class (TInterfacedObject, ISimpleInterface) private anotherObj: ISimpleInterface; public procedure DoSomething; procedure AddObjectRef (simple: ISimpleInterface); end;

If you create two objects and cross-reference them, you end up with a memory leak:

var one, two: ISimpleInterface; begin one := TObjectOne.Create; two := TObjectOne.Create; one.AddObjectRef (two); two.AddObjectRef (one);

Now the solution available in Delphi 10.1 Berlin is to mark the private field anotherObj as weak:

private [weak] anotherObj: ISimpleInterface;

Now the reference count is not modified when you pass the object as parameter to the AddObjectRef call, it stays at 1, and it goes back to zero when the variables go out of scope, freeing the objects from memory.

Now there are many other cases in which this feature becomes handy, and there is some real complexity in the underlying implementation. It is great feature, but one that takes some effort to fully master. Also, it does have some runtime cost, as weak references are managed (while unsafe ones are not).

Categories: News, Blogs, and Tips

RAD Studio 10.1 Berlin Launch Webinar Replay

Wed, 04/27/2016 - 09:45

The replay of last week launch webinar of RAD Studio, Delphi and C++Builder 10.1 Berlin by RAD Product Managers (myself included) is available on YouTube.

Some information about the webinar replay is also at http://community.embarcadero.com/blogs/entry/webinar-replay-introducing-rad-studio-delphi-and-c-builder-10-1-berlin

The YouTube video is available at https://www.youtube.com/watch?v=1CHPXbUeSJ8 

Categories: News, Blogs, and Tips

Some RAD Studio 10.1 Berlin Blogs and Videos

Wed, 04/27/2016 - 08:08

Here is a first batch of blogs posts and videos about RAD Studio 10.1 Berlin. More are coming, including an in-depth webinar next week.

10.1 Berlin New Installer and IDE

Great Installation Experience with new RAD Studio 10.1 Berlin at http://community.embarcadero.com/blogs/entry/great-installation-experience-with-new-rad-studio-10-1-berlin and follow the video at https://www.youtube.com/watch?v=4zt1TnYttds

Where is the ActiveX Project Type for Delphi 10.1 Berlin? at http://delphi.org/2016/04/where-is-the-activex-project-type-for-delphi-10-1-berlin/

Using the Floating Form Designer in Delphi at https://delphiaball.co.uk/2016/04/19/delphi-floating-form-designer/

New in FireMonkey for 10.1 Berlin

Customizing the style for a user interface control in RAD Studio 10.1 Berlin at http://community.embarcadero.com/write-blog-post/entry/customizing-the-style-for-a-specific-component

Introducing FireUI App Preview in RAD Studio 10.1 Berlin at http://community.embarcadero.com/write-blog-post/entry/rad-studio-fireui-app-preview-berlin. Also how to add components to the preview is explained at http://steema.com/wp/blog/2016/04/19/rad-studio-10-1-berlin-add-teechart-to-fireui-live-preview/. And a video on FireUI Mobile Previews offering a live preview at a glance at https://www.youtube.com/watch?v=D-CnrFdKM5M and also how to configure at https://www.youtube.com/watch?v=XEVMgCgWRLw

Accessing the Address Book on iOS and Android at https://delphiaball.co.uk/2016/04/22/accessing-address-book-ios-android-taddressbook/ and also at http://community.embarcadero.com/blogs/entry/using-the-new-taddressbook-component-on-ios-and-android-in-rad-studio-10-1-berlin and in a video at https://www.youtube.com/watch?v=UIgCg2qG3kc

What’s New Roundup For FireMonkey In #Delphi 10.1 Berlin On Android, Windows, OSX, And IOS at http://www.fmxexpress.com/whats-new-roundup-for-firemonkey-in-delphi-10-1-berlin-on-android-windows-osx-and-ios/

TListView design mode covered in a video at https://www.youtube.com/watch?v=vaQ-OtbAEh0

IoT and the coming RAD Server...

New IoT components videos at https://www.youtube.com/watch?v=lh8B6aIcO-Q and https://www.youtube.com/watch?v=tQlYAlvfpPQ. And the blog post at http://community.embarcadero.com/blogs/entry/try-to-use-iot-component-ti-sensortag-1-0-with-device-on-10-1-berlin

Swagger documentation for REST APIs at https://delphiaball.co.uk/2016/04/22/swagger-yaml-delphi

10.1 In-Depth Webinar Coming

Tune if for next week webinar: Fire up your business and users with RAD Studio 10.1 Berlin's “Enterprise Strong” Desktop, Mobile, Database, Server, Cloud and IoT Solutions. See http://community.embarcadero.com/all-events/viewevent/661-webinar-fire-up-your-business-and-users-with-rad-studio-10-1-berlin-s-enterprise-strong-desktop-mobile-database-server-cloud-and-iot-solutions

And stay tuned for more information about the 10.1 Berlin version Delphi, C++Builder and RAD Studio.

Categories: News, Blogs, and Tips

RAD Studio 10.1 Berlin Released Tuesday

Thu, 04/21/2016 - 02:41

As you probably know by now, Embarcadero has released Delphi, C++Builder and RAD Studio 10.1 Berlin on Tuesday, at a live event in the German capital city.

The Event in Berlin

This is a picture I took at the very start of the public event.

And this is a picture Matthias took of myself while presenting:

There was also a partners event, in which I gave more of a sales oriented overview. Some partners are always amused about how much I gesticulate, but I'm Italian, what can I do about it (Thanks, Richard)

And in the evening we did a joint launch session, in which we showed a comparison of the old and new installer, IoT components installation, FireUI App Preview on device, Beacon Fencing in action, and a Bluetooth controlled model car.

Remarkably, I was able to do all of these sessions even after my Mac decided to stop booting (SDD at fault). Thanks again to Matthias and Daniel for borrowing me their Macs -- and good I had all of my VMs in an external drive with me. 

The 10.1 Berlin Product Release

Here is some initial information and a number of relevant links, more will follow in the coming days from the entire team at Embarcadero. I'll probably blog about language features and other technical elements of the release.

The Embarcadero web site has been updated with information about the release, and you can find the more technical details in the feature matrix, or in the What's New page of the docwiki. There is also a press release on BusinessWire. There is also a detailed announcement by David I in the Embarcadero community site.

The Launch Webinar, Today

There has been a flurry of blogs and videos about the new features of the product, I'll offer a overview in a future blog post. For now, make sure you attend one of the sessions of todays's webinar (3 PM Central Europe, 11 AM Pacific, tomorrow morning in Asia) where I'll be online with the other PM answering your questions after the session.

PS: Did I mention there is a 10% introductory discount over the next 30 days? For both new licenses and updates

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #41

Mon, 04/18/2016 - 04:50

Another couple of weeks since my last posts collection, here is some references to interesting links -- waiting for tomorrow event in Berlin

The unexpected blog post of the month goes to The Delphi Open Tools API Book at http://www.davidghoyle.co.uk/WordPress/?page_id=1110 (very interesting, although I had very ltitle time to look into the actual content).

Technical Blog Posts

The hirearchical tree (by we should probably say graph) of all FireMonkey objects, at http://community.embarcadero.com/blogs/entry/inheritancetree-fmx-r101 from one of the developers

Database Application Tools for FireDAC that ship with our products by David I at http://community.embarcadero.com/blogs/entry/database-application-tools-for-firedac-that-ship-with-our-products-check-them-out

Using C++11 Lambda functions with the C++Builder Parallel Programming Library also by David I at http://community.embarcadero.com/write-blog-post/entry/using-c-11-lambda-functions-with-the-c-builder-parallel-programming-library

Interfacing A IoT Water Leak Sensor Via Bluetooth With Firemonkey In Delphi 10 Seattle On Android (article by FMX Express) at http://www.fmxexpress.com/interfacing-a-iot-water-leak-sensor-via-bluetooth-with-firemonkey-in-delphi-10-seattle-on-android/

Third Party Tools

Visual Arduino programming for kids and professionals using Visuino by Mitov Software - powered by Embarcadero Delphi (and summarized by David I ) at http://community.embarcadero.com/blogs/entry/visual-arduino-programming-for-kids-and-professionals-using-visuino-by-mitov-software-powered-by-embarcadero-delphi

Upgraded SVG Component Library For Firemonkey In Delphi 10 Seattle On Android And IOS (article by FMX Express) at http://www.fmxexpress.com/upgraded-svg-component-library-for-firemonkey-in-delphi-10-seattle-on-android-and-ios/

A tutorial "On Data Files and Configuration in Delphi Programs" (by Warren Postma) at http://delphicodemonkey.blogspot.fr/2016/04/on-data-files-and-configuration-in.html

Other Blogs Posts

Getting ready for Linux, just in case (by Warren Postma)... http://delphicodemonkey.blogspot.fr/2016/04/linux-essentials-for-delphi-developers.html

Google, Chrome and Delphi by Allen Bauer at http://blog.therealoracleatdelphi.com/2016/04/google-chrome-and-delphi.html

Conclusion

Again, stay tuned to tomorrow event (on social media like Twitter if you cannot be there) and the webinar on Thursday.

Categories: News, Blogs, and Tips

New highlights of RAD Studio webinar and the Berlin event

Fri, 04/08/2016 - 03:23

On April 21st, Embarcadero is running a webinar offering an overview of the latest release of the development tools products and their directions. I'll be hosting it with Sarina DuPont: "RAD Studio Product Managers Marco Cantu' and Sarina Dupont will cover the overall product directions and provide details about today's product and its future".

The webinar will be repeated 3 times during the day, for different time zones, covering Delphi, C++Builder, and RAD Studio. You can sign up at https://attendee.gotowebinar.com/rt/8114586402052971010.

Two days before, on April 19th, there will be a public event with the same focus in Berlin, Germany. I'll be in Berlin to give a keynote session at the event, followed by in-depth technical sessions in German language. The program is available at https://de.xing-events.com/RAD-Studio-Berlin.html. If you live in the area, you're more than welcome, and I'll be available for the entire day to discuss anything Delphi or RAD Studio related (and don't miss the evening part of the event).

There are great new features coming to the product, so don't miss these opportunities to learn about them. Of course, you can buy RAD Studio or Delphi or C++Builder today (check out our great offers) with update subscription, to get your hands on the product today (if you are not already on 10 Seattle) and receive new releases in the future.

Categories: News, Blogs, and Tips

Embarcadero Cool App Contest

Tue, 04/05/2016 - 01:19

Embarcadero has started a contest for "cool apps" with monthly winners. you can read all of the information at:

http://community.embarcadero.com/article/news/16221-join-our-club-of-elite-embarcadero-developers-show-us-your-cool-apps

There are submission rules, you basically have to submit a short video of the app, and you can use any technology (mobile, desktop, multitier, anything).  Submit your cool apps to share the fame as an elite Embarcadero developer.

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #40

Wed, 03/23/2016 - 07:16

Another collection of links to blogs posts, news, and other tidbits of interest to Delphi and RAD Studio developers.

Official Embarcadero Updates

The company has a new web site at https://www.embarcadero.com/ exclusively focused on development tools. Database management tools have been moved to the parent company web site, http://www.idera.com. This is part of Embarcadero new Dedicated Developer Strategy.

New Webinar on Updating from Delphi 2007 to Delphi 10 Seattle, tomorrow, by Jim McKeeth at http://community.embarcadero.com/blogs/entry/webinar-from-delphi-2007-to-10-seattle-easy

​Top 10 Ways to Monetize on Windows 10 at http://community.embarcadero.com/article/technical-articles/16216-top-ten-ways-to-monetize-windows-10-with-rad-studio

If you live in Germany, you might be interested in this special event April 19th in Berlin, https://www.amiando.com/RAD-Studio-Berlin.html 

Technical Blog Posts

Meet the new Embarcadero MVPs by Jim at http://delphi.org/2016/03/meet-the-new-embarcadero-mvps/

White paper on new JSON features in 10 Seattle, by Pawel at http://community.embarcadero.com/blogs/entry/new-json-features-in-rad-studio-10-seattle-whitepaper

​Nick got back to periodic summaries at http://www.codingindelphi.com/blog/flotsam-and-jetsam-112/

What's your favorite Delphi Demo by Jim at http://delphi.org/2016/03/what-is-your-favorite-delphi-demo/

Expand your toolkit with GetIt at https://ultimatedelphi.wordpress.com/2016/03/06/expand-your-development-tool-kit-with-getit/

Windows 10 Components in 10 Seattle by Jordi at http://thundaxsoftware.blogspot.it/2016/03/testing-new-windows-10-components-of.html

Not strictly Delphi, but very interesting post, "The Definitive Guide on Win32 to NT Path Conversion", by Google at http://googleprojectzero.blogspot.it/2016/02/the-definitive-guide-on-win32-to-nt.html

More Tidbits and Third Parties

A new Delphi REST library at http://www.andreamagni.eu/wp/2016/03/introducing-mars-curiosity-a-new-delphi-rest-library/

DataSnap filters compendium by Daniele at http://www.danieleteti.it/datasnap-filters-compendium-updated-to-delphi-10-seattle/

Pascal Analyzer, http://www.peganza.com/products.html#PAL

That's all for this week.

Categories: News, Blogs, and Tips

Considerations on StackOverflow 2016 Developer Survey

Mon, 03/21/2016 - 03:46

The popular StackOverflow site has released the results of their developers survey. which includes some interesting information -even if it skewed towards web developers. You can read the complete results at  http://stackoverflow.com/research/developer-survey-2016.

In this blog post I want to share some considerations about the data, well-aware that the self-selected audience is very much geared towards web development or (to be more precise) full-stack developers (30%) while only 7% claim to be "desktop developers" -- which is RAD Studio core audience.

The most popular language is JavaScript, which is not surprising given the focus, although it is also the most popular back-end development technology, way ahead of Java and PHP. The developers age and their experience is also a bit different than those in our surveys, and varies quite a bit by country. Roughly 50% of the developers who answered (or, maybe, who had time to answer) have less than 5 years experience as developers and in their 20ies; also a large percentage (45% has a site reputation below 100). This is more of a reflection of the StackOverflow users than of the developers at large. My impression is older developers favor different online communities, if any, but this is really a side issue.

Looking into the actual data, with JavaScript leading and JavaScript libraries on client and server side (Angular.js, Node.js) on the rise, it was nice to see that while Delphi was not listed as an option, it was the most typed entry in the "others" category, with over 650 respondents typing the tool name: 

A trend I've seen discussed online is the fact that developers using OS X are growing over those using Linux, a result probably influenced by the fact taht a Mac is needed for iOS development. Windows remains by far the OS most used by developers (around 50%). A fun fact is that VisualBasic also wins a catecory, that for the most dreaded technology. One think I wasn't too happy to read is that the most popular development environment is... Notepad++, but clearly given the web developer audience editors have a more higher role than IDEs. Delphi gets a "write in" mention also in this category.

Finally, I could not avoid noticing the age distribution of the Star Trek fans vs. the Star Wars fans. I would probably have been interesting to correlate age also with developer technologies, but this is what we have:

 

Categories: News, Blogs, and Tips

Writing a Windows Shell Extension

Wed, 03/16/2016 - 03:48

This is a technical article covering the content of my last week skill sprint about Writing Windows Shell Extensions in Delphi. Not really a new concept, but worth sharing. In any case, resources for the skill sprint (including video reply) are at http://community.embarcadero.com/blogs/entry/skill-sprint-windows-shell-integration and the code download is at http://www.marcocantu.com/files/ShellSkillSprint.zip.

Building a Shell Extension

Windows Resource Explorer Extensions, or Shell Extensions, are in-process COM objects that implement given interfaces. In other words, you can write a COM object (part of an ActiveX or COM library) and register it in the system as a shell extensions. You've likely seen applications that adds themselves in Explorer, we can use Delphi to do the same.

The program in question is a “to-do” application tied to files. It has a simple database table storing filenames and notes about these files. The form has a DBGrid component showing only a single column containing the filenames and a memo control hosting the notes related to the current file. The DBGrid is set up as a read-only component. In fact, users should not be able to create new records except by dragging a file onto the form (a portion of the program I'm not going to discuss here, as it doesn't related with COM support) or by using an extra Explorer menu. Here is the dmeo in action, with the active shell extension additional menu item and the target application:

Creating a Context-Menu Handler

Once you have the base program running, you can add a shell extension to the system to let the user simply select a file and “send” it to the application without having to do the dragging operation, which is not always handy when there are many programs running. A context-menu extension is one of the available Windows shell extensions and is activated every time a user right-clicks a file in the Windows Explorer (given the file extensions is associated with the shell extension).

Technically, a context menu is a COM server exposing an internal object that is going to be created and used by the system. A context-menu COM object must implement two different interfaces, IContextMenu and IShellExtInit. The first interface defines specific actions for the context menu, such as defining the number of menu items to add and their text, while the second interface defines a way to access the file or files the user is operating on. This is the resulting definition of the COM server object class:

type   TToDoMenu = class(TComObject, IUnknown,     IContextMenu, IShellExtInit)   private     fFileName: string;   protected     {Declare IContextMenu methods here}     function QueryContextMenu(Menu: HMENU; indexMenu, idCmdFirst, idCmdLast,       uFlags: UINT): HResult; stdcall;     function InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; stdcall;     function GetCommandString(idCmd: UINT_PTR; uFlags: UINT; pwReserved: PUINT;       pszName: LPSTR; cchMax: UINT): HResult; stdcall;     {Declare IShellExtInit methods here}     function IShellExtInit.Initialize = InitShellExt;     function InitShellExt (pidlFolder: PItemIDList; lpdobj: IDataObject;       hKeyProgID: HKEY): HResult; stdcall;   end;

Notice that the class implements the Initialize method of the IShellExtInit interface with a differently named method, InitShellExt. The reason is that I wanted to avoid confusion with the Initialize method of the TComObject base class, which is the hook we have to initialize the object, as described earlier in this chapter. Let’s examine the InitShellExt method first; it is definitely the most complex one:

function TToDoMenu.InitShellExt(pidlFolder: PItemIDList;   lpdobj: IDataObject; hKeyProgID: HKEY): HResult; stdcall; var   medium: TStgMedium;   fe: TFormatEtc; begin   Result := E_FAIL;   // check if the lpdobj pointer is nil   if Assigned (lpdobj) then   begin     with fe do     begin       cfFormat := CF_HDROP;       ptd := nil;       dwAspect := DVASPECT_CONTENT;       lindex := -1;       tymed := TYMED_HGLOBAL;     end;     // transform the lpdobj data to a storage medium structure     Result := lpdobj.GetData(fe, medium);     if not Failed (Result) then     begin       // check if only one file is selected       if DragQueryFile (medium.hGlobal, $FFFFFFFF, nil, 0) = 1 then       begin         SetLength (fFileName, 1000);         DragQueryFile (medium.hGlobal, 0, PChar (fFileName), 1000);         // realign string         fFileName := PChar (fFileName);         Result := NOERROR;       end       else         Result := E_FAIL;     end;     ReleaseStgMedium(medium);   end; end;

The initial portion of the method transforms the pointer to the IDataObject interface, which we receive as a parameter, into the same data structure used in a file drop operation, so that we can read the file information by using the DragQueryFile function again. This complex way of coding is actually the simplest one you can use! At the end of this operation, we have the value of the file name. Any selection of multiple files is not accepted.

We can now look at the methods of the IContextMenu interface. The first method, QueryContextMenu, is used to add new items to the local menu of the file. In this case, we add a new menu item (calling the InsertMenu API function) only if the ToDoFile application is running. We can determine this by searching for a window corresponding to the TToDoFileForm class, which should be unique in the system. The result of the function is the number of items added to the menu:

function TToDoMenu.QueryContextMenu(Menu: HMENU;   indexMenu, idCmdFirst, idCmdLast, uFlags: UINT): HResult; begin   // add entry only if the program is running   if FindWindow ('TToDoFileForm', nil) <> 0 then   begin     // add a new item to context menu     InsertMenu (Menu, indexMenu,       MF_STRING or MF_BYPOSITION, idCmdFirst,       'Send to ToDoFile');     // Return number of menu items added     Result := 1;   end   else     Result := 0; end;  

Now that items have been added to the menu, a user can select them. While the user moves over the items, a descriptive message is displayed in the status bar of the Windows Explorer. The menu ID (idCmd) we receive in the GetCommandString method is simply the relative number, starting with zero, of the items we have added to the menu. When the cursor is over an item, we simply copy a string with its description to the buffer provided by the system:

function TToDoMenu.GetCommandString(idCmd: UINT_PTR; uFlags: UINT; pwReserved: PUINT;       pszName: LPSTR; cchMax: UINT): HResult; stdcall; begin   if (idCmd = 0) and (uFlags = GCS_HELPTEXT) then   begin     // return help string for menu item     strLCopy (pszName, 'Add file to the ToDoFile database', cchMax);     Result := NOERROR;   end   else     Result := E_INVALIDARG; end;  

The final step is the operation to do once a menu item is selected. The InvokeCommand method receives a pointer to a structure holding the request. This method follows a standard pattern of first checking that the request is valid by looking at the two 16-bit words of the lpici.lpVerb value. After these preliminary (but required) steps, we check the value to see which menu item was activated; or, if the context menu has only one item, as in this case, we simply test for a value of zero. The following is the skeleton of the code, before we add the specific action:

function TToDoMenu.InvokeCommand(var lpici: TCMInvokeCommandInfo): HResult; var   hwnd: THandle;   cds: CopyDataStruct; begin   Result := NOERROR;   // Make sure we are not being called by an application   if HiWord(Integer(lpici.lpVerb)) <> 0 then   begin     Result := E_FAIL;     Exit;   end;   // Make sure we aren't being passed an invalid argument number   if LoWord(lpici.lpVerb) > 0 then   begin     Result := E_INVALIDARG;     Exit;   end;   // execute the command specified by lpici.lpVerb.   if LoWord(lpici.lpVerb) = 0 then   begin   ... // send data to application   end; end; Sending Data to the Application

Because we have the file name the user is operating on, all we have to do in the context-menu handler is send this name to the main form of the ToDoFile application. The problem is that the context-menu handler DLL runs in the Windows Explorer process, so it cannot send the value of a memory pointer to another process. This would simply be useless; as in Win32, different applications have separate memory address spaces. We could have used OLE Automation to communicate with the main program, however in this case I've resorted to a standard Windows technique, the wm_CopyData message. This is a special Windows message, which can be used to send a memory buffer to another application: Windows will resolve all the memory conversion problems for us.

Here is the core of the code of the InvokeCommand method, that was missing above:

// get the handle of the window hwnd := FindWindow ('TToDoFileForm', nil); if hwnd <> 0 then begin // prepare the data to copy cds.dwData := 0; cds.cbData := ByteLength (fFileName); cds.lpData := PChar (fFileName); // activate the destination window SetForegroundWindow (hwnd); // send the data SendMessage (hwnd, wm_CopyData, lpici.hWnd, Integer (@cds)); end else begin // the program should never get here MessageBox(lpici.hWnd, 'FilesToDo Program not found', 'Error', MB_ICONERROR or MB_OK); end;

As the context-menu handler sends data to it, the application has to be extended to handle the wm_CopyData message. In this event handler, we receive the same structure we sent on the other side. As a result, extracting the filename is actually very simple, but keep in mind that this is so only because Windows does a lot of work behind the scenes.

The code added to the form of the ToDoFile application restores the application if it was minimized and retrieves the name of the file:

procedure TToDoFileForm.CopyData(var Msg: TWmCopyData); var Filename: string; begin // restore the window if minimized if IsIconic (Application.Handle) then Application.Restore; // extract the filename from the data Filename := Copy ( PChar (Msg.CopyDataStruct.lpData), 1, Msg.CopyDataStruct.cbData div 2); // now insert a new record (omitted) Registering the Shell Extension

After writing this shell extension, we must register it. With the Run | ActiveX Server | Register command of the RAd Studio IDE, we can register the server in the system, but only if the operating system and the shell extensions are 32bit applications. For a 64bit version of Windows you need to build the COM server with a 64bit target, and perform a manual registration by invoking regsvr32.exe and passing the COM server DLL as parameter. (Yes, this has "32" in the name even for 64 bit systems).

In any case, we still have to provide some extra information to register it as a shell extension. There are several approaches: you can edit the Registry manually, you can write a REG file, or you can add registration information right into the COM server library, which is my preferred approach.

In a Delphi COM server, the default registration takes place in the TComObjectFactory class, when the UpdateRegistry method is executed. We can modify the default registration by inheriting a class from the standard class factory class and overriding this method:

type   TToDoMenuFactory = class (TComObjectFactory)   public     procedure UpdateRegistry (Register: Boolean); override;   end; procedure TToDoMenuFactory.UpdateRegistry(Register: Boolean); var Reg: TRegistry; begin inherited UpdateRegistry (Register); Reg := TRegistry.Create; Reg.RootKey := HKEY_CLASSES_ROOT; try if Register then if Reg.OpenKey('\*\ShellEx\ContextMenuHandlers\ToDo', True) then Reg.WriteString('', GUIDToString(Class_ToDoMenuMenu)) else if Reg.OpenKey('\*\ShellEx\ContextMenuHandlers\ToDo', False) then Reg.DeleteKey ('\*\ShellEx\ContextMenuHandlers\ToDo'); finally Reg.CloseKey; Reg.Free; end; end;

In the initialization section of the COM object unit, we also need to create a new global object of this class instead of the base class factory class:

initialization TToDoMenuFactory.Create (ComServer, TToDoMenu, Class_ToDoMenuMenu, 'ToDoMenu', 'ToDoMenu Shell Extension', ciMultiInstance, tmApartment);

This is all in terms of the code. To see this demo in action, refer to the video in the skill sprint resource page linked above.

Categories: News, Blogs, and Tips

Stepping through Values in a Delphi for Loop

Mon, 02/29/2016 - 02:03

There has been a recent request to add to for loop in the Object Pascal language the ability to add a step, that is an increment different from one. Here is an alternative implementation using a for..in loop and a custom enumerator.

Once I saw the request it reminded me of a demo I have in my Object Pascal Handbook (which originally came from my Delphi 2007 Handbook), The demo is available at https://github.com/MarcoDelphiBooks/ObjectPascalHandbook/ blob/master/10/NumbersEnumerator/NumbersEnumerator_MainForm.pas and shows how to build an enumerator over a range of numeric value. The only missing feature is the ability to have a Step property to skip value in the sequence, counting by 2, 3, 4 and so on. The other issue of the demo is it uses an object of a class, which implies the need of creating and freeing the object. Also the way properties are set is a bit cumbersome.

In the new version (listed below) I have moved from using classes to using records, still keeping the enumeration as a nested type, and added a static class function to initialize the data structure in a single call. The goal is to be able to use it as follows:

procedure TForm1.btnTestClick(Sender: TObject); var   I: Integer; begin   for I in TNumbersRange.Range (5, 13, 3) do     Show (IntToStr (I)); end;

Of course, you could also define a global Range () function, rather than a class method.

Below is an image with the type definition, followed by a second one with the core implementation. They are followed by the code itself, which might not be as well formatted and readable (hence the images). Feel free to use it any way you like. 

 

Here is the record declaration and definition in text format:

type   TNumbersRange = record   public   type     TNumbersRangeEnum = record     private       nPos: Integer;       nStart: Integer;       nEnd: Integer;       nStep: Integer;     public       constructor Create (aRange: TNumbersRange);       function MoveNext: Boolean;       function GetCurrent: Integer;       property Current: Integer read GetCurrent;     end;   private     NStart: Integer;     NEnd: Integer;     NStep: Integer;   public     class function Range (aStart, aEnd, aStep: Integer): TNumbersRange; static;     function GetEnumerator: TNumbersRangeEnum;   end; implementation uses Math; class function TNumbersRange.Range (aStart, aEnd, aStep: Integer): TNumbersRange; begin Result.NStart := aStart; Result.NEnd := aEnd; Result.NStep := aStep; end; { TNumbersRange } function TNumbersRange.GetEnumerator: TNumbersRangeEnum; begin   Result := TNumbersRangeEnum.Create (self); end; constructor TNumbersRange.TNumbersRangeEnum.   Create(aRange: TNumbersRange); begin   nStart := aRange.NStart;   nEnd := aRange.NEnd;   nStep := IfThen (aRange.NStep = 0, 1, aRange.NStep);   nPos := aRange.nStart - nStep; end; function TNumbersRange.TNumbersRangeEnum.   GetCurrent: Integer; begin   Result := nPos; end; function TNumbersRange.TNumbersRangeEnum.   MoveNext: Boolean; begin   Inc (nPos, nStep);   Result := nPos <= nEnd; end;

 

 

 

 

   
Categories: News, Blogs, and Tips

ObjectDebugger for Delphi 10 Seattle

Wed, 02/24/2016 - 02:26

I've just uploaded on GitHub my runtime Object Inspector, or ObjectDebugger, for VCL applications.

This is a component I wrote a lot of time ago for a Delphi 3 book (but never published as open source before) that you drop on a form and lets you inspect forms and components properties at runtime, and edit quite a few of them (including string lists and some other complex properties). It offers also access to some private data. As you can see from the source, it is based on the old TypInfo unit, not the newer RTTI code.

The code is at https://github.com/marcocantu/ObjectDebugger

Feedback and contributions ar more than welcome. Below is a simple screen shot:

PS. Thanks to Alain for asking about the component, which prompted me to make the code available.

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #39

Mon, 02/22/2016 - 04:46

Another collection of relevant news and blog posts on Delphi and RAD Studio, from the last couple of weeks.

Official Updates, Roadmap, Birthday, and New Chinese Year

Embarcadero has released hotfixes for XE7 and XE8 and some missing C++ files for 10 Seattle.

We have a roadmap at http://community.embarcadero.com/article/news/16211-embarcadero-rad-studio-2016-product-approach-and-roadmap-2

Another Delphi birtday, 21st, as you can read on http://blog.therealoracleatdelphi.com/2016/02/delphi-at-21-era.html

Chinese new year, is the year of the FireMonkey, our great multi-device development framework, http://delphi.org/2016/02/the-year-of-the-firemonkey/

Techical Blog Posts

"Updating 32bit code to Delphi 64bit", great summary by Stephen Ball at https://delphiaball.co.uk/2016/02/16/delphi-64bit-code/

"Setting the VCL application icon, by Craig Chapman at http://chapmanworld.com/2016/02/17/rad-studio-setting-the-vcl-application-icon/

"10 Reasons to use PAServer for Windows Deployment, by Jim McKeeth at http://delphi.org/2016/02/10-reasons-to-use-paserver-for-windows-deployment/

Third Party

EurekaLog 7.4 released, http://eurekalog.blogspot.it/2016/01/eurekalog-7-4.html 

Interesting NFC library for Android, at http://www.winsoftxe.com/anfclib.htm

 

Categories: News, Blogs, and Tips

RAD Studio iOS Developer Certificate Issue Possibly Caused by Apple WWDR Certificate Expriration

Mon, 02/15/2016 - 07:29

Starting yesterday (Feb 14th), a few RAD Studio iOS developers have been experiencing provisioning issues, due to the expiration of an Apple intermediate certificate, not of their own developer certificate. See the following links for more information and how to fix the issue:

While this is mentioned on Google+ and I could have tweeted a link, I have the impression this is going to hit quite a few developers in the coming days and weeks, so I felt it was better to capture it in a blog post as well. 

Categories: News, Blogs, and Tips

RAD Studio Hotfixes for XE8 and XE7 with 10 Seattle fixes

Fri, 02/12/2016 - 13:48

Yesterday Embarcadero has released two hotfixes for RAD Studio XE7 and RAD Studio XE8 including a number of bug fixes that have already been made available in RAD Studio 10 Seattle.

This effort is part of the Update Subscription benefits (the fixes are made available only to Update Subscription customers) and it is tied to the request coming from customers of increasing the support for older versions.

Here are the CodeCentral download links:

As you can see from the names, these updates have been in development and QA for a little time, but it took some extra effort to ensure their quality.

At the very bottom of the two pages above you'll see the list of fixes covered by each of the two hotifes. These fixes are in many different areas of the tool, from RTL to VCL, from mobile to FireDAC. Notably there is improved support for iOS 9, OS X El Capitan and Windows 10 for the older versions of RAD Studio. There are also some significant fixes to the XE8 generic TList and TListHelper.

Categories: News, Blogs, and Tips

Delphi 2016 Roadmap

Tue, 02/09/2016 - 01:35

The RAD Studio roadmap for 2016, including plans for Delphi and C++Builder for the current year, is now public. You can find it at:

http://community.embarcadero.com/article/news/16211-embarcadero-rad-studio-2016-product-approach-and-roadmap-2

As you can see, there is a lot of ongoing development and some great releases coming soon. The best way to get them? Buy 10 Seattle now (unless you already have it) along with 1 year of Update Subscription.

This is far from complete list of what's coming, and highlights only the main themes. If you are looking forward for other features, feel free to post your suggestions to Embarcadero Quality Portal or reach either myself or any of the other RAD Studio Product Managers. As always comments are welcome also here and on the community site, but no flames, please.

Categories: News, Blogs, and Tips

Delphi Blogs of the Week/Month #38

Wed, 02/03/2016 - 09:50

Here is another round up of interesting links and blog posts for Delphi developers, over the last couple of weeks. Meanwhile the blog UI redesign continues, but it is still much of a work in progress.

From Embarcadero

Skill sprints at https://www.embarcadero.com/landing-pages/skill-sprints

New Bogo (Buy One Get One) offer at http://www.embarcadero.com/radoffer

Technical Blog Posts

A Splash Form in FireMonkey by Uwe Raabe at http://www.uweraabe.de/Blog/2016/01/22/a-splash-form-in-firemonkey/

Videos that will help you move your Delphi, C++Builder and RAD Studio projects forward by David I at http://community.embarcadero.com/blogs/entry/videos-that-will-help-you-move-your-delphi-c-builder-and-rad-studio-projects-forward

On Conditional Compilation by Uwe Raabe at http://www.uweraabe.de/Blog/2016/01/22/on-conditional-compilation/

Decompressing the TRESTResponse by Jim McKeeth at http://delphi.org/2016/01/decompressing-the-trestresponse/

Delphi TouchID wrapper for iOS by David I at http://community.embarcadero.com/blogs/entry/delphi-touchid-wrapper-for-ios

More windbg tricks with Delphi – how to ignore specific exceptions by Marc Durdin at https://marc.durdin.net/2016/01/more-windbg-tricks-with-delphi-how-to-ignore-specific-exceptions/

Hacking The Android JNI To Add MultiLine Notifications For Firemonkey In Delphi 10 Seattle by FMXExpress at http://www.fmxexpress.com/hacking-the-android-jni-to-add-multiline-notifications-for-firemonkey-in-delphi-10-seattle

Third Party

Cool new FMX components by Graham Murt @kscomponents, see http://community.embarcadero.com/blogs/entry/cool-new-fmx-components-by-graham-murt-kscomponents and directly at https://github.com/gmurt/KernowSoftwareFMX/blob/master/README.md

Written in Delphi

Non Stick Mouse in corners of Windows 10 by Jonathan Barton at http://www.jawfin.net/?page_id=143

Categories: News, Blogs, and Tips

Blog UI Redesign in Progress

Mon, 02/01/2016 - 03:02

As you might have seen if you visited my blog during the last two days, I'm in the process of a complete redesign of the blog user interface.

I'm moving from a totally custom CSS style written when I first built this blog, in September 2005, to a Bootstrap-based web site. I started from a rather standard blog design from the Bootstrap demos, and done some limited touching. I'm really expecting to go beyond basic functionalities, but I have still quite a few features to implement, like a folding side menu, cleanup of a few links, and more.

I have not migrated the blog to a new engine, as keeping all of the existing content and links won't be easy. So this blog HTML rendering is still powered by XSLT and is based on XML data structures generated by a Delphi-powered application.

I hope you'll appreciate the results... but unless you see something totally broken, please wait reporting issues for a few more days, while I'm finishing the work.

Categories: News, Blogs, and Tips

Editing Delphi Code on a Mac

Fri, 01/29/2016 - 03:49

Over the last year, there has been an increasing push in the development of source code editors and even full development environments based on portable code and available on multiple platforms, including Mac OS X. Here are some notes about my experiments with Object Pascal enabled editors on the Mac.

As a side note, most of this editors are based on HTML + JavaScript (and variations like TypeScript), but there are some exceptions. And before you ask, Embarcadero is not currently officially endorsing any of these solutions, but we are looking into this area to understand how valuable this would be for Delphi (and C++) developers.

Visual Studio Code

Microsoft entrance into the area of cross platform hosted development tools made a significant splash last year. Visual Studio Code is a very interesting project, mainly oriented to development with scripting languages and web technologies, but with capabilities that go well beyond those of an editor. While not a replacement of Visual Studio for C# development, it works pretty well on Mac OS X and has a couple of Object Pascal language extensions (among many others). Being backed by Microsoft, makes this project highly visible. Some links:

Below is a screenshot of some Delphi code on my Mac in Visual Studio Code.

Atom

Another very interesting open source and cross platform editor is Atom, which is backed by GitHub. Atom is more of an editor than a full development environment, is focused on customization (or hack-ability), and is extremely fast. There are Object Pascal language bindings also for it (done by the same developer of the Pascal VSCode plugin). Links:

And here is a screen shot, with the same Delphi source code file.

Trolledge

This is not such a popular editor, but a very interesting one for me. In fact, rather than in JavaScript/HTML technologies it is written in Delphi and uses FireMonkey for the user interface. Trolledge comes natively with Delphi support, and it is available (not surprinsingly) for Windows and Mac. It does support many different programming languages, though, from JavaScript to C#. Links:

As you can see in the image below, opening a form automatically opens the matching designer in a second text editor. This is the only editor with a core knowledge of Delphi and its language and architecture.

What's Your Take?

So, what's your take on these editors and IDEs? I end up using Delphi code editors on the Mac almost only for reading code, as writing in the Delphi editor is significantly better. But I increasingly use these editors for my HTML and JavaScript work. While the lack of designers and other integrated tools severely limits their scope, for the developer who are focused mostly on code writing and those using operating systems other than Windows, these editors can be handy.

Have you used any and what's your experience? Which one do you like most? And do you think taht Embarcadero as a development tools company should invest in this area alongside with improving and modernizing the RAD Studio IDE on Windows? 

Categories: News, Blogs, and Tips