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,854 other subscribers

Archive for the ‘Delphi’ Category

TFreedObject in FastMM4/FastMM4.pas at master · pleriche/FastMM4 · GitHub

Posted by jpluimers on 2020/01/08

Reminder to Self:

  {The class used to catch attempts to execute a virtual method of a freed
   object}
  TFreedObject = class
  public
    procedure GetVirtualMethodIndex;
    procedure VirtualMethodError;
{$ifdef CatchUseOfFreedInterfaces}
    procedure InterfaceError;
{$endif}
  end;

If you encounter the class TFreedObject when doing a cast, then you’re working on a freed object and have FastMM4 enabled to detect that.

Source: [WayBackFastMM4/FastMM4.pas at master · pleriche/FastMM4 · GitHub; FastMM4 – A memory manager for Delphi and C++ Builder with powerful debugging facilities

Note that if you want to see the underlying FastMM data for any TObject allocation, use this watch (where Self is the current instance):

PFullDebugBlockHeader(PByte(Self) - SizeOf(TFullDebugBlockHeader))^

You can also put a ,r behind it to see the fields of this structure:

(Reserved1:nil; Reserved2:nil; AllocatedByRoutine:$41BF74; AllocationGroup:0; 
AllocationNumber:592682; 
AllocationStackTrace:(4224198, 4233131, 4235210, 11103806, 6552132, 131126, 6597961, 11106984, 4235210, 11107153, 11104090); 
AllocatedByThread:90428; FreedByThread:90428; 
FreeStackTrace:(4241541, 131126, 4235210, 11103806, 6552132, 131126, 6597961, 11106984, 4235210, 11107153, 11104090); 
UserSize:36; PreviouslyUsedByClass:132272; HeaderCheckSum:2673350594)

–jeroen

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

VCL FadingEffect by Paul Toth at GitHub

Posted by jpluimers on 2020/01/07

In case I ever need a fading effect between 2 panels on one form, there is some code that will get me started.

I’d probably code it in a different design (without a global variable), but it works so can be a good source of ideas.

Source: Delphi/FadingEffect at master · tothpaul/Delphi · GitHub

Via: [WayBack] VCL Tiny demo of a Fading effect for Delphi Tokyo  – Paul TOTH – Google+

–jeroen

Read the rest of this entry »

Posted in Delphi, Development, Software Development | Leave a Comment »

Im memoriam: Rudy Velthuis

Posted by jpluimers on 2020/01/05

Given that I’m fighting rectal cancer and am extremely low on energy, I am keeping this much shorter than I want to.

Recently, I learned that Rudy Velthuis passed away on 2019-05-13. Born on 1960-10-30, he passed away at only age 58.

After asking permission from his family, I wrote a small im memoriam.

We frequently encountered each other on-line in the Delphi community, especially in the early days when I was way more active on forums, newsgroups and chat channels. He was famous there, with good reason.

Though colloquially known as [WayBack“dentist with a strong interest in programming”, he was a great Delphi programmer and very well known for thoroughly documenting the many gaps that Embarcadero left in their documentation.

In 2009, Edwin van der Kraan and I had an opportunity to have dinner with Rudy. We met at his house, where we learned he not only ran a fully fledged dentistry practice, but also was married someone who origilally was from the Philippines. A truly happy couple they were.

In retrospect, I wish we had had met in real life more often, but I’m learning the hard way that life is finite giving you only so much time to do things.

I will remember Rudy because of his knowledge, wit and odd – but great – combination of work and interests.

In the mean time, I have asked a few archival organisations (including the WayBack machine) to archive his sites:

Some of his profiles that I archived on 20190103:

I love the “Kraftwerk – Autobahn” picture on his Stack Overflow profile page, so I included that song below the fold.

Related:

–jeroen

Read the rest of this entry »

Posted in About, Delphi, Development, History, Personal, Software Development | 4 Comments »

Delphi Programming Blog (by Shaun Roselt): Delphi Communties on: WhatsApp, Telegram, Google+, Facebook

Posted by jpluimers on 2020/01/02

From a while ago by a young (then ~18, now around ~20) enthusiastic Delphi programmer: [WayBackDelphi Programming Blog (by Shaun Roselt): Delphi Communties on: WhatsApp, Telegram, Google+, Facebook

He has an interesting YouTube channel too: https://www.youtube.com/user/shaunroselt/videos

–jeroen

Via: [WayBack] More Delphi communities! – Ilya S – Google+

 

Posted in Delphi, Development, Software Development | Leave a Comment »

GitHub – Libaud/POLCLVCLISO: Pascal Object LCL and VCL ISO standards implementation for CodeTyphon, Delphi, Lazarus

Posted by jpluimers on 2020/01/02

For my link archive: GitHub – Libaud/POLCLVCLISO: Pascal Object LCL and VCL ISO standards implementation for CodeTyphon, Delphi, Lazarus

It implements these standards:

  • ISO standard 3166-1, 3166-2, 3166-3 implementation
    • (all part of the ISO 3166 – Wikipedia that “defines codes for the names of countries, dependent territories, special areas of geographical interest, and their principal subdivisions)”
  • ISO standard 4217 implementation
    • ISO 4217 – Wikipedia  “delineates currency designators, country codes (alpha and numeric)” where the country codes are the same as in ISO 3166
  • ITU E.164 standard implementation
    • E.164 – Wikipedia “E.164 defines a general format for international telephone numbers. Plan-conforming numbers are limited to a maximum of 15 digits, excluding the international call prefix.”

A library like this needs monitoring the standards changes, so hopefully Libaud will do that.

Some of my posts related to ISO 3166 are below.

–jeroen

Related:

 

Posted in Delphi, Development, FreePascal, Lazarus, Pascal, Software Development | Leave a Comment »

Delphi multi-threading: confused by TThread.Synchronize / TThread.Queue? You’re not alone. And you need to be aware of exceptions there too.

Posted by jpluimers on 2020/01/01

Below an elaboration on my answer to the question [WayBack] I don’t understand the following part of the second Delphi example:TThread.Synchronize… – Alberto Paganini – Google+:

I was looking at the Task example at the EMB wiki link below

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Tutorial:_Using_Tasks_from_the_Parallel_Programming_Library

and I don’t understand the following part of the second Delphi example:

TThread.Synchronize(nil,
  procedure
  begin
    Label1.Text := lValue.ToString;
  end);

why is there the need to pass Label1.Text := lValue.ToString; as procedure in TThread.Synchronize ?

Why not a simple Label1.Text := lValue.ToString; ?

Basically that question can be either of these:

  1. Why is there no easier language construct than wrapping the callback in a procedure (anonymous method).
  2. Why a call to TThread.Synchronize at all?

The tutorial that Alberto refers to is [WayBack] Tutorial: Using Tasks from the Parallel Programming Library – RAD Studio. That example uses the TTask feature in Delphi, but the portion he has a question about is general to any multi-treading in Delphi that touches the updating of a VCL or FMX UI from another thread.

This is the more complete code in the meant example:

procedure TForm1.ButtonTask1Click(Sender: TObject);
var
  lValue: Integer;
begin
    Label1.Text := '--';
    TTask.Run(procedure
      begin
          {Some calculation that takes time}
          Sleep(3000);
          lValue := Random(10);
          TThread.Synchronize(nil,
            procedure
            begin
                  Label1.Text := lValue.ToString;
            end);
      end);
end;

What happens here is that the TTask is used to run some code (starting with {Some calculation that takes time}) in a different thread (that is being determined by the framework behind TTask).

I recommend against using TTask (or any other part of the Delphi Parallel Programming Library) as I agree with Stefan Glienke in [WayBack] Hello, Do you know why the “default” keyword of a class property is sometime defined also as an attribute ? – Paul TOTH – Google+:

If that works as well as the PPL does I would not touch it with a 10 foot pole ;)

With “that”, he refers to the APL (Asynchronous Programming Library [Archive.is]) which got introduced in Delphi XE8 and adds asynchronous support for UI controls, but unlike .NET (which implements it on the .NET TControl equivalent) shifted it down to TComponent probably because that’s the common ancestor for both VCL and FMX. But that’s a topic for another day.

The Delphi Parallel Programming Library (DPL) is a complex and intricate framework originally started as Delphi Parallel Library (DPL) and modelled after [WayBackIntel’s Threading Building Blocks (TBB) and Microsoft’s Task Parallel Library (TPL) (not in WayBack, but moved to the CHM file [WayBack], see also[WayBack] Task Parallel Library changes since the MSDN Magazine article | Parallel Programming with .NET)

Most parts of the DPL were written over at least 7 years time by former Chief Scientist Allen Bauer and introduced in Delphi XE7 as the Delphi Parallel Programming Library (PPL), see [WayBack] Delphi Parallel Programming Library & Memory Managers – Steve Maughan and [WayBack] The Oracle at Delphi: Lock my Object… Please!.

Since Delphi XE7, the PPL hardly got maintenance and now most if not all of the people having knowledge about it have left Embarcadero: early 2016, [Archive.is] Delphi Chief Scientist Allen Bauer Has Left Embarcadero/Idera | Hacker News leaving a big gap as “There are no plans that I’m aware of to move someone into my old position… All those that I would consider qualified are either already gone or are currently looking elsewhere.” (it is not in the [WayBack] part of How safe is Delphis future? Who is the new Lead Compiler Engineer? Who is the new Chief Scientist? – Ralf Stocker – Google+, hence the screen shot).

Luckily, Allen copied most of his old Embarcadero blog over to his personal one (including comments!), so there is quite some historic reference, see for instance [WayBack] Thread pools <> Task handling. – Community Blogs – Embarcadero Community and [WayBack] The Oracle at Delphi: Thread pools <> Task handling.

So back ensuring you can execute some code on the main thread and the questions from the G+ post:

  1. Why is there no easier language construct than wrapping the callback in a procedure (anonymous method).
  2. Why a call to TThread.Synchronize at all?

Lets start with the questions in order I answered them, starting with the my response:

Read the rest of this entry »

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | Leave a Comment »

from old school to new frontier: Pattern, naming and MVVM from a Delphi point of view.

Posted by jpluimers on 2019/12/31

On my list of things to check later: FMBC a Delphi implementation of MVVM? [WayBackfrom old school to new frontier: Pattern, naming and MVVM from a Delphi point of view.

via: [WayBack] #FBMC the new MVVM 2.5? – Frank Lauter – Google+

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi, decoding files to strings and finding line endings: some links, some history on Windows NT and UTF/UCS encodings

Posted by jpluimers on 2019/12/31

A while back there were a few G+ threads sprouted by David Heffernan on decoding big files into line-ending splitted strings:

Code comparison:

Python:

with open(filename, 'r', encoding='utf-16-le') as f:
  for line in f:
    pass

Delphi:

for Line in TLineReader.FromFile(filename, TEncoding.Unicode) do
  ;

This spurred some nice observations and unfounded statements on which encodings should be used, so I posted a bit of history that is included below.

Some tips and observations from the links:

  • Good old text files are not “good” with Unicode support, neither are TextFile Device Drivers; nobody has written a driver supporting a wide range of encodings as of yet.
  • Good old text files are slow as well, even with a changed SetTextBuffer
  • When using the TStreamReader, the decoding takes much more time than the actual reading, which means that [WayBack] Faster FileStream with TBufferedFileStream • DelphiABall does not help much
  • TStringList.LoadFromFile, though fast, is a memory allocation dork and has limits on string size
  • Delphi RTL code is not what it used to be: pre-Delphi Unicode RTL code is of far better quality than Delphi 2009 and up RTL code
  • Supporting various encodings is important
  • EBCDIC days: three kinds of spaces, two kinds of hyphens, multiple codepages
  • Strings are just that: strings. It’s about the encoding from/to the file that needs to be optimal.
  • When processing large files, caching only makes sense when the file fits in memory. Otherwise caching just adds overhead.
  • On Windows, if you read a big text file into memory, open the file in “sequential read” mode, to disable caching. Use the FILE_FLAG_SEQUENTIAL_SCAN flag under Windows, as stated at [WayBack] How do FILE_FLAG_SEQUENTIAL_SCAN and FILE_FLAG_RANDOM_ACCESS affect how the operating system treats my file? – The Old New Thing
  • Python string reading depends on the way you read files (ASCII or Unicode); see [WayBack] unicode – Python codecs line ending – Stack Overflow

Though TLineReader is not part of the RTL, I think it is from [WayBack] For-in Enumeration – ADUG.

Encodings in use

It doesn’t help that on the Windows Console, various encodings are used:

Good reading here is [WayBack] c++ – What unicode encoding (UTF-8, UTF-16, other) does Windows use for its Unicode data types? – Stack Overflow

Encoding history

+A. Bouchez I’m with +David Heffernan here:

At its release in 1993, Windows NT was very early in supporting Unicode. Development of Windows NT started in 1990 where they opted for UCS-2 having 2 bytes per character and had a non-required annex on UTF-1.

UTF-1 – that later evolved into UTF-8 – did not even exist at that time. Even UCS-2 was still young: it got designed in 1989. UTF-8 was outlined late 1992 and became a standard in 1993

Some references:

–jeroen

Read the rest of this entry »

Posted in Delphi, Development, Encoding, PowerShell, PowerShell, Python, Scripting, Software Development, The Old New Thing, Unicode, UTF-16, UTF-8, Windows Development | Leave a Comment »

Delphi: Why is there no class procedure TArray.Sort(Keys: array of T; var Values: array of T; const Comparer: IComparer);

Posted by jpluimers on 2019/12/26

The underlying question at [WayBack] … Does anyone know of any array sort method similar to this for Delphi (with the two array parameters, key and value with a comparer method) … – Ugochukwu Mmaduekwe – Google+ was basically this:

Why is there no
class procedure TArray<T>.Sort(Keys: array of T; var Values: array of T; const Comparer: IComparer<T>); overload;

From my answer:

No it is not there as the method that does the actual sort does not accommodate for it:

class procedure TArray.QuickSort<T>(var Values: array of T; const Comparer: IComparer<T>; L, R: Integer);

You could write a helper for it so that similarly to C#, they all end in public static void Sort(Array keys, Array items, int index, int length, IComparer comparer)

In case you need to look at the external TrySZSort: https://github.com/dotnet/coreclr/blob/master/src/classlibnative/bcltype/arrayhelpers.cpp#L268

In other cases, C# uses an IntrospectionSort implemented at

Or you could try to use this overload of TArray.Sort Method (array of T):

class procedure Sort<T>(var Values: array of T; const Comparer: IComparer<T>); overload;

It was introduced in Delphi 2009.

Your Comparer then needs to extract the key of each element and implement IComparer<T>.

However, this will never sort the Keys array.

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Delphi 10.1.2 Berlin: after ….

Posted by jpluimers on 2019/12/25

For my archive: [WayBack] Bummer, a big showstopper with Berlin 10.1.2: an object with an indexed property getter crashes the debugger! Please +Marco Cantù we need a fix for this… – André Mussche – Google+

When debugging and adding a watch on a property:

  1. ‘Function to be called, xxxx, was eliminated by linker’
  2. ‘Assertion failure: “!e32->evalArgs.evalFCallPending”
    in ..\win32src\proc32.cpp at line 1830’

It was fixed in 10.2 Tokyo: [RSP-16522] property getters with index can’t be viewed in the debugger and crashes! – Embarcadero Technologies

–jeroen

Posted in Delphi, Delphi 10.1 Berlin (BigBen), Development, Software Development | Leave a Comment »