Quantcast
Channel: Planet Object Pascal
Viewing all 1725 articles
Browse latest View live

twm’s blog: Converting from Subversion to Mercurial

$
0
0

Here, I will be posting notes on converting Subversion repositories to Mercurial.

NOTE: This is work in progress. I will probably come back and change things as well as adding.

Some links on using Mercurial:
Hg Init: a Mercurial tutorial by Joel Spolsky
QuickStart in the Mercurial Wiki

I have got TortoiseSVN 1.8.3 including the command line clients and TortoiseHG 2.10.1 installed.

There are several short tutorials on converting from svn to hg. They all suggest that you first create a local copy of your subversion repository to work on.

A – Create a local copy of your subversion repository
Creating this local copy can easily be done as described by Massimo Iacolare, which I used as a guide.

1 – Create a local svn repository
You can use any local directory as the path to your local svn repository, I will be using the extension .svn to remind me that it is a svn repository. The converted Mercurial repository will not get an extension.

Unfortunately there is the first gotcha: Massimo seemed to be using an older version of svn that used db format 4. The current svn 1.8 uses db format 6 by default, and as Jeroen W. Pluimers found out, the current Mercurial does not support it yet. So, what can we do until the Mercurial developers fix this problem? Why, use db format 4, of course:

svnadmin create --compatible-version 1.7 [path\to\your\new\repository.svn]

I am not sure whether the steps 2 to 4 are necessary, it seemed to work fine without them. I’ll keep them here just in case I run into trouble later because I left them out.

2 – Enable writing on your new repository
Open the file [path\to\your\new\repository.svn]\conf\svnserve.conf and uncomment the line

[general]
password-db = passwd

This tells SVN which file stores the user credentials.

3 – Add a new user
Open the file [path\to\your\new\repository.svn]\conf\passwd and add a new user:

[users]
svnsync_user = svnsync

4 – Give your new user read/write permissions
Open the file [path\to\your\new\repository.svn]\conf\authz and add:

[/]
svnsync_user = rw

5 – Enable rev propchange (revision property change)
create a text file pre-revprop-change.bat in [path\to\your\new\repository.svn]\hooks containing:

exit 0

This can be done easily with

echo exit 0 > [path\to\your\new\repository.svn]\hooks\pre-revprop-change.bat

6 – Initialize the repository

svnsync init file:///[path/to/your/new/repository.svn] [REMOTE PATH]

Getting the local repository path right can be tricky. Pay close attention to the number of slashes and use forward slashes. e.g.

svnsync init file:///c:/some/path/here.svn https://svn.somesvnserver.com/svn/repository

7 – Synchronize
Once the repository is initialized, you can synchronize it as often as you like:

svnsync sync file:///[path/to/your/new/repository.svn]

Be aware, if your repository is big, the first synchronization may take very long.
After the synchronization has been done once, you can keep it in sync by just repeating step 7.

B – convert your local Subversion repository to a Mercurial repository

This is a one step action:

hg convert [path/to/your/new/repository.svn] [path/to/your/hg/repository]

If you omit the second parameter, hg convert will assume [path/to/your/new/repository.svn-hg] which is probably not what you want, but you can easily rename the directory later on.


Žarko Gajić: FireMonkey / Mobile (Android, iOS) QR Code Generation Using Delphi XE 5 / DelphiZXingQRCode

$
0
0

fmx-TDelphiZXingQRCode
The DelphiZXingQRCode unit, ported from ZXing by Debenu, allows to easily add QR Code generation to your Delphi VCL applications.

While the DelphiZXingQRCode was designed to support VCL applications (and be used in newer as well as in older Delphi versions), it can also easily be “upgraded” for Fire Monkey applications – be it desktop or mobile (Android, iOS).

DelphiZXingQRCode -> FireMonkey Support

To FireMonkey-enable the DelphiZXingQRCode unit a few changes to the source code were required.

The unit uses “contnrs” (System.Contnrs.pas) unit which implements TObjectList (used by the unit) and other container like classes. Under FireMonkey for mobile, more specifically under ARC, the classes contained in System.Contnrs.pas cannot be used because they are not ARC compliant.

Equivalent classes are to be found in System.Generics.Collections.pas (ARC compliant) where generics versions of TObjectList is defined.

Therefore, the first change is to replace “uses contnrs, …” with “uses System.Generics.Collections, …”

This also requires to make changes like: from “Blocks: TObjectList;” to “Blocks: TObjectList<TBlockPair>;” – that is to use strongly typed generics list classes.

Further, there are lots of “ansistring” and “widestring” types used for parameters in various functions inside the unit. If you want to go mobile, those are not supported and you should use “string”. More info here: Migrating Delphi Code to Mobile from Desktop.

Therefore, the second change to the unit would be to replace “widestring” with “string” and “ansistring” with “array of byte” (or something else as explained in the article).

Single Pixel Drawing (and Other Canvas Drawing) FireMonkey Style

In the VCL, the TCanvas class allows accessing single pixels through the “Canvas.Pixels()” property. In FireMonkey this is not supported and you have to use the SetPixel property of a TBitmapData instance.

Once the qr code is generated, to convert it to a bitmap image, in FireMonkey:

var
  QRCode: TDelphiZXingQRCode;
  Row, Column: Integer;
  pixelColor : TAlphaColor;
  vBitMapData : TBitmapData;
  rSrc, rDest : TRectF;
  s : widestring;
begin
  QRCode := TDelphiZXingQRCode.Create;
  try
    QRCode.Data := edtText.Text;
    QRCode.Encoding := TQRCodeEncoding(cmbEncoding.ItemIndex);
    QRCode.QuietZone := StrToIntDef(edtQuietZone.Text, 4);
    QRCodeBitmap.SetSize(QRCode.Rows, QRCode.Columns);
    for Row := 0 to QRCode.Rows - 1 do
    begin
      for Column := 0 to QRCode.Columns - 1 do
      begin
        if (QRCode.IsBlack[Row, Column]) then
          pixelColor := TAlphaColors.Black
        else
          pixelColor := TAlphaColors.White;

        if QRCodeBitmap.Map(TMapAccess.maWrite, vBitMapData)  then
        try
          vBitMapData.SetPixel(Column, Row, pixelColor);
        finally
          QRCodeBitmap.Unmap(vBitMapData);
        end;
      end;
    end;
  finally
    QRCode.Free;
  end;

  //refresh image control imgQRCode is a TImage
  {code below}
end;

Note: compare this with the VCL approach of TDelphiZXingQRCode usage.

VCL’s Canvas.StretchDraw to FMX’s Canvas.DrawBitmap

There’s no StrecthDraw in FMX’s Canvas class. There’s DrawBitmap. StretchDraw by default does no antialiasing. FMX does. So I had to play a little until I was able to make it work correctly.

I’ve decided to use TImage and not TPaintBox as I was simply not able to make TPictureBox in FireMonkey draw what I wanted :(

Using TImage, the code to get/display the generated QR Code is as follows:

  //refresh image. imgQRCode is a TImage

  imgQRCode.Bitmap.SetSize(QRCodeBitmap.Width, QRCodeBitmap.Height);

  rSrc := TRectF.Create(0, 0, QRCodeBitmap.Width, QRCodeBitmap.Height);
  rDest := TRectF.Create(0, 0, imgQRCode.Bitmap.Width, imgQRCode.Bitmap.Height);

  if imgQRCode.Bitmap.Canvas.BeginScene then
  try
    imgQRCode.Bitmap.Canvas.Clear(TAlphaColors.White);

    imgQRCode.Bitmap.Canvas.DrawBitmap(QRCodeBitmap, rSrc, rDest, 1);
  finally
    imgQRCode.Bitmap.Canvas.EndScene;
  end;

Aliasing – Do Not Need It!

By default, in FMX, when using DrawBitmap to resize it, antialiasing is used by default. There are two properties you need to set to ensure a bigger copy of your (small) qr code is drawn pixel-copy-perfect.

begin
  imgQRCode.DisableInterpolation := true;
  imgQRCode.WrapMode := TImageWrapMode.iwStretch;
end;

In a FireMonkey Desktop application, this works as expected.

On FireMonkey Mobile it does not :(– the resized image is still blurred (antialiasing used).

That’s it. QR Codes generation in FireMonkey – both desktop and mobile!

Comments are welcome (even more if you know how to resize a bitmap in FireMonkey on mobile without antialiasing)!

Firebird News: Firebird 3.0 alpha2

$
0
0
The second alpha of Firebird 3.0 is about to be released. Find more information at http://sourceforge.net/p/firebird/code/HEAD/tree/firebird/tags/T3_0_0_Alpha2/doc/WhatsNew

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

One more for the weekend (:

I wrote about Some links on the Delphi compiler and the LLVM Compiler Infrastructure Project about a year and a half ago which caused a short discussion on the embarcadero forums. A few month later Robert Love showed his views in a response to Tim Anderson writing about Clang and LLVM in the C++ side of the toolchain. Tim Anderson wrote more about LLVM in the Delphi tool chain  in September 2012, then it went quite for a while.

Since then the LLVM tool chain has integrated itself into both the C++ and Delphi toolchains and Wired wrote about LLVM.

Gunsmoker – who works at EurekaLog– wrote up some interesting comments in Rusian (I hope the English Google translation is good enough).

In my view, the LLVM tool chain opens a lot more possibilities (shared back-end for Delphi and C++, coverage of more platforms, better optimization), but is also a lot slower and makes the debugging part a lot harder as the debugger is – symbol wise – much further away from the compiler than in the traditional setting (hence the 3 levels of debugging information that got introduced in Delphi XE5 and the compatibility problem that came with it).

I’m wondering what other users in the Delphi community think about the LVVM chain: is it working good enough for you? Should it be integrated further into the Windows/OSX parts of the chain?

–jeroen


Filed under: Delphi, Delphi XE3, Delphi XE4, Delphi XE5, Development, Software Development

Andreano Lanusse | Technology and Software Development: Delphi XE5 Update 2 many bug fixes on FireMonkey for iOS, Android and compiler

$
0
0

Another update for available for Delphi XE5 and C++Builder XE5, the Update 2 is has lots of bug fixes covering several areas, specially on FireMonkey for Android, iOS, Windows and Mac.

The Update is available for registered users and you can find on the following links. Just a friendly remind that you need to Uninstall your current Delphi XE5 in order to install XE5 Update 2.

Below the complete list of bugs fixed on this Update.

 

Reference No

Summary

Component/s

[Indy] Access Virolation occues on OnValidatePeerCertificate for IPPeerCommon bug[HTTPS,SSL]3rd Party

120473

[iOS] SOAP fails in iOS when using SSL (“IOHandler value is not valid.”)Blocker

119873

TCameraComponent causes memory leak in Win32Blocker

115697

TDump command crashes on DLL’sCommand Line Tools

112826

TDump.exe shows strange outputCommand Line Tools

100328

TDump crashes on the x64 shell32.dllCommand Line Tools

110887

TDump fails on some ‘foreign’ .dllsCommand Line Tools
Delphi XE5 cannot build OSX applications from the command lineCompiler
[FM Mac OSX 10.9] Compile error XMLDocument using SDK 10.9Compiler, Compiler\C++

120686

[Mavericks 10.9] C++Builder XE4 does not support OS X 10.9Compiler, Compiler\C++, Compiler\C++\BCC
Throwing a exception in virtual member function returning an AnsiString causes an AV and an abend under certain circumstances, in 32-bit C++ applicationCompiler, Compiler\C++, Compiler\C++\BCC, Compiler\C++\BCC\Back End

120476

[iOS ARM][Android] E2581 Backend error: invalid linkage type for global declarationCompiler, Compiler\Delphi
[dcc(ios/a)arm] Backend Error compiling constructor for generic classesCompiler, Compiler\Delphi

118897

method overload resolution fails when passing @ parameter to overloaded methods mixing Pointer and specific pointer parameters.Compiler, Compiler\Delphi
ShowMessage/Message Alerts not working in iOS 7 SimulatorCompiler, Compiler\Delphi
[dccaarm][dcciosarm] Implicit finally block doesn’t execute if the exception is not catch in except block.Compiler, Compiler\Delphi
Crash by declaration error when declaring class function in record typeCompiler, Compiler\Delphi
Internal Error URW1154 calling TValue.From() of System.RttiCompiler, Compiler\Delphi

72147

Invalid section table entries on empty sectionsCompiler, Compiler\Delphi

119197

subtraction of sets changes its paramsCompiler, Compiler\Delphi, Compiler\Delphi\CodeGen
Integer computation error upon mixing Byte and IntegerCompiler, Compiler\Delphi, Compiler\Delphi\CodeGen
When Currency is used in a generic record type you get an internal compiler error G1239 IN Zephyr and G1232 in XE4Compiler, Compiler\Delphi, Compiler\Delphi\Generics

118815

Generic method inlining (part 2)Compiler, Compiler\Delphi, Compiler\Delphi\Generics

118866

Cannot perform FillChar on Currency variables – E2197 Constant object cannot be passed as var parameterCompiler, Compiler\Delphi, Compiler\Delphi\Messages

93738

Internal Error URW1136Compiler, Compiler\Delphi, Compiler\Delphi\Messages

118929

Totally broken package compiler for an iOS deviceCompiler, Compiler\Delphi, Compiler\Delphi\Packages/Libs

118523

[dcc32] Command-line build fails for user account with non-ASCII charactersCompiler, Compiler\Delphi, IDE\Build System
DataSnap : Memory leaks caused by TFDJSONDataSetsBase.FOwnsDataSetData, Data\DataSnap
DataSnap: HTTP request may be broken when sending DeltaData, Data\DataSnap
[C++][DataSnap]Exception raised when trying to execute server method through proxy on OS X 10.9Data, Data\DataSnap

116417

[ISAPI] DataSnap Server as an ISAPI DLL get a 48KB limitation when receiving POST dataData, Data\DataSnap
[OS X][DataSnap][FireDAC] Unable to find static library: DataSnapFireDAC.aData, Data\DataSnap, Data\FireDAC
[DataSnap] TX509CertificateIndy.Verify is not operation as specification.Data, Data\DBX
Unable to load libsqlib.dylibData, Data\DBX
DBX memory leak when running queries on NEXTGEN platformsData, Data\DBX
FireDAC FDConnection does not autocommitData, Data\FireDAC
FDExplorer resizing causes lost display of description column messageData, Data\FireDAC
Building a Mobile Application that contains a TFDPhysIBDriverLink component raises an errorData, Data\FireDAC
[SQLite] It can’t encipher by the specified encrypt parameter, so it can’t setup except aes-256Data, Data\FireDAC
If XML containing MBCS is saved by SaveToStream, It is not copied correctly..Data, Data\FireDAC
If XML containing MBCS is copied to TFDMemtable, Exception class EDOMParseError occursData, Data\FireDAC
FireDAC memory leak when running queries on NEXTGEN platformsData, Data\FireDAC

119995

“Not editing” error reported with LiveBindings when calling ApplyUpdates on TAdapterBindSourceData, Data\LiveBindings

118633

[iOS device/Android] With TSoapConnection, TClientDataset.ApplyUpdates raises “Exception in safecall method” in iOS device and AndroidData, Data\Midas

118633

[iOS device/Android] gdb reports wrong file after step intoDebugger
Debugging not working with a FireMonkey Mobile app on Nexus 7 2013Debugger
[Delphi] Access Violation when Inspecting or Adding a Watch with a function where an array is passed in as a var or constDebugger
Function call evaluation on C++ OSX apps is broken when using MavericksDebugger, Debugger\Evaluator

120506

[OSX 10.9] Mavericks Modules Debug Window doesn’t show framework dylibs anymoreDebugger, Debugger\Views

119777

ReqMulti.pas has been removed from the productFile Delivery, Internet
[FMX/Android] TEdit causes SIGSEG if SetFocus method is called inside Forms’s OnCreate event.FireMonkey
[iOS] Sharing popup size is calculated wrongFireMonkey

120259

Bugs in creating forms with TForm.CreateNew() – i.e. without a designer.FireMonkey
Orientation switch breaks app or bars user after device activated again (after sleep)FireMonkey

119176

[iOS7 iPad Simulator] App crash in iOS 7 iPad SimulatorFireMonkey

118770

Bad text rendering on AndroidFireMonkey
Poor application performance on Nexus 10FireMonkey
[iOS] TMemo – sometimes when using LongTap to bring up the context menu on iOS, the cursor and context menu is moved up with one lineFireMonkey

118554

[iOS Device] iOS App crashes on iOS 6.1.3 (iPad) when Showing Forms – but not on SimulatorFireMonkey
TabletMasterDetail app takes over 10 seconds to load on Nexus 10FireMonkey

120566

When adding a TBindNavigator, an Access Violation occursFireMonkey

118799

2D Empty app does not start on Samsung Galaxy Tab 3FireMonkey, FireMonkey\3D Components

120517

TMemo.ScrollLayout could cause access violationFireMonkey, FireMonkey\Components

120827

[iOS7] With TMemo, unintentional letter appears when entering with Japanese keyboard.FireMonkey, FireMonkey\Components
Date Picker mobile code snippet TCalendarEdit – decrements the date when you don’t change the date in the pickerFireMonkey, FireMonkey\Components
Using German ß (00DF; LATIN SMALL LETTER SHARP S) in TListBoxGroupHeader raises EArgumentOutOfRangeExceptionFireMonkey, FireMonkey\Components
On HTC one X(4.1.1) cannot be typed a set of numbers if the keyboard has the vktPhonePad typeFireMonkey, FireMonkey\Components

120515

TMemo.GoToTextEnd crashes at program startup and doesn’t move the horizontal scrollbarFireMonkey, FireMonkey\Components

120517

TMemo.ScrollLayout could cause access violationFireMonkey, FireMonkey\Components

119442

Mobile Code Snippets – Web Browser needs to be updated. Web Browser Top Margin should be 0FireMonkey, FireMonkey\Components
Problem changing the KeyboardType among different TEditFireMonkey, FireMonkey\Components

120136

[Android 4.3] TListView component scrolling performance is very slow (Samsung GALAXY Note 3)FireMonkey, FireMonkey\Components
Listview scrolling performance slow on Samsung Galaxy Note 3FireMonkey, FireMonkey\Components
Custom TabIcon support missing for iOS 7FireMonkey, FireMonkey\Components

119442

[iOS7 device] Web Browser positioned incorrectly in iOS7FireMonkey, FireMonkey\Components

120007

[Android, iOS] Viewport3D does not fully display on a mobile form with TabControlFireMonkey, FireMonkey\Components

118859

[iOS] TMedia Volume cannot be changed in iOSFireMonkey, FireMonkey\Components
TWebBrowser misaligned when Align set to alClientFireMonkey, FireMonkey\Components

119891

[Android] Edit.SetFocus in Form.OnShow() will cause app crash when entering textFireMonkey, FireMonkey\Components
TabControl does not fit the screen completely widthwise when it has exactly 6 TabItemsFireMonkey, FireMonkey\Components

119821

[Android] Performance of Delphi Apps on Google Nexus 10(Android 4.3)FireMonkey, FireMonkey\Components

119539

[iOS] TMediaplayer pause (stop) on iOS is rewindingFireMonkey, FireMonkey\Components

119447

[Android] Location demo on some Android devices not workingFireMonkey, FireMonkey\Components
Korean input problem with Tmemo on OS XFireMonkey, FireMonkey\Components

119192

[Android] Uppercase national characters are drawn bad on AndroidFireMonkey, FireMonkey\Components

119162

[Android] password is shown on virtual keyboardFireMonkey, FireMonkey\Components
TMemo very slow on Nexus 10FireMonkey, FireMonkey\Components

119703

Stretched property of TText control does not work properly when TText is a child component for some other component, not a formFireMonkey, FireMonkey\Components

118859

[iOS] TMedia Volume cannot be changed in iOSFireMonkey, FireMonkey\Components

120023

[Android] TGestureManager crash on app close.FireMonkey, FireMonkey\Runtime
Throwing an exception and not catching it during any FMX component in an event have unexpected resultFireMonkey, FireMonkey\Runtime

119450

[iOS7] vertical touch co-ordinate is several pixels lower than the actual touch position.FireMonkey, FireMonkey\Runtime

119444

[iOS7 device] Keyboard does not completely disappear when hidden in iOS7FireMonkey, FireMonkey\Runtime
[NEXUS 10] SpeedButton – it takes too long until OnClick event is triggeredFireMonkey, FireMonkey\Runtime

118910

Keyboard shift/ctrl+arrow keys not working for FireMonkey objects on a formFireMonkey, IDE, IDE\FireMonkey Designer
iOS 7 apps showing iOS 6 styled native controls (pickers/keyboard) on iOS SimulatorFireMonkey, PAServer
FM C++ app with Mac OS X 10.9 SDK fails to compileIDE, IDE\Build System, IDE\Deployment, PAServer

120029

[Android] lower case of file path in deployedassets.txtIDE, IDE\Deployment
When starting RAD Studio XE5 (with android support installed) as the C++Builder personality it REMOVES the android SDK setting in the registry.IDE, IDE\General

118105

Android apps deployed to emulator will not function, display black screenIDE, Install

118830

Error detected (LME288), [ilink32 Error] Error: Unable to perform linkLinker

116888

Strange linker crashLinker
Throw exception crash C++ Win64 appRTL, RTL\C++, RTL\C++\Exception Handling
Wrong behavior when executing code from a catch section on Mac OSRTL, RTL\C++, RTL\C++\Exception Handling
ARC Using Unsafe objects in records are not working properlyRTL, RTL\Delphi
FM application crash at init in Android devices when the language is set to Norwegian (Norsk Bokmål)RTL, RTL\Delphi

118726

Application crash with raising exception class Segmentation fault (11)RTL, RTL\Delphi, RTL\Delphi\Other
SOAP: Double precision return values not correct for AndroidRTL, RTL\Delphi, SOAP

119872

SOAP AsDateTime implementation is wrongSOAP

119741

[Android] Segmentation fault consuming web serviceSOAP

76053

C++ templates are translated as “Vorlagen”Translation

Andreano Lanusse | Technology and Software Development
Follow me on Twitter: @andreanolanusse

Behind the connection: Compiling to native code begets better performance

$
0
0
Todays with Mobile platforms such as IOS and Android, developers are faced with writing application targeted to several platforms. Of course developers want to do that with minimal effort. This is why the market of cross platform tools is growing. Embarcadero do it well with RAD Studio XE5 (Includes Delphi and C++ Builder). There is an interesting article on NetworkWorld talking about the

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

Thanks Uncle Bob Martin for posting this.

I’ve been trying (with increasing success: it takes time to get this all right) to practice XP (through various name changes) as much and wide as possible since almost 14 years, and only the last few years it is starting to be common practice for many more people.

take a moment to reflect back on 1999. A time when Kent Beck wrote a ground-breaking book. A book that changed everything. Look back and remember: Extreme Programming; and recognize it as the core of what we, today, simply think of as:

Good Software Practice.

–jeroen

via: Extreme Programming, a Reflection | 8th Light.


Filed under: .NET, Agile, Continuous Integration, Delphi, Design Patterns, Development, Software Development, Source Code Management, Technical Debt, Testing, Unit Testing

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

Behind the connection: Why your comment does not appear on my blog

$
0
0
It seems I have to clarify why some comments does not appear on my blog. My blog is a place where I publish my personal views. It is not in anyway a public forum. To be published on my blog, a comment must be: Directly related to the subject Add something complementing the point of view I expressed Be constructive, informative and helpful  Use the same language as the post you comment The

Delphi Haven: Removing a FMX controls size restrictions

$
0
0

One rather annoying aspect of FMX’s evolution has been a restriction on control sizes. The most notorious case is probably TGroupBox, which in XE4′s iOS support was bizarrely matched to Safari’s toolbar (i.e., a standard control with a non-standard height), rendering the thing useless. Nevertheless, the general rationale for fixed sizing is not ridiculous – different platforms have different standard sizes for buttons, toolbars and so forth, so it makes sense for FMX to assist the developer in ensuring these conventions are respected. Even so, the implementation taken has been distinctly sub-optimal in my view – in particular, I would have much preferred an AutoSize property that defaults to True. As things stand, standard sizes are instead hardcoded in internal style code and trump even the Align property.

For example, here’s a right-aligned TSpeedButton with its StyleLookup set to ‘composetoolbutton’ and parented to a TListBoxItem, running on an Android tablet. I’ve taken the screenshot as I am pressing the button down – notice how this clearly shows it to be taller than its parent:

Too tall TSpeedButton

Happily, this dubious behaviour can be prevented by overriding the control’s AdjustFixedSize method however. To implement this fix in the form of an interposer class, declare the following immediately before the form type:

type
  TSpeedButton = class(FMX.StdCtrls.TSpeedButton)
  protected
    procedure AdjustFixedSize(const Ref: TControl); override;
  end;

Next, implement the method like so:

procedure TSpeedButton.AdjustFixedSize(const Ref: TControl);
begin
  SetAdjustType(TAdjustType.None);
end;

Fix added, a speed button’s Align property will now be properly respected:

Fixed TSpeedButton


The Podcast at Delphi.org: FireDAC is the Recommended Database Access Library

$
0
0

I got a great call the other morning. A Delphi developer from a few versions back was considering upgrading to XE5, but he wanted to know if FireDAC was recommended for database access, or if he would need a 3rd party library.

I remember working on some data driven Delphi applications when the drill was you always bought a 3rd party database access library. There are lots of great database access libraries to choose from, which is one of the great things about Delphi: all the technology partners!

In XE5 the BDE is officially deprecated (and has been for a while), but it still ships (maybe not for much longer though). dbExpress is still there, and so is dbGo and IBX, and they are all good, specialized database access libraries. But with the full integration of FireDAC in XE5, it is the recommended database access library, and for good reason.

FireDAC is a universal data access library: you use the same components to connect to a huge variety of databases. The usage pattern is similar to the BDE, and it is fully bidirectional. It also has a large collection of specialized features for dealing with specific databases, and local, in memory data.

If you are still on the BDE, check out the FireDAC migration guide or any of the other great FireDAC documentation. Cary Jensen just did a fabulous webinar on FireDAC including a fabulous 70 page whitepaper.

Of course you are still welcome to continue using 3rd party libraries, and some of them may offer some other specialized features. That is one of the great things about Delphi, C++Builder and RAD Studio: It comes with great features in the box, but you can expand on those with 3rd party libraries.

If you still aren’t on XE5, you still have a little time to take advantage of the special offers.

Delphi Haven: Inspecting platform styles redux

$
0
0

Back when XE3 was current I blogged about retrieving the default FMX styles for Windows and OS X, a process less transparent than in XE2 when the standard styles were distributed as *.style files. Roll onto mobile support in XE4 and XE5, and the default styles are if anything even more hidden. Nevertheless, it is possible to recover them and get human-readable *.style files:

1. Find the resource name; for Android this is currently ‘androidstyle’ (see FMX.Controls.Android.pas), for iOS one of ‘iphonestyle’, ‘ipadstyle’ or ‘iphonepadstyle_Modern’ (= iOS 7; see FMX.Controls.iOS.pas).

2. Create a blank new mobile project, and in the form’s OnCreate event, load and output the desired resource to a file. For example, for Android you might do this:

uses System.IOUtils;

procedure TForm1.FormCreate(Sender: TObject);
var
  FN: string;
  Stream: TResourceStream;
begin
  FN := TPath.Combine(TPath.GetHomePath, 'FMX default.style');
  Stream := TResourceStream.Create(HInstance, 'androidstyle', RT_RCDATA);
  Stream.SaveToFile(FN);
  ShowMessage('Saved to ' + FN);
end;

3. Run the app on a device.

4. Manually copy over the extracted file to your development PC or VM.

5. Back in your dummy project, add a TStyleBook component to the form, and double click it to open the style book editor.

6. Click the ‘Load’ button and locate the extracted *.style file.

7. Click the ‘Save’ button and overwrite the extracted *.style file.

The reason for step (7) is because the style will be extracted in a binary format, and resaving in the style book editor will output to a textual one. More specifically, it will convert from the DFM binary format to the DFM textual one with just a simple header added – FMX being based on the VCL’s streaming system as much as the VCL itself.

Removing platform restrictions

If between running the dummy app on the device and loading the extracted style file into the style book you changed the active target platform, the style book editor will complain:

Style load error

To prevent this happening in future, once you have reselected the ‘correct’ target platform (Android in my case) and now successfully loaded the style file, select the style’s ‘description’ component in the Structure pane and press Delete:

Delete style description

Having clicked Apply (or Apply and Close), the style will also now load when you select a different platform (just remember that to make a style book active, the form’s StyleBook property needs to be assigned). Here for example is the Android style used when running on Windows:

Android style on Windows

While XE5 update 2 introduced a special ‘mobile preview’ style for testing mobile projects on Windows, you can’t beat having the style that will actually be used on a device I think.


DelphiTools.info: Launching fractals.dwscript.net

$
0
0
Happy new Year to all! The fractals.dwscript.net is now launched to host the results of the recent Mandelbrot TeraPixel experiment. It’s a small website to centralizes browser, documentations, links and downloads. There was also news of a FireMonkey client for the data set API. Raw Database Downloads now Available For those interested, in the Documentation page…

Castle Game Engine news: Development: Android and iOS, new game release "Darkest Before the Dawn", more

$
0
0
Screenshot from "Darkest Before the Dawn"
Screenshot from "Darkest Before the Dawn"
One of the first 2D programs to run with OpenGLES renderer - "isometric_game" from engine examples
One of the first 3D programs to run with OpenGLES renderer - "android_demo" from engine examples
Summary of new view3dscene AWSD controls
Tooltip with summary of new view3dscene AWSD controls

Hello everyone in 2014 :)

First of all, I would like to present a small game I did during a weekend "gamejam" at the end of November 2013:

Darkest Before the Dawn

The game is free to download for Android, Linux or Windows. Of course the game uses our Castle Game Engine for everything. The complete game code and data are available in our SVN repository.

Next, we have news about the engine development:

  1. Yes, you have heard right: the engine supports Android and iOS (iPhone, iPad).

    The rendering is done using an OpenGL ES 2.0 renderer. Most of the rendering features work (and the rest is in-progress :). Rendering 3D shapes with shaders, textures, lighting of course works. Note that mobile shaders use the Gouraud shading for speed. Rendering 2D images (TGLImage) is also done. Since TGLImage is used underneath by all our 2D controls — most of 2D GUI works (except fonts, for now...).

    You can compile the whole engine for OpenGLES (as opposed to normal desktop OpenGL) by defining symbol OpenGLES in base/castleconf.inc file. This symbol is defined automatically when we compile for Android or iOS, but you can also test OpenGLES renderer on normal systems like Windows and Linux (it's a nice way to test your mobile game on a desktop system).

    We can initialize OpenGLES context using the EGL library. This is useful to initialize OpenGLES on Android or Xlib (with glX+EGL) or Windows (with wgl+EGL).

    The Android port uses NativeActivity, available since Android 2.3. It requires FPC 2.7.1 to cross-compile code to Android ARM, see FPC wiki about Android. Integration with Android includes using Android's log facility (just use WritelnLog from CastleLog unit) and using Android's assets (URLs like assets:/my_texture.png are supported, and ApplicationData returns assets:/ to read data from apk).

    You can develop cross-target games (for Android, iOS, or standalone — normal OSes like Linux or Windows) using the engine. This means that a single source code can be used to compile multiple versions of the game. We also have plans to make a "build tool" for the engine to auto-generate the necessary files for the compilation on given target (although it's unsure if this will be ready for next release). See Planned: build tool wiki page, and drop a comment if you're interested!

  2. Engine can be compiled and used as a shared library (castleengine.dll on Windows, libcastleengine.so on Linux), with API accessible from C or C++. We provide a C header in src/library/castlelib.h for this purpose. See code in src/library/ and tests in examples/library/ .
  3. The default TWalkCamera inputs are now equal to TPlayer inputs, in particular they honour common AWSD combo.
    • You can move using AWSD by default (e.g. in view3dscene).
    • Space / c keys make jump / crouch. We no longer have separate inputs for jump / crouch (when gravity works) or flying up / down (when gravity doesn't work).
    • This avoids switching the meaning or left / right arrows in mouse look mode in view3dscene.
    • This makes keys in all our programs and games more consistent. And everyone knows AWSD, while previous shortcuts for strafing (comma and dot) were quite uncommon.
    • Of course, all TWalkCamera inputs remain configurable. So, if you really liked previous key shortcuts, you can restore them for your application.
  4. TextureBackground support, making it possible to use MovieTexture as skybox sides. The rendering of Background and TextureBackground uses new simplified code, that can utilize our texture cache and works on OpenGLES too.
  5. Notes about transformation hierarchy added to the documentation.
  6. Context resource sharing (so that many windows/controls work OK, sharing textures and fonts and such) implemented for CastleWindow Xlib+GLX and GTK backends.
  7. Support for png and gz formats without any external libraries (using FpRead/WritePng and PasZlib underneath). This is particularly useful for Android and iOS, where linking with external libraries is not so easy.
  8. CastleEnumerateFiles API much changed and renamed to CastleFindFiles. It supports searching for files inside Android assets too (although, unfortunately, not recursive — because of NDK API limitations).
  9. --hide-menu option implemented for view3dscene. Useful e.g. for fullscreen presentations, where you may want to hide all UI.

Firebird News: ADO.NET provider for Firebird 4.1.0.0 is ready

$
0
0
ADO.NET provider for Firebird 4.1.0.0 is ready

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

I forgot who pointed me at this, but recently I came across a reference to the Good Ideas, Through the Looking Glass paper by Niklaus Wirth (by many known as the “father” of Pascal, though he has done a lot more - for instance the WSN - , still is involved with the ETH in Zürich, and turns 80 on February 15h).

Back when it appeared in the 2005/2006 timeframe I missed it, and I’m glad to have bumped into just for the historic perspective he offers. I can understand some will disagree with parts of his conclusions and observations, that’s why I like that MetaFilter has a nice page with discussion about it and a link to the PDF version of the paper.

I also like that Niklaus kept active in the field of computer science for so long, similar to Donald Knuth. There is a lot to having a great historic perspective to things.

–jeroen

via: Good Ideas, Through the Looking Glass | MetaFilter.


Filed under: Delphi, Development, History, Pascal, Software Development

Behind the connection: What programming languages have you used this year?

$
0
0
There is a website which maintain a voting system about which language has been used in 2013. The presentation is very nice. Of course, you should vote for your favourite language (I hope it is Delphi). To vote you need a Tweeter account. Send a tweet using the hashtag #code2013 and then the language you vote for. You can see the result, updated every 10 minutes at http://code2013.

Delphi Code Monkey: Zombie Apocalypse Survival Toolkit Part 37: The Self Contained Software Environment

$
0
0
The following is an example of my weird sense of humor.  If you don't get it, or you aren't interested in Gedankenexperimentmy regular Delphi-themed blog content will resume tomorrow. 

Imagine you knew three weeks, or three months ahead of time, that there was going to be a major Zombie Apocalypse, or something else that would basically take the internet offline for the rest of your (possibly short) life.  Imagine, furthermore, that after some months you are able to get your basic human needs taken care of, such as a place to live, clean air, clean water, food, plumbing, electricity, and get back to life at, say, a 1950s level.   You still have your computer, but it's disconnected from the internet, and it's unlikely that anything like the internet will re-emerge in  less than, say 20 years.  You wish to be a computer guy, but you now find that the world in which you might do some computing requires you to be a bit of a rugged individualist. 

Windows is a non-starter in my self-contained post-disaster scenario.   For example, one fine day, due to some glitch in Windows activation, all your Microsoft windows operating systems cease to boot.  You don't have the source code to Windows, and you can't fix it yourself.  You are now out of the computing business.   Fine, you say, the world's over, I don't care.  But wait, it's not over...


I sometimes think about this idea of having a "self contained programming environment".   It basically has the following attributes:

1.  I have the source code to the whole thing, from the metal upwards.

2.  I can boot it up to a command prompt (live CD or Usb stick) or a full graphical desktop, without any installation, on any PC-compatible.   I can also do an operating system install onto a new system, after such a boot-up, either using an automated installer, or by hand, if necessary.

3.  I can repair anything that goes wrong with it, because it's constructed according to rational principles, and because I'm a smart person.


So let's think about how you would build this.  I can think of a number of ways to build it.    I thought about Linux but most of the Linux distributions are not designed in a way that makes them easy to use in my post-apocalyptic world.  Debian and Ubuntu have apt-build for source code rebuilding, including an apt-build world capability.   Some Source-Based Linuxes out there are pretty powerful, but I find them hard to use, there's stuff like Arch Linux, and Gentoo.

Personally, I think FreeBSD,  and DragonFly BSD have a lot to recommend them for my "zombie apocalypse" deployment scenario.  These systems are uniquely suited to my Zombie Apocalypse scenario, because they are far simpler to deploy, modify, understand and thus, repair than any Linux system, and the "ports" tree for them is much smaller, and represents a natural curated set of "stuff you would want on a desert island".    Remember that when they break you can no longer google any error messages.  A simpler system, with fewer lines of code, that is functional, will be easier to maintain than one that is larger.    The BSD kernel for example is several orders of magnitude simpler to understand than the Linux kernel.   The BSD user space layout is much simpler than the Linux distribution's layout, closer to classical Unix systems practices, and has a certain Zen to it that you have to experience to understand.

If you had a large amount of disk space to reserve for a Debian Network Mirror, say one terabyte,
and you could figure out how to keep it all working, and free of bit-rot, you could probably keep a Debian system going on your local area network.    By comparison, a complete mirror of FreeBSD or DragonFly BSD, because it contains a lot less software, would be much smaller and more portable.  It contains a lot higher percentage of the stuff you might wish you had (compilers, and such) and a lot less of the end-user stuff.  So, if you wanted to say, have a reasonable set of open source games, then I would go with Linux,  but if you wanted a more general purpose Hacking system, in the classic and noble Unix meaning of the term Hacker, not a cracker, but a wizard of software, then I would go with the BSD variants.

That zen of BSD thing makes it fun to plan with. For example, FreeBSD, and DragonFly BSD have this cool thing called the "ports tree", which is basically the ancient Unix Hacker way of getting software onto a Unix system.  Originally they used CVS (that ancient version control tool), but FreeBSD has switched to Subversion, and DragonFly BSD has switched to Git.    Because of Git's DVCS capabilities, I think it's ideal for a self-replicating deploy scenario that I think we would need while rebuilding after the zombie apocalypse.

Anyways, if the recent ice storm has you thinking about being a Survivalist, and your weird mind also wanders towards "Software Survivalism", check out Dragonfly BSD.   One USB portable drive of about 1 TB in size, and you've got a pretty amazing "self contained software survival kit" for PC compatible hardware.   Batteries included.  And source code too.  

Now if you'll excuse me, I'm off to plan a bit more about the water, the food, and the electricity parts of my survival plan.  Those might be a bit harder to figure out than the software side of my plans.
Also, I think I need a USB Geiger Counter, in case of Radioactive Zombie Apocalypse.

It's a blong, blong, blong road...: Catching up on happenings in the Delphi world

$
0
0

When I’m head-down in a ‘long hours’ contract I tend to miss quite a bit of Delphi-oriented news. Once in a while I look up and I find a whole host of interesting posts around the blog-world and this has been the case over this seasonal break.

I’ve been browsing around seeing what’s new and have collated the following list of stuff I found interesting. Anyone else who hasn’t been keeping up-to-date on news of late might possibly also find some stuff of interest in the list.

Happy New Year!

Delphi XE5 Update 2

If you're a user of Delphi XE5 or RAD Studio XE5, then unless you've been hiding under a rock you'll be very much aware that Update 2 was released a while back (10th December, 2013). There are quite a few changes, so it's basically one of those uninstall/reinstall cycles. On the EDN page for Update 2 you can pull down the web installer, which downloads all the required bits over the web as it sees the need to, or pull down the rather larger full Update 2 ISO CD image. When I used the CD image I found that Hotfix 1 and Hotfix 2 (also mentioned on the same page) appeared to be already applied.

However as François Piette pointed out, we now also have a Hotfix 3 for Update 2. This addresses a few missing .OBJ files (compiled versions of C source files for the JPEG support). In the absence of a README file, I decided these files belonged alongside their corresponding source files in $(BDS)\source\vcl\jpg\src (e.g. C:\Program Files (x86)\Embarcadero\RAD Studio\12.0\source\vcl\jpg\src).

Update 2 does incorporate a good number of fixes, including the really annoying one where the form designer keyboard shortcuts (various permutations of Ctrl, Shift and the cursor keys) were not supported by the FMX form designer (as Marco posted).

Here are links for the Release Notes and the What's New page for XE5 Update Pack 2.

One of the key features added in Update 2 was iOS development support for C++ programmers. David Intersimone made a handful of posts showing how to use this support, and they have been accompanied by and followed up with a variety of videos on the Embo YouTube channel:

  • C++Builder XE5 iOS Preview slides, video
  • What's New in C++Builder XE5 for iOS, video
  • Building your first C++Builder multi-device application, post and video
  • Using TabControls, Gestures and Actions in your C++Builder XE5 for iOS apps, post and video
  • Using Image Effects Filters in your C++Builder for iOS apps, post and video
  • Location enabling your C++Builder for iOS apps, post and video
  • Mobile Code Snippets: IBLite on iOS, video
  • Mobile Code Snippets: Date Picker for iOS, video
  • Mobile Code Snippets: Sharesheet & Media Library Actions, video
  • Mobile Code Snippets: Sending & Cancelling Notifications, video
  • Mobile Code Snippets: Tap & Hold Interactive Gesture, video
  • Mobile Code Snippets: Sending & Resetting Badge Numbers, video
  • Mobile Code Snippets: Pinch & Zoom Interactive Gesture, video

Another neat feature slipped in is the Mobile Preview feature, which allows you to compile and test a good chunk of your mobile functionality within a Windows preview app. It's discussed by Marco here and Sarina DuPont here and documented here.

Recent VCL enhancements

Given Embo's focus on talking lots and lots about FMX over recent years it's easy to forget that the VCL is still being enhanced. Indeed so easy that when XE5 was released, the home page made nary a mention of VCL! Anyway, in an attempt to redress the balance DavidI emitted a blog post that talks about the benefits of VCL in Delphi XE5.

In there he mentions support for 64-bit Windows, full Unicode support, FireDAC, the REST client support, VCL styles, LiveBindings, Metropolis for Windows 8-like apps, and sensor support.

Some additional posts on the REST client support are:

On the subject of FireDAC, if you missed it you can catch the replay of Cary Jensen’s webinar on the subject, entitled: No App is an Island: Universal Enterprise Data Connectivity for the Multi-Device World with FireDAC. Also available on that page are a hefty white paper by Cary to back up the webinar and links to some FireDAC videos.

And for additional Unicode information, check the list of resources collated by Malcolm Groves (and others in the comments) in his post Resources for Unicode in Delphi.

New product features for old product users

I discovered that Embo have made some pages that talk about new features in releases since certain commonly used old versions. For those trying to find out how much merit there might be in upgrading to the current XE5 release from an old version these pages could prove pretty useful. So we have:

Warren Postma has a post citing a variety of reasons to upgrade: Modernize your codebase: Inspiration to Ditch your Ancient Delphi Version. Do read through them.

reFind for search/replace with PCRE

Here’s a tool I didn’t notice appear in Delphi XE5. It’s a command line find/replace tool that uses Perl-compatible regular expressions (PCRE). It’s documented in the XE5 docwiki and uses a rule file to control the process of running over a bunch of source files (and form files) making specified changes.

The tool comes from FireDAC (née AnyDac) and was designed to help migrate BDE components and code over to [Any|Fire]DAC equivalents, but of course can be applied to any search/replace scenario.

Embo’s Stephen Ball posted on the topic of source migration from Delphi 5 to Delphi XE5, which is where I first bumped into the tool. I’ve since seen it referenced on posts on Mick’s Mix and Marco’s blog.

Mobile coding topics

We've had a good spate of posts on how to do various things in Delphi mobile apps.

Here are some Android-specific ones:

Here is an iOS topic:

And here are some that cover both Android and iOS:

Additionally DavidI posted a useful set of resource links that came up in his Step Up to the Multi-Device App Platform webinar so do peruse them at your leisure.

DEP & ASLR in Windows projects

While looking into reFind I bumped into a new (to me) Delphi blog from Mick Grove called Mick’s Mix. A 2011 post on there reminded me of support added to Delphi 2007 and later to support DEP (Windows XP SP2 and later) and ASLR (Windows Vista and later).

DEP is Data Execution Prevention, which helps avoid hacked data bytes being executed. This is done in 32-bit apps using AMD’s NX (no-execute page protection) processor feature and Intel’s XD (Execute Disable Bit) processor feature.

ASLR is Address Space Layout Randomization and helps foil buffer overrun exploits by randomising the load address of DLLs. Thus ASLR is only really pertinent to DLLs or packages.
[ Update: thanks to Ericlaw for pointing out that setting the DynamicBase flag in an executable project randomises the location of heaps and other data structures, as well as enabling other mitigations. In other words, ASLR should really be enabled on all projects as should DEP. ]

According to a post by MSDN blogger Michael Howard, and echoed by a post by Hallvard Vassbotn, Delphi 2007 added support for ASLR and DEP by the small operation of adding this after the uses clause in the project file:

{$SETPEOPTFLAGS $140}

This sets 2 flags in the DllCharacteristics field of the IMAGE_OPTIONAL_HEADER section of the PE file that your DLL will be emitted as by the linker.

IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE and IMAGE_DLLCHARACTERISTICS_NX_COMPAT are defined by Microsoft’s MSDN documentation as having the values 0x0040 and 0x0100 respectively.

IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE is defined as: the DLL can be relocated at load time.

IMAGE_DLLCHARACTERISTICS_NX_COMPAT is defined as: the image is compatible with data execution prevention (DEP).

Neither of these constants is defined in Delphi’s Winapi.Windows.pas, but for readability you could alternatively write this below the DLL project’s uses clause:

const
  IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = $0040;
  IMAGE_DLLCHARACTERISTICS_NX_COMPAT = $0100;

{$SETPEOPTFLAGS IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE or
                IMAGE_DLLCHARACTERISTICS_NX_COMPAT}

For ASLR in DLLs and packages you can alternatively use the undocumented {$DYNAMICBASE ON} directive (as mentioned by Michael and Hallvard), which has the same effect as setting the IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE PE opt flag. Thus this would be a viable equivalent:

const
  IMAGE_DLLCHARACTERISTICS_NX_COMPAT = $0100;

{$SETPEOPTFLAGS IMAGE_DLLCHARACTERISTICS_NX_COMPAT}
{$DYNAMICBASE ON}

Note that in more recent product releases you can also pass these optional PE header flags using a linker switch. In the Linking section of the Project Options dialog you can pass the combined decimal flags value to the Set extra PE Header optional flags field, so $140 would need a value of 320 to be passed in.

You can see that the flags have been noted by looking at the properties of your project when running using a tool such as Process Explorer from SysInternals.

DEP and ASLR

Delphi Haven: Improved XE5 mobile previews part 2

$
0
0

Last time around I blogged about how to extract the default XE5 mobile styles into *.style files – in a nutshell, you need to create an app that extracts the desired style resource to a file, then open the file in the stylebook editor, delete the ‘Description’ resource, and resave. In that post I went on to suggest using the extracted files in TStyleBook components. There is however a better way – provide a custom FMX.MobilePreview unit instead (NB: for all about the standard mobile previews – introduced in XE5 update 2 – check out either Marco Cantù’s blog post or the documentation).

To do this, create a new unit and, modeling on the standard FMX.MobilePreview.pas, add the following code:

unit FMX.MobilePreview;
{
  Use actual Android style
}
interface

implementation

{$IFDEF MSWINDOWS}

{$IF CompilerVersion <> 26}
  {$MESSAGE Error 'Custom FMX.MobilePreview.pas expects XE5!'}
{$IFEND}

uses
  System.Types, System.SysUtils, FMX.Styles, FMX.Graphics, FMX.Platform;

var
  OldInitProc: TProcedure;

procedure InitializeStyle;
begin
  if Assigned(OldInitProc) then
    OldInitProc();
  //!!!change path to whereever you have put the resaved *.style file
  TStyleManager.SetStyle(TStyleManager.LoadFromFile('C:\Delphi\LibXE5\Android.style'));
end;

initialization
  OldInitProc := InitProc;
  InitProc := @InitializeStyle;

finalization
  TStyleManager.SetStyle(nil);
  TCanvasManager.UnInitialize;
{$ENDIF}
end.

If you save the unit as FMX.MobilePreview.pas, compile and ensure the DCUs are in the global search path, you can have the IDE pick it up rather than the standard FMX.MobilePreview.pas. Alternatively, save it under a different name and just amend your project files to use it rather than FMX.MobilePreview.

That said, if you do this, something still won’t quite be right – namely, the font:

Font not right

This is because in the current FireMonkey code, the default font is a property of the platform rather than the style. As such, the font used here is a regular Windows one rather than Roboto, the default font on Android. Fixing this discrepancy is easy however – back in the custom unit, first add the following class immediately after the uses clause:

type
  TFMXSystemFontService = class(TInterfacedObject, IFMXSystemFontService)
  public
    function GetDefaultFontFamilyName: string;
  end;

function TFMXSystemFontService.GetDefaultFontFamilyName: string;
begin
  Result := 'Roboto';
end;

Secondly, unregister the standard IFMXSystemFontService implementation before registering our own by adding the following lines at the top of the unit’s initialization block:

  TPlatformServices.Current.RemovePlatformService(IFMXSystemFontService);
  TPlatformServices.Current.AddPlatformService(IFMXSystemFontService, TFMXSystemFontService.Create);

In all, the code for unit should now look like this:

unit FMX.MobilePreview;
{
  Use actual Android style
}
interface

implementation

{$IFDEF MSWINDOWS}
{$IF CompilerVersion <> 26}
  {$MESSAGE Error 'Custom FMX.MobilePreview.pas expects XE5!'}
{$IFEND}
uses
  System.Types, System.SysUtils, FMX.Styles, FMX.Graphics, FMX.Platform;

type
  TFMXSystemFontService = class(TInterfacedObject, IFMXSystemFontService)
  public
    function GetDefaultFontFamilyName: string;
  end;

function TFMXSystemFontService.GetDefaultFontFamilyName: string;
begin
  Result := 'Roboto';
end;

var
  OldInitProc: TProcedure;

procedure InitializeStyle;
begin
  if Assigned(OldInitProc) then
    OldInitProc();
  TStyleManager.SetStyle(TStyleManager.LoadFromFile('C:\Users\CCR\Downloads\Android FMX (resaved, and minus description).style'));
end;

initialization
  TPlatformServices.Current.RemovePlatformService(IFMXSystemFontService);
  TPlatformServices.Current.AddPlatformService(IFMXSystemFontService, TFMXSystemFontService.Create);
  OldInitProc := InitProc;
  InitProc := @InitializeStyle;

finalization
  TStyleManager.SetStyle(nil);
  TCanvasManager.UnInitialize;
{$ENDIF}
end.

Run the mobile preview again, and the font is now how it should be:

Font fixed


Viewing all 1725 articles
Browse latest View live