Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Pawel Glowacki
European Technical Lead for Delphi and RAD Studio
http://blogs.embarcadero.com/pawelglowacki
Agenda
• 0830-0900 Registrations
• 0900-0915 Embarcadero Overview
• 0915-0930 Introduction to AppWave
• 0930-1030 RAD Studio XE2 Overview
• 1030-1045 Coffee break
• 1045-1145 FireMonkey Deep Dive
• 1145-1215 Delphi 64-bit and VCL Styles
• 1215-1330 Lunch & coffee
• 1330-1400 LiveBindings Deep Dive
• 1400-1430 RAD Cloud Services
• 1430-1500 Q&A
Embarcadero Overview
Who is Embarcadero?
Embarcadero provides
database professionals
and application developers
with award-winning software tools
to design, build and run their systems
in the environment they choose
Developers, DBAs, and
Architects
Embarcadero Has You Covered
Introduction to AppWave
RAD Studio XE2
Overview
The ultimate application
development suite for Windows,
Macintosh, Mobile, and Web
Fast Native applications for Windows,
Macintosh, Web and Mobile
• Write app once, compile
for multiple platforms
• Data-rich, Component-based
• Delphi and C++
native code performance
• Delphi for 64-bit Windows
• VCL Styles
• RadPHP for full
visual web development
Introducing
The Next Generation Business Application Platform
• Stunning HD and 3D
Business Applications
• Native Power and Performance
• Connect with any Data
and Services
• Full Suite of UI Controls
• Visualize Live Data
• Styled Vector UIs
without coding
• Communicate with Animations
• No-Code Hardware Effects
Applications that Connect Everywhere
• High-speed connectivity
to popular databases
• Multi-tier applications
• Clients on multiple
computers and devices
• Connect to the world
of data, services,
and the cloud
Mobile choices for you and your users
• Native mobile apps for DataSnap
– iOS, Android, Blackberry,
and Windows Phone 7
– Delphi and C++Builder DataSnap Servers
• Mobile-optimized PHP web apps
– Web apps that look great
– Web apps that work great on mobile
devices
– Package applications for distribution
– Sell on Apple App Store and Android
Marketplace
And one more thing…
Create native iOS apps
• Use the RAD Studio XE2 IDE
• Create a Delphi FireMonkey application
• Compile for iOS
• Run on iPhone, iPad, iPod Touch
• Your rich app, your rich data, everywhere
Demonstrations
RAD Studio XE2
…and more!
Delphi XE2
• Starter (Delphi/C++Builder)
• Professional
• Enterprise
• Ultimate
• Architect
RAD Studio XE2
The ultimate application development suite for Windows, Mac, mobile and Web
Business SW
is stuck here
VCL
UE Richness
MFC
UE Performance
Introducing… FireMonkey!
FireMonkey
FireMonkey is not …
Game
HTML5/CSS3 Engine
FireMonkey is…
App Development Platform
C++Builder Delphi
• IControl
– Handles Focus, Mouse and Keyboard events
– Implemented by TControl and TControl3D
“FireMonkey” Architecture
• IRoot
– Interface for top-level containers
– Handles Focused, Captured, Active controls
– Implemented by TCustomForm
• IScene
– Container interface for 2D objects
– Implemented by TForm, TCustomLayer3D
• IViewport3D
– Container interface for 3D objects
– Implemented by TForm3D, TViewport3D
FireMonkey Styles
• FireMonkey Stylebook
– Any object inherited from TBaseObject
– Set StyleName to identify
– Found using FindStyleResource method from parented object
– Stored In / Loaded From a stream file
• FireMonkey Styles
– A collection of FireMonkey resource style
– WPF type of implementation
– Styles can be inherited, saved, loaded
– Look and Feel style files for Win7, MacOS, iOS and custom
themes
“FireMonkey” – Animation
• Used to modify property values over time
• Machine speed independent
• Can be looped and / or reversed
• Can follow a variety of time / value curves
• Can be triggered by MouseOver, Focus,
Visibility, etc.
“FireMonkey” – Effects / Filters
• Can be applied to bitmaps
• Can be applied to controls
• Can be triggered by MouseOver, Focus,
Visibility, etc.
• GPU shader based implementation
3D Programming
• One object model to target multiple platforms
• FM uses right-handed orientation in 3D
• Hardware acceleration
– Windows – DirectX
– MacOS – OpenGL
– iOS – OpenGL ES
FireMonkey and Cross Platform
• FM is a platform that supports
– RTL
– GUI
– Database
– Operating System
• Compile / Run on all platforms we support *
• Go FIREMONKEY !!!
Live Bindings
Deep Dive
What is LiveBindings?
• TBindingsList
– Hold the binding lists
– Manage the list of methods and output converters used by the expression
LiveBinding Scenario
SOURCE CONTROL
TField TLabel
LiveBinding
Engine
Binding Expression Editor
64-bit and VCL Styles
Deep Dive
Delphi 64-bit
What’s the same?
• Integer, Longint, Cardinal – still 32bits
• Int64, UInt64 – still 64bits
• UnicodeString, AnsiString, WideString
• Exceptions
• Runtime Library (RTL)
• SysUtils, Classes, etc…
Delphi 32 and 64-bit Type Sizes
Signed types Delphi/32 Delphi/64
ShortInt 1 byte
SmallInt 2 bytes
LongInt 4 bytes
Integer 4 bytes
Int64 8 bytes
• Online resources
• http://msdn.microsoft.com/en-us/magazine/cc300794.aspx
• http://msdn.microsoft.com/en-us/library/7kcdt6fy.aspx
What does this mean for Delphi?
Don’t panic!
Delphi 64-bit on Windows
• Same Windows API
– CreateWindowEx, PeekMessage, etc..
• Same Delphi RTL
– SysUtils, Classes, Generics.Collections, etc…
• Same VCL
– Forms, Graphics, Controls, Menus, etc..
Pre-Defined Conditionals
• Category Identifier dcc32 dcc64
• Compiler DCC defined defined
VER230 defined defined
• Platform MSWINDOWS defined defined
WIN32 defined not defined
WIN64 not defined defined
• CPU CPU386 defined not defined
CPUX86 defined not defined
CPUX64 not defined defined
• Availability ASSEMBLER defined defined
UNICODE defined defined
Delphi 64-bit on Windows – some gotcha’s
• SizeOf(Pointer) <> SizeOf(Integer)
– Integer<->Pointer casts will break in 64bit
– SizeOf(THandle) = SizeOf(Pointer)
– All Handles = SizeOf(Pointer) (HWND, HDC, etc..).
• All code in process must be 64bit
– Must have 64bit versions of external non-Delphi libraries (DLLs)
• One, and only one, calling convention
– register, pascal, cdecl, stdcall are ignored.
• safecall is still “special”
• Old “pointer math” code may break
– Works in 32 and 64bit: MyPtr := PByte(P) + 10;
• TList’s internal FList is now a TPointerList. Used to be a PPointerList.
Removing ^ should be sufficient to port from 32-bit to 64-bit.
• Tag property is now a NativeInt (32-bit vs 64-bit)
Delphi 64-bit on Windows – some gotcha’s
• Inline Assembly
– Cannot mix asm blocks with Pascal code
– Only procedural level asm blocks supported
– Stack must be 16-byte aligned at each call instruction
– Define locals for temp storage
– Do not modify the RSP stack pointer
– New unified calling convention. First 4 parameters in registers,
RCX, RDX, R8, R9 (or XMM0-XMM3)
• Exception unwinding
– No change for pure Delphi code. Exceptions function identically.
– Inline Assembly can cause exception unwinding to fail if not
properly written.
• SHL/SHR – 32-bit values (Integer et al) will only shift in 32-bit space.
64-bit values will of course shift in 64-bit space.
• No Extended type in 64-bit. Use TExtendedRec80 if necessary (binary
files with Extendeds in them for instance)
Windows API gotcha’s
• SetWindowLong / GetWindowLong should
be replaced by SetWindowLongPtr /
GetWindowLongPtr for GWLP_HINSTANCE,
GWLP_WNDPROC, etc… as they return
pointers and handles.
– Pointers passed to SetWindowLongPtr should
be type-casted to LONG_PTR and not to Integer
/ Longint.
• SetWindowLong mapped to
SetWindowLongPtr in Windows.pas.
– Calls to our declaration of SetWindowLong are
safe, as long as they are cast correctly.
Windows API gotcha’s (con’t)
• Use explicit casts to WPARAM and LPARAM
where appropriate.
– Example: Passing pointers through
SendMessage SendMessage(hWnd,
WM_SETTEXT, 0,
LPARAM(@MyCharArray));
• Use LRESULT to cast message
results
– Example: Message.Result :=
LRESULT(Self);
• Message cracker records
(TWMxxx) changed
– Alignment changes and field-size
changes
What can I do today?
• Find all Integer<->Pointer casts, including
Integer<->instance casts.
– Check for Pointer size assumptions
• Ensure external dependencies are also 64bit
– Image/bitmap libraries
– Hardware interfaces libraries
– ActiveX controls
• Consider rewriting Assembler in pure-Pascal
– Better future portability (think ARM CPUs…)
– Rely more on algorithmic performance rather
than raw assembly performance.
• Make sure you know what bit-size (32 vs 64)
you’re shifting with SHL/SHR.
VCL
What’s New in the VCL?
• 64-bit
• VCL Styles
VCL Styles
Themes in Delphi/C++Builder XE and
earlier
• Only 1 "theme" supported (native Windows)
• 3rd party products required to change look of VCL
apps
• Current “skinning" products for Windows
common controls
– Requiring hooking WndProc's
– Intercepting control messages
• Separate controls needed for "custom" controls
– TCustomControl / TGraphicControl descendants
VCL Styles
• Multiple styles provided/supported
• Custom style file creation
• Custom style classes
• Pluggable style engine
• Works with TWinControl and TGraphicControl
descendants
VCL Styles
• TThemeServices replaced by TCustomStyleServices
– Extends TThemeServices with more parts, states and methods
• TStyleEngine
– Processes control messages
– Calls StyleServices to render parts
• TStyleManager
– Provides services such as
• LoadFromFile
• LoadFromResource
• RegisterStyle
• RegisterStyleClass - Associates file extension with Style class
• SetStyle
• Style selection
• Style engine selection
• Providing custom styles
– Create style file (using provided style building tool)
– Implement TCustomStyleServices descendant and render parts directly
What can’t be styled?
• TMainMenu/TPopupMenu (main menu bar is
styled, but not the pop-up parts)
• Ribbon controls
• OS dialogs
Project Options | Appearance
From this…
To this!
VCL Style Designer
Typical Usage
• Uses Vcl.Styles, Vcl.Themes;
• TStyleManager.SetStyle(‘Ruby Red Graphite’);
RTL
RTL
What’s new in the RTL?
• 64-bit for Windows!!!
• MacOSX - No COM, No ActiveX. :)
– Windows specifics has been mapped to MacOSX equivalents wherever
possible
• TOSVersion
– Architecture (32/64-bit), Platform (Win/Mac), Major, minor OS version, Service Pack info
• TFormatSettings
– replaces global format setting variables (that don't exist on MacOSX)
• TZipFile - cross platform Zip support
• SymLinks in IOUtils and SysUtils file handling routines
– class function TFile.CreateSymLink(const Link, Target: string): Boolean;
• TLoginCredentialService
– Extensible framework agnostic login credential services with support for
callbacks (success, failure, etc)
• TPoint, TRect, TSize - new methods and properties
• TPointF, TRectF, TSizeF - floating point versions
TFormatSettings (SysUtils)
type
TFormatSettings = record // System.SysUtils
…
CurrencyString: string;
CurrencyFormat: Byte;
CurrencyDecimals: Byte;
DateSeparator: Char;
TimeSeparator: Char;
ListSeparator: Char;
ShortDateFormat: string;
LongDateFormat: string;
TimeAMString: string;
TimePMString: string;
ShortTimeFormat: string;
LongTimeFormat: string;
ShortMonthNames: array[1..12] of string;
LongMonthNames: array[1..12] of string;
ShortDayNames: array[1..7] of string;
LongDayNames: array[1..7] of string;
ThousandSeparator: Char;
DecimalSeparator: Char;
TwoDigitYearCenturyWindow: Word;
…
end;
TZipFile (System.Zip)
type
TZipFile = class
..
public
…
procedure Open(ZipFileName: string; OpenMode: TZipMode); overload;
procedure Open(ZipFileStream: TStream; OpenMode: TZipMode); overload;
procedure Close;
procedure Extract(FileName: string; Path: string = ''; CreateSubdirs: Boolean=True); overload;
procedure Extract(Index: Integer; Path: string = ''; CreateSubdirs: Boolean=True); overload;
procedure ExtractAll(Path: string = '');
procedure Read(Index: Integer; out Bytes: TBytes); overload;
procedure Read(FileName: string; out Stream: TStream); overload;
procedure Read(Index: Integer; out Stream: TStream); overload;
procedure Add(FileName: string; ArchiveFileName: string = '';
Compression: TZipCompression = zcDeflate); overload;
…
property FileCount: Integer read GetFileCount;
property FileNames: TArray<string> read GetFileNames;
…
end;
TLoginCredentialService
type
TLoginCredentialService = class sealed
public const
Default = '';
DefaultUsrPw = 'DefaultUsrPw'; // do not localize
DefaultUsrPwDm = 'DefaultUsrPwDm'; //do not localize
…
strict private class var
FLoginHandlers: TStringList;
strict private
class constructor Create;
class destructor Destroy;
class function IndexOfHandler(const Context: TLoginCredentialEvent): Integer;
public
class procedure RegisterLoginHandler(const Context: string; const HandlerEvent: TLoginCredentialEvent); static;
class procedure UnregisterLoginHandler(const Context: string; const HandlerEvent: TLoginCredentialEvent); static;
Deep Dive
Agenda
• RAD Cloud Overview
• DBExpress
• New Cloud API
• What’s new in DataSnap
Cloud API
What is the Cloud API?
Container = Bucket
Blobs = Object
Page = Multipart
ACL = ACL (Access Control List)
Microsoft Azure
• Blob Storage
– Unstructured storage
– Defined Container
– For storing large pieces of data such as: Images, Video,
Documents, etc.
• Azure Tables
– Scalable structured storage
– NOSQL type tables
– Entities stored in a table
– Different set of properties made up of different types
• Queues
– Persistent asynchronous messaging
– Each message is up to 8kb long
Amazon WS
• Simple Storage Service (S3)
– Blob Storage
– Unstructured storage
– Defined Container
– For storing large pieces of data such as: Images, Video, Documents,
etc.
• SimpleDB - Tables
– Scalable structured storage
– NOSQL type tables
– Entities stored in a table
– Different set of properties made up of different types
• Simple Queue Service (SQS)
– Persistent asynchronous messaging
– Each message is up to 64kb long
Deploying to the Cloud
• Deployment manager supports:
– Microsoft Azure
– Amazon EC2
What's new in DataSnap
What’s new in DataSnap
• Enhancements
– Server
– REST Interfaces
– Callback
– Authentication Manager
• New DataSnap Monitoring and Control
Server
• Proxy info support for DataSnap HTTP
connections in TSQLConnection and
TDSRESTConnection
• New TDBXChannelInfo.DBXClientInfo
(TDBXClientInfo record) provides:
– IP Address
– Protocol
– Application Name (when possible) – only for HTTP
HTTPS Support
• For Stand-alone DataSnap servers
• For Stand-alone WebBroker servers
• DataSnap Wizards updated with HTTPS
support
Session Manager
• Session support for TCP/IP protocol
• Support for store and retrieve TObject in
Sessions
• Sessions created and destroyed with the
TCP/IP protocol now notifies the
AddSessionEvent and RemoveSessionEvent
• Support for multiple Callback Tunnels on
DataSnap REST Interface
Callback Tunnel Manager
• TDSCallbackTunnelManager class in DSServer
unit
• Allows tracking when:
– Callback is added or removed
– Tunnel is created or closed
Callbacks
• Heavyweight callbacks now support
broadcasting to specific callbacks
• GetAllChannelNames added to the DSServer
to get the name of all callback channels
Callback client side events
• Notifications whenever the manager’s tunnel
is opened or closed, or when callbacks are
added to it or removed from it. Available for:
– Delphi DBX Client Events
– Delphi REST Client Events
– JavaScript REST Client Events
Delphi DBX Client Events
• TDSClientCallbackChannelManager
component, event OnChannelStateChange
• Method signature:
(Sender: TObject; const EventItem: TDSClientChannelEventItem);
Event.Channel.EnableKeepAlive(10000);
How to use EnableKeepAlive
• If the client doesn’t respond the OS will
resend the packet X number of times (Win 7
will retry 10 times).
Event.Channel.EnableKeepAlive(10000, 100);
KeepAlive Enablement
• Available through TDSTCPServerTransport
component
• Three new published properties
– KeepAliveEnablement - (Set: Default, Enabled,
Disabled)
– KeepAliveTime - Integer Milliseconds value
– KeepAliveInterval - Integer Milliseconds value
How to use DisableKeepAlive
• Get the associated Channel for the given
connection and call:
DisableKeepAlive;
Closing Client Connections
• Connection can be closed any time
• Channel provide the connection instance
//Get the associated Channel for the given connection, and if successful close it
if FConnections.TryGetValue(Connection, Channel) then
Channel.Close;
Demo
• Tracking all the TCP/IP connections and their
corresponding sessions
• How to manually close a TCP/IP connection
from the server
• How to detect when a client has lost internet
connectivity while connected.
Mobile and Connectors
Deep Dive
Mobile Connectors for DataSnap
• DataSnap Mobile Connectors
– iOS – Objective C
– Android – Java
– BlackBerry – Java
– Windows Phone 7 – C#, Prism
DataSnap Mobile Connectors Demonstration
RadPHP XE2 – Mobile App
RadPHP XE2 – Phone Gap
Tools | Wizard for PhoneGap
Summary
• FireMonkey - The Next Generation Business
Application Platform
• Fully harness the powerful GPU graphics hardware
• Rapidly build visually spectacular applications
• Invest in one platform and deploy to numerous OS-s
• Delphi and C++ compiled, native executable
• Fully programmable animations and effects
• Go FIREMONKEY !!!
RAD Studio XE2
The ultimate application development suite for Windows, Mac, mobile and Web