Windows 10 VCL Universal Windows Platform (UWP)/WinRT Services and Components has been added to the Run Time Library (RTL).
For example, the Windows 10 Notifications Component and Windows 10 Sharing/Contract Component, for both Object Pascal and C++ is included in RAD Studio, Delphi and/or C++ Builder
Introduction/Background on WinRT
What does the WinRT and Universal Windows Platform Integration mean in RAD Studio?
RAD Studio provides WinRT API mappings and Object Pascal interfaces, and this provides support for Services such as Win 10 Notifications and Win 10 Contracts (source only).
We provide components for both Notifications and Contracts that you can use in your application in both VCL and FMX C++ and Object Pascal. The Notifications come through the Win10 Standard Action Center. The Contracts are similar to Intents on Android or ShareSheet on iOS. The Contracts allow you to find what types of applications can consume the content of your application. For example, you can select TEXT content in your app, and click SHARE, and then you can open it up with a Reading List Application or a Notes Application.
The sample Object PascalVCLWindows 10 Calendar includes WinRT support by System.Win.Winrt and Winapi.winrt.
Using WinRT Classes
Let’s takes a quick overview look at some of the WinRT units, and how to use them.
Using RAD Studio 10.2 Tokyo, from Windows Explorer, you can see all the WinAPI units (that Embarcadero has translated) using the APIs metadata, installed at C:Program Files (x86)EmbarcaderoStudio19.0sourcertlwinwinrt
We have Units like UI.Notifications, Globalization, and some interesting ones like Devices.Bluetooth.
WinAPI.Devices.Bluetooth contains the new BT and BTLE classes. (NOTE: We did discover that Windows implementation of this unit was very poor, and lacked some of the needed BT and BTLE characteristics like Advertisement, but the good news is WinRT fixed all of this!)
Let’s say we are interested in working with BluetoothLE Advertisement Manufacture Data.
Open unit Winapi.Devices.Bluetooth.Advertisement in RAD Studio and Search | Find | advertisement, and you will see interfaces for BT LE Advertisement:
Let’s look at one more WinRT unit. Let’s look at Winapi.UI.Notifications that we used for the new Windows 10 Notifications.
From Windows Explorer, Drag and Drop Winapi.UI.Notifications.pas into the IDE.
Looking at the source code for Winapi.UI.Notifications, we see, looking for the TToastManager (line 280), we have the ToastNotificationManagerStatics :
We have static methods of a class that you can use, for example, if you create:
1. File | New | VCL Forms App – Delphi.
2. Add Winapi.UI.Notifications to the uses.
3. Then you can code: TToastNotificationManager.
And you see Statics: IToastNotificationManagerStatics
And TToastNotificationManager.Statics. gives the static methods of the class (functions we can use!).
Create a Windows 10 VCL Universal Windows Platform (UWP) application.
Let’s look at one more of the classes, the Calendar class and create a Windows 10 VCL Universal Windows Platform (UWP) application.
For example, using C# and Visual Studio, to create a calendar and display the current year, the code looks like this:
1 2 3 4 5 6 7 8 9 10 11 |
Using Windows.Globalization; Using Windows.UI.Popups; Calendar Cal = new Calendar(); String Year = Cal.YearAsString(); MessageDialog ToShow = new MessageDialog(Year); ToShow.ShowAsync(); |
1. New | VCL Forms Application.
2. Add a Button.
3. Add to uses: Winapi.Globalization, System.Win.WinRT;
(Note: We use the same Globalization classes, and the WinRT is for the Helper classes).
4. For the Button’s onClick Event, we declare the Calendar:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
procedure TForm2.Button1Click(Sender: TObject); var Cal: ICalendar; begin //create the Calendar Cal := TCalendar.Create; //get the Calendar Year as a String method (YearAsString), //returns the new Type HSTRING // // So we need to convert it to a Delphi String, using the //TWindowsString class, with the HStringToString method // // And then we can display the Year in a ShowMessage ShowMessage(TWindowsString.HStringToString(Cal.YearAsString)); end; |
5. We want to build this for our Windows 10 machine, Win32:
– Project Options | Delphi Compiler | Linking | Include remote debug symbols | TRUE
6. Build and Run the app.
7. Click the Button.
8. The ShowMessage displays the current year 2017:
So, as you can see, the code in Delphi is similar to the code in Microsoft C# Visual Studio to create a new Calendar.
This is because if you look at the Winapi.Globalization.pas code from C:Program Files (x86)EmbarcaderoStudio19.0sourcertlwinwinrt, (Drag and Drop the file into the IDE), search for TCalendar (line 1042):
1 |
function GetCalendarSystem: HSTRING; safecall; |
We see we have an ICalendarFactory (Search | Find Class):
1 2 3 4 5 |
// DualAPI Interface // Windows.Globalization.ICalendar [WinRTClassNameAttribute(SCalendar)] ICalendar = interface(IInspectable) ['{CA30221D-86D9-40FB-A26B-D44EB7CF08EA}'] |
1 2 3 |
// Windows.Globalization.ICalendarFactory ICalendarFactory = interface; PICalendarFactory = ^ICalendarFactory; |
In the IDE, place your cursor on the ICalendarFactory, | Find Declarations | gives us the Interfaces:
1 2 3 4 5 6 7 8 |
// DualAPI Interface // Windows.Globalization.ICalendarFactory [WinRTClassNameAttribute(SCalendar)] ICalendarFactory = interface(IInspectable) ['{83F58412-E56B-4C75-A66E-0F63D57758A6}'] function CreateCalendarDefaultCalendarAndClock(languages: IIterable_1__HSTRING): ICalendar; safecall; function CreateCalendar(languages: IIterable_1__HSTRING; calendar: HSTRING; clock: HSTRING): ICalendar; safecall; end; |
We see we have a function CreateCalendar that we can use to create a Calendar. So we can do a CREATE on the Calendar. In other cases, you need to use the Factory.
In our sample Calendar app above, we used Cal := TCalendar.Create;
This post gave a quick overview of the Windows 10 VCL Universal Windows Platform (UWP)/WinRT Services and Components added to the RAD Studio, Delphi and C++ Builder Run Time Library (RTL).
[DownloadButton Product=’RAD’ Caption=’Start Your RAD Studio FREE Trial Today to create your own UWP/WinRT applications’]
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition