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

Delphi sorcery: Loop wars – measuring performance

Posted by jpluimers on 2018/11/21

Interesting read: [WayBack] Delphi sorcery: Loop wars – measuring performance.

It is on optimisation of for…in constructs. More comments at [WayBack] Since there was this offtopic argument going on about performance of for-in versus for-to. – Stefan Glienke – Google+, including penalties for TStrings, string handling and inline methods.

–jeroen

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

Reminder to Self: check if NameOf has been implemented yet

Posted by jpluimers on 2018/11/20

It’s been a wish for a very very long time: to get the name of an identifier as a string in Delphi:

For now the best one can do is either using an Assert and catching the exception (it gets you the unit name, source file name and source line number) in the links below, or using debug symbol information (like a MAP or TDS file) mentioned in the StackOverflow questions above.

C# has had a  [WayBack] nameof for many years now that is evaluated at compile time: [WayBackc# – Is nameof() evaluated at compile-time? – Stack Overflow.

There is a request RAD Studio – RSP-13290: NameOf(T) compiler (magic) function in Quality Portal by Horácio Filho about 3 years ago quotes below.

Since it took the C# team about 3 years after the original [WayBackAdd nameof operator in C# – Visual Studio request, I wonder how fast the Delphi team is.

NameOf .NET-like compiler magic (intrinsic) function would eliminate a lot of hand-written exception messages from several units.

C# 6 introduced nameof operator to obtain the simple (unqualified) string name of a variable, type, or member.

With the current Delphi implementation, after changing variables name we have ot change the related exception message as well. Putting variables name in the code is not a good practise, and is here that NameOf taking place saving tons of lines of code. As the result of NameOf(T) function (if so) is evaluated at compile time (according to the C# implementation – http://stackoverflow.com/a/26573179) we need a help from compiler or it could be achieved using RTTI.

There is a discussion on Google+ community [WayBackhttps://plus.google.com/+StefanGlienke/posts/AsGHSLF4rTX.
The function could be designed as
NameOf(x: Identifier)
following the same (or similar) warranties C# provides.

Using Assert:

–jeroen

Read the rest of this entry »

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

Solution for Delphi – post-build event with multiple if/copy combinations only execute if first file does not exist – Stack Overflow

Posted by jpluimers on 2018/11/15

My solution in [WayBack] delphi – post-build event with multiple if/copy combinations only execute if first file does not exist – Stack Overflow is an addendum to my 2014 post Delphi prebuild/prelink/postbuild events.

Here we go:

Read the rest of this entry »

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

Andreas on Twitter:

Posted by jpluimers on 2018/11/13

Cool: I never knew the Delphi debugger’s expression understood more than just expressions: compiler directives too!

[WayBack@AndyHTech on Twitter:

The debugger’s expression evaluator can’t access an PInteger like an array because PInteger wasn’t declared with $POINTERMATH ON. But if you write “{$POINTERMATH ON} MyIntPtr[0]” into the evaluator the array access works. POINTERMATH ON should always be on in the expr evaluator.
… and if you did this, the option stays active until the compiler has to compile a project, the it is reset.

–jeroen

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

Delphi 10.1 Berlin Update 1 exit error · GitHub

Posted by jpluimers on 2018/11/13

Reminder to self: check this when it re-occurs [WayBack] Delphi 10.1 Berlin Update 1 exit error · GitHub.

there is an Invalid pointer operation. inside System.TObject.FreeInstance with a stack trace involving multiple rounds of

[50BE9CC9]{vcl240.bpl  } Vcl.Forms.TCustomForm.CloseQuery (Line 7061, "Vcl.Forms.pas" + 8) + $14
[5393DDD4]{DDevExtensionsD101.dll} DSUFeatures.CloseForm + $28
[5393DEA2]{DDevExtensionsD101.dll} DSUFeatures.HookedTCustomFormClose + $42
[50BE8A80]{vcl240.bpl  } Vcl.Forms.TCustomForm.WMClose (Line 6398, "Vcl.Forms.pas" + 0) + $0
[50AA3B32]{vcl240.bpl  } Vcl.Controls.TControl.WndProc (Line 7313, "Vcl.Controls.pas" + 91) + $6
[1ACC4D50]{tmsdXE10.bpl} Advgrid. + $0

–jeroen

Read the rest of this entry »

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

Reminder to self: check if David Nottage published source code the Firebase application analytics

Posted by jpluimers on 2018/11/13

I need to check the outcome of this comment at [WayBack] Google analytics is no more avaliable for analytic Apps and send to firebase when you want to track a new App. How to do with firebase analytics? there … – Xavi P. – Google+:

I’m working on an implementation. It’ll be an extension of what I did with Firebase Cloud Messaging:

[WayBackAdding Firebase Cloud Messaging to your mobile apps – part 1 – Delphi Worlds

However, my implementation may or may not become a part of a commercial solution that includes other Firebase services, including Firebase Database, using the Android and iOS SDKs

–jeroen

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

Reminder to self: make a start for an XSD that validates Delphi dproj files

Posted by jpluimers on 2018/11/07

Below are a few interesting things from this thread [WayBack] Any idea why Delphi (At least since Seattle) does this to Dproj filesand… – Tommi Prami – Google+.

It’s likely that the WordPress system deleted parts between angle brackets because it thinks it’s invalid HTML and WordPress is PHP.

Anyhow: maybe by now I’ve found time for creating an XSD for .dproj files in addition to the one I mentioned yesterday for the .groupproj files: Validating a nested XML element with an empty namespace using XSD – Stack Overflow.

Oh and in the mean time for various Delphi versions, there is a (binary, because it uses some commercially licensed parts) [WayBackDproj changed or not changed? Normalize it! | The Art of Delphi Programming.

Files and directories I need to research:

In the mean time, QualityPortal indicates that:

Achim Kalwa:
That is a long living bug: https://quality.embarcadero.com/browse/RSP-11308
Still exists in Berlin Update 2.

Jeroen Wiert Pluimers
For more than a decade, the IDE rewriting dproj files in different order/indentation/spacing, properties appearing/disappearing in DFM files and writing DFM files despite no changes have driven me even more nuts than I was.

Walter Prins
+Jeroen Wiert Pluimers Yes. Given that .dproj is XML I’ve been almost annoyed enough to look at making some kind of pre-checkin script to force sort things to try and avoid the issue. Almost… Edit: Ah, just checked that RSP, which references this: https://github.com/joshkel/RadCli Seems someone has already done it.

Lübbe Onken
Did you try tidy_proj +Walter Prins? For me it fails with a “Unicode Encode Error” when I try to write an output file. In my case this is caused by German umlauts in the excluded bpl section descriptions. Changing the umlauts to something low-ascii allows tidy_proj to finish.

Walter Prins
+Lübbe Onken No, but I have just done so. Unicode bites again. To fix that error, change line 125 from:

print(proj.toxml())

to:

print(proj.toxml().encode(‘utf-8’))

Note: This will likely not display correctly if you allow the output to go to the console but will ensure it is correct if redirected back to file.

Edit: Ha, I was about to go report this issue ad suggest this fix, but I see you’ve already suggested essentially the same fix. ;)

Jeroen Wiert Pluimers’s profile photo
Jeroen Wiert Pluimers
+Walter Prins interesting tool! Do you know of a tool that can downgrade .dproj files so you can use them with older Delphi versions? (the opposite of what the IDE does)?

Or someone that has written more than my XSD on .dproj files? My one is so small that’s hardly a real attempt. https://wiert.me/2013/08/31/delphi-first-try-on-an-xsd-for-groupproj-files/

Walter Prins
+Jeroen Wiert Pluimers No, but interesting idea. I suppose you’re probably aware that the JEDI JCL/JVCL takes a somewhat similar (ish) related approach, in that it generates project and package files that are compatible with every desired version of Delphi from minimalist (XML) template files. Every so often I think it might be worth looking whether one can re-use the code from there easily but haven’t gotten around to it. Always something else to do first. :/

Jeroen Wiert Pluimers
+Walter Prins no I didn’t. Where should I start reading on that minimalist template approach?

Walter Prins
+Jeroen Wiert Pluimers Sorry I see I missed out the word installer in my comment: It’s the Jedi JCL/JVCL installers that uses xml templates etc.

But the point stands: I guess it should be (perhaps) possible to reuse its infrastructure for ones own projects, though as I say I keep meaning to look into this but haven’t really done so.

(BTW I’m assuming you are familiar with the JCL/JVCL and in in particular their installers that bootstrap from source code? If not then perhaps my comments may not be that useful?)

Anyway, not sure if or where there’s particular documentation about this (kind of doubt it), but if you have the JCL/JVCL installed somewhere, then first of all have a look at the “xml” folders e.g. “<jclroot>\jcl\packages\xmls” and “<jvclroot>\jvcl\packages\xml”.

These files appear to define projects and packages in a seemingly abstract/somewhat minimal way using XML. This seemingly is then used to automatically produce .dproj and .dpk files which are placed in e.g. “<jclroot>\jcl\packages\dXX” and “<jvclroot>\jvcl\packages\dXX” where dXX corresponds to a folder for each of the supported Delphi versions and compiled/used during installation.

Having just looked into this briefly a bit further as a result of this conversation: Key units here (in the case of JVCL) seems to be “<jvclroot>\devtools\PackagesGenerator\PackageGenerator.pas”, “<jvclroot>\install\JVCLInstall\PackageUtils.pas” and “<jvclroot>\devtools\common\PackageInformation.pas” (used predictably by <jvclroot>\JVCLInstall.dproj)

(Additionally, having looked at this a bit more closely, it also appears that the JCL does not actually replace all or even most of its .dproj and .dpk files after all, but ships version specific .dproj and .dpk files in most cases, though the JVCL does appear to mostly do so. )

Edit: The JCL also has this interesting sounding unit “jclroot>\source\windows\JclMsBuild.pas” which appears to be an MSBuild project file parser…

–jeroen

Posted in Conference Topics, Conferences, Continuous Integration, Delphi, Development, Event, msbuild, Software Development, XML, XML/XSD, XSD | Leave a Comment »

Delphi: updating a (potentially non-existing) item in a generic TDictionary: use ExtractPair. Except in Delphi 2010/XE.

Posted by jpluimers on 2018/11/06

“Documented” in Delphi 2010, [Archive.is] Generics.Collections.TDictionary.ExtractPair – RAD Studio VCL Reference, and functioning bug-free since Delphi XE2, but still hardly documented, [Archive.is] System.Generics.Collections.TDictionary.ExtractPair – XE2 API Documentation is the easiest way to get a value out of a dictionary and updating it, even if it does not exist.

ExtractPair extracts the TPair<TKey, TValue> if it exists (and removes it from the dictionary) or returns a Default initialised one if not. Though Default is still not documented, you can find an example at [WayBack] How to properly free records that contain various types in Delphi at once? – Stack Overflow.

Example code for ExtractPair:

  FEceptionDictionary := TDictionary<TExceptionKey, Integer>.Create();

...

var
  ExceptionCountPair: TPair<TExceptionKey,Integer>;
begin
  TMonitor.Enter(FEceptionDictionary);
  try
    ExceptionCountPair := FEceptionDictionary.ExtractPair(ExceptObj.ClassType); // extracts and removed from dictionary!
    FEceptionDictionary.Add(ExceptionCountPair.Key, ExceptionCountPair.Value + 1); // use Value as count
  finally
    TMonitor.Exit(FEceptionDictionary);
  end;
end;

In Delphi 2010 and XE it was buggy (see [WayBack] QualityCentral 80947: TDictionary.ExtractPair Fails and creates memory leak via [WayBack] generics – Delphi TPair Exception – Stack Overflow), but since then it works fine, and now is properly documented:

[WayBack] System.Generics.Collections.TDictionary.ExtractPair – RAD Studio API Documentation

Returns the TPair<TKey,TValue> pair with the specified Key and [WayBackremoves the returned pair from a dictionary.

If the dictionary does not contain the specified Key, the returned pair contains a default TValue.

–jeroen

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

Validating a nested XML element with an empty namespace using XSD – Stack Overflow

Posted by jpluimers on 2018/11/06

In a quest for making Delphi Group Project XML files (with extension .groupproj) validate with XSD, I had to find out about [WayBackValidating a nested XML element with an empty namespace using XSD – Stack Overflow.

I needed the XSD so I could import it in Delphi in order to write a good .groupproj file generator.

They are here:

And some more background posts are here:

–jeren

Posted in Delphi, Development, Software Development, XML, XML/XSD, XSD | 1 Comment »

Delphi: create implementations in the same order as the interface section and sync method signatures

Posted by jpluimers on 2018/10/30

An interesting question at [WayBack] Previously i have not been big on IDE plugins.So i’m blatantly asking for pointers on the following, i.e. is there already such beasts? Or maybe i’m i… – Dany Marmur – Google+:

… asking for pointers on the following…

Crtl+C – create implementations in the same order as the interface section?
Ctrl+C – adjust the signature of the method the cursor is on interface if implementation and vice versa.

I realise they can both be very tricky to implement. Second function might not be able to handle overloads.

From that thread, a few things you might want to try:

  • [WayBack] ModelMaker Code Explorer can do both.
  • [Archive.is] DDevExtensions version 2.82 (2014-08-25): introduced “Added: Disable Alpha-Sort Class Completion (Default off)”
  • More recent versions of the IDE (I think 10.0) incorporated the “sync prototypes” action (Shift+Ctrl+Alt+P) from Castalia.

–jeroen

 

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