40
64-bit and VCL Styles Deep Dive

64-bit and VCL Styles

  • Upload
    jaeger

  • View
    82

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: 64-bit and VCL Styles

64-bit and VCL Styles

Deep Dive

Page 2: 64-bit and VCL Styles

Delphi 64-bit

Page 3: 64-bit and VCL Styles

What’s the same?

• Integer, Longint, Cardinal – still 32bits• Int64, UInt64 – still 64bits• UnicodeString, AnsiString, WideString• Exceptions• Runtime Library (RTL)• SysUtils, Classes, etc…

Page 4: 64-bit and VCL Styles

Delphi 32 and 64-bit Type SizesSigned types Delphi/32 Delphi/64ShortInt 1 byte SmallInt 2 bytes LongInt 4 bytes Integer 4 bytes Int64 8 bytes

Unsigned types Delphi/32 Delphi/64 Byte 1 byte Word 2 bytes LongWord 4 bytes Cardinal 4 bytes UInt64 8 bytes

Page 5: 64-bit and VCL Styles

What’s different?

• NativeInt, NativeUint – 64bits• Pointer (all pointers) – 64bits• Dynamic Arrays – 64bit indexing• Floating point math - Double

Page 6: 64-bit and VCL Styles

Delphi 32 and 64-bit Type SizesSigned types Delphi/32 Delphi/64NativeInt 4 bytes 8 bytes

Unsigned types Delphi/32 Delphi/64 NativeUInt 4 bytes 8 bytes

Page 7: 64-bit and VCL Styles

Delphi 32 and 64-bit Pointer TypesPointer types Delphi/32 Delphi/64Pointer StringClass instance Class reference Interface AnsiString 4 bytes 8 bytes WideString UnicodeString Procedure pointer Dynamic array PAnsiChar PWideChar PChar

Page 8: 64-bit and VCL Styles

The CPU – Programming model

Page 9: 64-bit and VCL Styles

Instructions and Addresses• 64 bit address space• Limited by physical hardware• Same core Intel instruction set• New REX prefix for 64bit instructions• RIP-relative addressing• Jumps – relative +/- 2GB• 16 byte stack alignments

• Online resources• http://msdn.microsoft.com/en-us/magazine/cc300794.aspx• http://msdn.microsoft.com/en-us/library/7kcdt6fy.aspx

Page 10: 64-bit and VCL Styles

What does this mean for Delphi?

Page 11: 64-bit and VCL Styles

Don’t panic!

Page 12: 64-bit and VCL Styles

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..

Page 13: 64-bit and VCL Styles

• Category Identifier dcc32 dcc64 • Compiler DCC defined defined

VER230 defined defined • Platform MSWINDOWS defined defined

WIN32 defined not defined WIN64 not defined defined

• CPU CPU386defined not defined CPUX86defined not defined

CPUX64not defined defined • Availability ASSEMBLER defined defined

UNICODE defined defined

Pre-Defined Conditionals

Page 14: 64-bit and VCL Styles

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)

Page 15: 64-bit and VCL Styles

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)

Page 16: 64-bit and VCL Styles

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.

Page 17: 64-bit and VCL Styles

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

Page 18: 64-bit and VCL Styles

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.

Page 19: 64-bit and VCL Styles

VCL

Page 20: 64-bit and VCL Styles

What’s New in the VCL?

• 64-bit• VCL Styles

Page 21: 64-bit and VCL Styles

VCL Styles

Page 22: 64-bit and 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

Page 23: 64-bit and VCL Styles

VCL Styles

• Multiple styles provided/supported • Custom style file creation • Custom style classes• Pluggable style engine• Works with TWinControl and TGraphicControl

descendants

Page 24: 64-bit and VCL Styles

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

Page 25: 64-bit and VCL Styles

What can’t be styled?

• TMainMenu/TPopupMenu (main menu bar is styled, but not the pop-up parts)

• Ribbon controls• OS dialogs

Page 26: 64-bit and VCL Styles

Project Options | Appearance

Page 27: 64-bit and VCL Styles

From this…

Page 28: 64-bit and VCL Styles

To this!

Page 29: 64-bit and VCL Styles

VCL Style Designer

Page 30: 64-bit and VCL Styles

Typical Usage

• Uses Vcl.Styles, Vcl.Themes;• TStyleManager.SetStyle(‘Ruby Red Graphite’);

RTL

Page 31: 64-bit and VCL Styles

RTL

Page 32: 64-bit and VCL Styles

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

Page 33: 64-bit and VCL Styles

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;

Page 34: 64-bit and VCL Styles

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;

Page 35: 64-bit and VCL Styles

TLoginCredentialServicetype 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;

class function GetLoginCredentialEvent(const Context: string): TLoginCredentialEvent; static; class function GetLoginCredentials(const Context: string; Sender: TObject; const Callback: TLoginEvent): Boolean; overload; static; class function GetLoginCredentials(const Context: string; const Callback: TLoginFunc): Boolean; overload; static; class function GetLoginCredentials(const Context: string; var Username, Password: string): Boolean; overload; static; class function GetLoginCredentials(const Context: string; var Username, Password, Domain: string): Boolean; overload; static; end;

Page 36: 64-bit and VCL Styles

TPointF (System.Types)type TPointF = record X: Single; Y: Single; public constructor Create(const P: TPointF); overload; constructor Create(const X, Y: Single); overload; constructor Create(P: TPoint); overload; class operator Equal(const Lhs, Rhs: TPointF): Boolean; class operator NotEqual(const Lhs, Rhs: TPointF): Boolean; class operator Add(const Lhs, Rhs: TPointF): TPointF; class operator Subtract(const Lhs, Rhs: TPointF): TPointF; function Distance(const P2: TPointF): Double; procedure SetLocation(const X, Y: Single); overload; procedure SetLocation(const P: TPointF); overload; procedure SetLocation(const P: TPoint); overload; … function Add(const Point: TPointF): TPointF; overload; function Add(const Point: TPoint): TPointF; overload; function Subtract(const Point: TPointF): TPointF; overload; function Subtract(const Point: TPoint): TPointF; overload; function IsZero: Boolean; function Ceiling: TPoint; function Truncate: TPoint; function Round: TPoint; end;

Page 37: 64-bit and VCL Styles

C++

Page 38: 64-bit and VCL Styles

What’s New in C++?

• FireMonkey• Live Bindings• DataSnap• Extended RTTI• Audits and Metrics

Page 39: 64-bit and VCL Styles

Demos

Page 40: 64-bit and VCL Styles

Demos

• 32-bit/64-bit Stylish Fish Facts• C++ Stylish Fish Facts• Stylish Live Bindings Fish Facts