The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for the ‘Delphi’ Category

Tip for the doc team: make TMonitor.Enter docs more clear on non-blocking re-entry from the same thread

Posted by jpluimers on 2018/04/19

Even when the Delphi team was large, the documentation was lacking, so with the reduced Delphi team size, I don’t have high expectations of the below to get fixed.

But since much of the post Delphi 7 run-time library looks a lot like the .NET core, you can usually fallback to the Microsoft documentation.

Tip for the doc team: make http://docwiki.embarcadero.com/Libraries/en/System.TMonitor.Enter more clear. Especially that if the same thread calls TMonitor.Enter more than one time, it will allow entry without blocking as per System.Threading.Monitor.Enter Method (Object) documentation https://msdn.microsoft.com/en-us/library/de0542zz

(note that this got introduced in Delphi XE3: http://docwiki.embarcadero.com/Libraries/XE3/en/System.TMonitor.Enter)

–jeroen

via: [WayBack] Tip for the doc team: make http://docwiki.embarcadero.com/Libraries/Seattle/e…

Posted in Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 2 Comments »

Reminder to Self: `TProc` is incompatible with parameterless procedures on interfaces

Posted by jpluimers on 2018/04/19

I knew that methods on interfaces were not compatible with the procedure of object (like [WayBack] TProc)or function of object construct, but they are also not compatible with the reference to procedure or reference to function construct.

Via: [WayBack] I try to call an Interface method from TThread.Syncrhonize()…and Berlin don’t accept that… – Paul TOTH – Google+

If you want it fixed, vote for [RSP-13007] Interface methods are not assignable to anonymous method variable – Embarcadero Technologies (Thanks Stefan Glienke).

You can work around it with an anonymous method.

This won’t work:

program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;
 
type
  ITest = interface
    ['{B5AD87E8-A3DF-4B83-BE14-997C2E76A06C}']
    procedure Run;
  end;
 
  TTest = class(TInterfacedObject, ITest)
    procedure Run;
  end;
 
procedure TTest.Run;
begin
  Writeln('PASS')
end;
 
var
  test: ITest; // <- change this to TTest and it compiles
  proc: TProc;
begin
  test := TTest.Create;
  proc := procedure begin test.Run; end; // <- this compiles
  proc := test.Run; // E2010 Incompatible types: 'TProc' and 'procedure, untyped pointer or untyped parameter'
  proc();
  Readln;
end.

–jeroen

 

Posted in Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

… / source / Native / Delphi / Library / Data / DataSetEnumeratorUnit.pas — Bitbucket

Posted by jpluimers on 2018/04/18

Reminder to self that I one day need to write more about this enumerator:

[WayBackjeroenp / BeSharp.net / source / Native / Delphi / Library / Data / DataSetEnumeratorUnit.pas — Bitbucket

It’s not nearly as good as the one by Uwe Raabe, but I didn’t really update this code for about a decade as it has functioned well for me in the current state: in 2009 it was like [WayBackbo library – Source Code.

Code by Uwe is at [WayBackDataset Enumerator Reloaded | The Art of Delphi Programming via [WayBack] Refurbishing old code: http://www.uweraabe.de/Blog/2017/02/09/dataset-enumerator-reloaded/Uwe Raabe – Google+

A couple of years ago I wrote a two-part article about a dataset enumerator: A Magical Gathering – Part 1 and Part 2. Well, things evolved a bit since then and I wondered how one would implement something similar given the current features of Delphi. Actually I am following here a suggestion from commenter Alan Clark.

So for now it’s just to document that my enumerator is there and that it works as intended.

I referenced an older version at [WayBackFor-in Enumeration – ADUG as I used it at Spoken @ CodeRage III, December 1-5, 2008 on Delphi, database and XML related topics and Source: Conferences/2009/DelphiLive.2009/Smarter-code-with-databases-and-data-aware-controls.

A small video on how you use it is here:

It was back when Better Office and CodeGear still existed and we celebrated (late) Gwan Tan’s 50th birthday.

O the days (:

More history:

–jeroen

Posted in Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 2 Comments »

TTemporaryFileStream – via DELPHI AREA » How to have a temporary stream, with no size limit

Posted by jpluimers on 2018/04/17

I needed a TTemporaryFileStream and found it at [WayBackDELPHI AREA » How to have a temporary stream, with no size limit.

It taught me that CreateFileA and CreateFileW (the ANSI and Unicode versions of [WayBackCreateFile function (Windows)) accept a FILE_FLAG_DELETE_ON_CLOSE parameter, so as soon as you close the handle, Windows will dispose of the file.

Note however that this will apply to the file handle so if you want to open it multiple times, you need [WayBackDuplicateHandle function (Windows) as per [Archive.isThe FILE_FLAG_DELETE_ON_CLOSE flag applies to the handle, also known as the file object, which is not the same as the file – The Old New Thing

–jeroen

Posted in Delphi, Development, Software Development, The Old New Thing, Windows Development | Leave a Comment »

Why you should try to avoid using Variant operations in Delphi

Posted by jpluimers on 2018/04/17

[WayBackDelphi “WAT?!” of the day: var v1, v2: Variant; begin v1 := True; v2 := True… shows some interesting code.

The [WayBackVariant Types (Delphi) – RAD Studio: Variant Type Conversions (and the decimal point/comma handling or rounding issues not documented there) usually kill you and are the most important reason to avoid Variant operations in Delphi.

–jeroen


// Delphi "WAT?!" of the day:
var
v1, v2: Variant;
begin
v1 := True;
v2 := True;
Writeln(v1 + v2); // -2
Readln;
end.

Posted in Delphi, Development, Software Development | 5 Comments »

David Heffernan was on a bug reporting spree. Compiler unit tests could have detected these much faster.

Posted by jpluimers on 2018/04/12

For my archive, most bugs around UInt64 handling, lots of them in the Windows x64 compiler, all by David Heffernan:

  1. [WayBack] Who can guess what value is returned by StrToFloat(‘߀’) if the PUREPASCAL version of StrToFloat is used ……. Make sure that you copy and paste the… – David Heffernan – Google+
  2. [WayBack] Another day, another bug. This one a rather nasty one in the x64 compiler. Consider this program: {$APPTYPE CONSOLE} uses System.SysUtils; var … – David Heffernan – Google+
  3. And my run of bugs continues: https://quality.embarcadero.com/browse/RSP-20351 This program: {$APPTYPE CONSOLE} var D: Double; U64: UInt64; begin … – David Heffernan – Google+
  4. [WayBack] Final bug of my day: https://quality.embarcadero.com/browse/RSP-20353 {$APPTYPE CONSOLE} var I: Integer; U64: UInt64; D: Double; begin I := 1;… – David Heffernan – Google+

I also learned that quite a while ago, [Archive.is] System.TFloatSpecial – XE2 API Documentation got introduced.

1: Who can guess what value is returned by

StrToFloat('߀')

if the PUREPASCAL version of StrToFloat is used …….

Make sure that you copy and paste the code above rather than re-typing it.

To spoil the surprise read this: https://stackoverflow.com/a/49736812/

2: Another day, another bug. This one a rather nasty one in the x64 compiler.

Consider this program:

{$APPTYPE CONSOLE}

uses
  System.SysUtils;

var
  D: Double;
begin
  Writeln(fsZero=D.SpecialType);
  Writeln(fsNZero=D.SpecialType);
  D := -D;
  Writeln(fsZero=D.SpecialType);
  Writeln(fsNZero=D.SpecialType);
Readln;
end.

It should output

TRUE
FALSE
FALSE
TRUE

It does so on x86. On x64 it outputs

TRUE
FALSE
TRUE
FALSE

The reason being that Emba implemented floating point negation on x64 by compiling

-d

as

0 - d

Which is a different thing.

The right thing to do is to load the value into an XMM register, and then xor it with 8000000000000000h.

https://quality.embarcadero.com/browse/RSP-20350

That’s three bugs in two days!

3: And my run of bugs continues: https://quality.embarcadero.com/browse/RSP-20351

This program:

{$APPTYPE CONSOLE}
var
  D: Double;
  U64: UInt64;
begin
  D := high(UInt64);
  Writeln(D);

  U64 := high(UInt64);
  D := U64;
  Writeln(D);

  Readln;
end.

should output

1.84467440737096E+0019
1.84467440737096E+0019

but in fact outputs

-1.00000000000000E+0000
1.84467440737096E+0019

I guess the compiler generates code as if the constant value was treated as a signed Int64.

Shout out to +Stefan Glienke for bringing this one to my attention.

I have one more bug that I have seen, but not yet submitted.

Quite amazing what can be found with a little bit of effort. Imagine if the Emba team put in some serious testing effort?

4. Final bug of my day: https://quality.embarcadero.com/browse/RSP-20353

{$APPTYPE CONSOLE}
var
I: Integer;
U64: UInt64;
D: Double;
begin
I := 1;
U64 := $8000000000000000;
D := I * U64;
Writeln(D);

U64 := $7fffffffffffffff;
D := I * U64;
Writeln(D);

Readln;
end.

Under dcc32 all is well, the output is

9.22337203685478E+0018
9.22337203685478E+0018

but under dcc64 it all goes south

-9.22337203685478E+0018
9.22337203685478E+0018

Looks like the compiler authors still haven’t found all the parts of the code that treat UInt64 as though it were Int64.

All these bugs (5 reports, but more bugs) from one simple SO question yesterday about StrToFloat……..

Posted in Delphi, Development, Software Development | 2 Comments »

Delphi attributes cannot use `const x: array of string` as argument

Posted by jpluimers on 2018/04/12

[WayBack] I want to annotate some of my enumerated types with human facing names. So I want to write: type[Names(‘Explicit time domain’, ‘Implicit time domain’,… – David Heffernan – Google+

This does not work:

constructor Create(const Values: array of string);

It seems to be in QC.

The reason is not obvious until you realise (thanks Stefan for wording that) that attribute constructor arguments are limited to anything that can be const. Open arrays nor dynamic arrays can be const (yes, nowadays you can have “consts” that are dynamic arrays but in fact they are compiler protected variables).

An alternative you might think works, but fails us using one attribute per enumeration element. But that’s where Delphi RTTI leaves you in the dark: it does not expose the RTTI for enumeration elements (likely doesn’t even generate it), only the the enumeration type itself.

So this fails:

type
  NameAttribute = class( TCustomAttribute )
  private
    FName: String;
  public
    constructor Create( AName : String );
    property Name: String read FName;
  end;

  TMyEnumeration = (
    [Name('One')]
    meOne,
    [Name('Two')]
    meTwo
  );

–jeroen

 

Posted in Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

Improve Android and iOS debug compilation speed – grijjy blog – Set the Debug information option to Limited Debug information

Posted by jpluimers on 2018/04/12

If you develop mobile apps with Delphi, you know it: compiling for Android and iOS is sloooooooooooooow, especially for debug builds. This little tip makes compiling Debug builds much faster……

Set the Debug information option to Limited Debug information

When I read a thing like that, I always think “how come I never thought about that before?” Well done Erik!

[WayBackImprove Android and iOS debug compilation speed – grijjy blog

via: [WayBack] Here’s a quick tip to improve the compilation speed of debug builds for iOS and Android… – Erik van Bilsen – Google+

–jeroen

Posted in Android, Delphi, Development, iOS Development, Mobile Development, Software Development | Leave a Comment »

Disable the Delphi clipboard history; originally by Attila Kovacs at https://plus.google.com/u/0/108426155215159556558/posts/6MBZuMYDTCD

Posted by jpluimers on 2018/04/07

Delphi Clipboard History

Delphi Clipboard History

[WayBack] Castalia had a Clipboard History for Delphi since a long time and since the acquisition of it around Delphi XE8, that was [Archive.isintegrated into the IDE for everyone to use as the [WayBack] “Delphi Clipboard History

Some people object to the history viewer, for instance:

  • stability reasons
  • security issues

Even though used by a lot of password managers to transfer saved passwords to applications requiring credentials, the clipboard isn’t really a secure place as it is a shared resource that any application can monitor: [WayBackIs a password in the clipboard vulnerable to attacks? – Information Security Stack Exchange.

It’s just that often the clipboard is about the only way to communicate date between two applications.

The real reason to get rid of the clipboard history is that in many Delphi versions it causes trouble with RichEdit controls: [Archive.isCastalia’s Clipboard history + TRichEdit = IDE deadlock | Andy’s Blog and Tools after Eugene Kotlyarov posted a [WayBack] bug issue on G+.

I’m still not sure why Castalia and Delphi include a Clipboard History and even show it by default as:

If you would want to build such a tool (that can hide itself when not needed), then use the free repository at chrisrolliston/CCR.Clipboard: Extended TClipboard implementation for Delphi (FMX and VCL) [Archive.isDitto download | SourceForge.net

At G+, Attila Kovacs published a non-intended version of the below version: [WayBack]

Source: Disable the Delphi clipboard history; originally by Attila Kovacs at https://plus.google.com/u/0/108426155215159556558/posts/6MBZuMYDTCD

–jeroen

Read the rest of this entry »

Posted in Castalia, Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

Do not use non-ASCII characters as identifiers – not all your tools support them well enough

Posted by jpluimers on 2018/04/05

For a very long time I’ve discouraged people from using non-ASCII characters in identifiers. It still holds.

In the past, transliterations messed things up. Even with increased support for Unicode, tools still screw non-ASCII characters up.

Delphi is not alone in this (the most important one is the DFM view as text support), see this report: [RSP-16767] Viewing a form as text fails with non ascii control or event names – Embarcadero Technologies (you need an account for this, but the report is visible for anyone):

Viewing a form as text fails with non ascii control or event names Comment

Steps:

  1. create a new VCL forms application
  2. drop a label onto the form
  3. change the name of that label to lblÜberfall (note the U-umlaut)
  4. switch to view as text
  • exp: DFM content shown as text
  • act: first line is shown incorrectly (see screenhsot)

–jeroen

Source: [RSP-16767] Viewing a form as text fails with non ascii control or event names – Embarcadero Technologies

via: [WayBack] Code of the day – – Thomas Mueller (dummzeuch) – Google+:

function TNameGenerator.StrasseToStrasse(const _Strasse: string): string;
begin
Result := _Strasse;
end;

Strasse := StrasseToStrasse(_Strasse);

Read the rest of this entry »

Posted in ASCII, Conference Topics, Conferences, Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Encoding, Event, Mojibake, Software Development | Leave a Comment »