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

Flexible and Economical UTF-8 Decoder

Posted by jpluimers on 2019/12/25

For my link archive: [Archive.is] Flexible and Economical UTF-8 Decoder.

Be sure to read the whole article there as the explanation of the initial algorithm is important and final algorithm is towards the end.

The foundation is a state machine combined with a lookup table to find the initial state and proceed to subsequent states.

Related (and reminder to check what David did):

–jeroen

Read the rest of this entry »

Posted in C, C++, Delphi, Development, Software Development | 1 Comment »

Delphi and generics: some examples of “E2015: Operator not applicable to this operand type”

Posted by jpluimers on 2019/12/24

I don’t have enough time right now to elaborate on the code, so below is a an example of where I bumped into the very non-descriptive [WayBack/Archive.is] E2015: Operator not applicable to this operand type when using generics in Delphi.

Most have to do with comparing types (one of which is similar to comparing interfaces where you need to have a GUID in order to get an as comparison working, see Source: Delphi – Using FastMM4 part 2: TDataModule descendants exposing interfaces, or the introduction of a TInterfacedDataModule).

Like most post-Delphi 2007 language features in Delphi, generics still have rough edges. I doubt this will change anytime soon and I am not alone in this.

The documentation never got update to cover situations involving generics ([Archive.is] E2015 Operator not applicable to this operand type (Delphi) – RAD Studio), so basically this to show some examples you might bump into as well.

Note the code below usually is an indication of code-smell, as was the more elaborate situation I had to use it in. A long term solution for that code was to introduce more polymorphism.

A shorter term solution involves either the use of local variables or type-casting (for the latter, see [WayBack] delphi – Cannot compile constrained generic method – Stack Overflow)

–jeroen

Read the rest of this entry »

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

Delphi: 2 things to check when FMX/VCL units are inserted when you use VCL/FMX components

Posted by jpluimers on 2019/12/19

On G+Tom Field bumped in the [WayBack] issue that the IDE would add VCL units to the uses list when putting FMX controls on a form.

I’ve observed it the other way around as well, and there are two things you need to check:

References:

David Nottage:

It has to do with whether there’s {$R *.fmx} or {$R *.dfm} in the unit. You may be able to get away with renaming the .dfm file to .fmx, and changing the directive in the unit.

Jeroen Wiert Pluimers:

 Your .dproj file tells you what kind of application it is (FMX or VCL) in the FrameworkType element and the IDE should respond to that correctly.

–jeroen

Source: [WayBackIn the Berlin Update 2 IDE. I’m working on a multi-device app I’m creating. …

Posted in Delphi, Development, FireMonkey, OS X FMX, Software Development | 3 Comments »

IOTAProjectNotifier.Modified notifies when when Project Options have changed…

Posted by jpluimers on 2019/12/18

From: [WayBack] Is there any way using Open Tools to detect when Project Options have changed? This link from +David Hoyle covers a whole bunch of other notifications: … – David Nottage – Google+

IOTAProjectNotifier.Modified

Note a direct “IOTAProjectNotifier.Modified” – Google Search revealed nothing relevant, but a parts “IOTAProjectNotifier” “Modified” – Google Search revealed [WayBack] RadStudioVersionInsight/SvnIDENotifier.pas at master · rburgstaler/RadStudioVersionInsight · GitHub: TProjectNotifier

Further reading are these excellent blog posts:

–jeroen

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

Great quote destructors in Delphi development…

Posted by jpluimers on 2019/12/18

No destructor should ever throw an exception. If it does, there’s not really any way to recover from it anyway, so it doesn’t matter if anything leaks because of it.

Greate quote by [WayBackUser Rob Kennedy answering [WayBackinterface – Avoiding nested try…finally blocks in Delphi – Stack Overflow

It’s a basic development pattern for writing Delphi destructor code.

–jeroen

Posted in Delphi, Design Patterns, Development, Software Development | 6 Comments »

InplaceExeWrapper for those tools that do not allow specifying an output file – twm’s blog

Posted by jpluimers on 2019/12/17

In my bin directory from [WayBack] InplaceExeWrapper Project Top Page – OSDN: [WayBackInplaceExeWrapper for those tools that do not allow specifying an output file – twm’s blog:

There are a lot of command line tools that are very useful, but have one flaw: They directly modify a file in place and do not allow you to specify an output file instead.

Enter InplaceExeWrapper which called as

InplaceExeWrapper --expectfilenameonstdout c:\path\to\dprojnormalizercmd.exe input.dproj output.dproj

does the following:

  1. Create a temporary directory under %TEMP%
  2. Copy the input file input.dproj there
  3. Call the tool as dprojnormalizer tempfile.dproj
  4. Copy the modified file to the output file output.dproj
  5. Delete the temporary directory

So basically it replaces the missing functionality of specifying an output file for the tool it calls.

Here is the full help on command line parameters and options:

Synopsis: InplaceExeWrapper [options] Executable InFile [OutFile]

Parameters:
Executable        : Executable to call (if set to "copy" we only copy InFile to OutFile)
InFile            : input filename
OutFile           : output filename, defaults to infile

Options:
--CheckResult=value : If set, the executable must return the value given for this option (must be a number)
--debug           : if given, some debug output is written to error.txt in the temp directory and the temp directory will not be deleted.
--ExpectFilenameOnStdout : if set, the output of the executable must contain the filename
--help
-?
-h
-H                : display parameter help
--ShowCmdLine     : Show command line as passed to the program.
--StartupLog=value : Write a startup log to the given file.
--TempDir=value   : directory to use for temporary files (must exist)
--toStdOut        : if set, output is written to stdout and infile is not changed

Via [WayBack] There are a lot of command line tools that are very useful, but have one flaw: They directly modify a file in place and do not allow you to specify an o… – Thomas Mueller (dummzeuch) – Google+

–jeroen

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

Delphi: “Override method %s.%s should match case of ancestor %s.%s (H2365)”

Posted by jpluimers on 2019/12/17

If you write consistent code, you will never see [WayBackOverride method %s.%s should match case of ancestor %s.%s (H2365), but a long while ago I bumped into a project where some the developers had trouble using their shift key and failed to use code completion in quite a few parts of the source code.

So next a lot of lines containing things like Begin, whIle, repeaT, wrong indentations (not just at the wrong level, but even getting things indented at the same level wrong).

Code formatted like this was no exception, not even for methods bound to events:

procedure  TForm1.Button1CLick(SendeR  : TOBJect ) ;
 Begin
  Button2Click  (Sender );
end;

You cannot disable this hint individually as it is not on the list at [WayBack] Delphi XE2’s hidden hints and warnings options | Marc Durdin’s Blog, so you either have to fix the code (which I prefer), or disable all hints with {$ HINTS OFF} as per [WayBackcompiler construction – Can specific Delphi hints be disabled? – Stack Overflow (thanks Lars Truijens).

The above occasion was the first and only time I saw the hint H2365 until recently when I again bumped into a project that had grown over a long time needing some maintenance.

This reminded me I should have blogged about it, found back [Archive.is] H2365 Override method %s.%s should match case of ancestor %s.%s (Delphi) Today was the first time I have ever seen this compiler hint. Why does Delphi… – Graeme Geldenhuys – Google+ and dug a bit deeper.

Read the rest of this entry »

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

Delphi ^A syntax: Documented, implied, or undocumented? – Stack Overflow

Posted by jpluimers on 2019/12/12

The syntax is documented. In the Turbo Pasal 3 documentation, i.e. the Z80 era.

Source my answer to [WayBackDelphi ^A syntax: Documented, implied, or undocumented? – Stack Overflow (I have added some WayBack Internet Archive links below) as it is from the Turbo Pascal era where the caret was introduced to support control characters:

This is from long ago as an escape character to enable you to have consts for control characters in a more readable way.
const
  CtrlC = ^C;
begin
  Write(Ord(CtrlC));
end.

This defines a Char constant with value #3, then writes 3 in Borland Pascal 7, and I remember seeing it years before that too.

I just checked the Turbo Pascal 5.0 and Borland Pascal 7.0 languages guides, but could not find it, so it seems undocumented.

Edit: I do remember this was a Borland thing, and just [WayBack] checked: it is not part of the ISO Pascal standard (formerly this was ANSI Pascal Standard, thanks Sertac for noticing this).

It [WayBack] is documented in the Free Pascal documentation [WayBack].

SGI uses the backslash as escape character, as per their docs [WayBack].

More Edit: I found it [WayBackdocumented in Delphi in a Nutshell and the [WayBackDelphi Basics site.

Found it: Just found it on page 37 of the Turbo Pascal 3 Reference Manual [WayBack].

(Marco van de Voort found the Free Pascal documentation)

It in fact originates in the 1984 Turbo Pascal 1 edition, as per the [WayBack] Turbo_Pascal_Reference_Manual_Feb84.pdf:

Read the rest of this entry »

Posted in Borland Pascal, Delphi, Development, FreePascal, History, Pascal, Software Development, Turbo Pascal, Z80 | 1 Comment »

Exceptional Safety

Posted by jpluimers on 2019/12/11

I think I tend to forget with [WayBack] Exceptional Safety is this:

object destruction process must not cause or raise any unhandled exceptions or you will have memory leaks beyond your ability to fix them.

Particulary, that means the BeforeDestruction method – and destructors themselves – must never ever allow exceptions to escape them. Any escaping exception there will always cause memory leak. Period.

–jeroen

via [WayBack] Single or nested try…finally blocks? None will prevent the memory leak if your destructors are broken. – Dalija Prasnikar – Google+

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

Delphi/GDIPBitmap at master · tothpaul/Delphi · GitHub

Posted by jpluimers on 2019/12/11

Next time I don’t need something like TPngImage any more:

this little unit let you load any GDI+ supported graphic format (BMP, JPG, PNG or TIF) into a Delphi TBitmapit’s a TBitmap helper, so just add the unit to you’re project and call the method GDIPLoadFromStream

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

Found via: [WayBack] Let’s extend TBitmap with a GDIP loader :) TBitmap.GDIPLoadFromStream can load any GDI+ supported format (JPEG, PNG, TIFF) https://github.com/tothpaul… – Paul TOTH – Google+

–jeroen

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