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

Some links on hooking anonymous methods to Delphi events

Posted by jpluimers on 2020/06/03

On my reading list are these:

–jeroen

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

Are there any static code analysis tools for Delphi/Pascal? – Stack Overflow

Posted by jpluimers on 2020/06/02

Still interesting question: [WayBack] Are there any static code analysis tools for Delphi/Pascal? – Stack Overflow

The basic problem here is that there is no formal language definition for the Delphi or Object Pascal language.

[WayBack] GitHub – RomanYankovsky/DelphiAST: Abstract syntax tree builder for Delphi (which also supports FreePascal and Lazarus) comes closest, and is used by FixInsight.

All other tools have more or less problems parsing various language constructs.

This starts with the built-in tooling that is based on [WayBack] Modeling Applications with Together which basically has not been maintained since the Delphi 2007 era.

Then there is for instance [WayBack] Code Healer Group CodeHealer for Delphi, but their [WayBack] Code Healer Group Forums – Index page have no messages since 2016.

Another wrapper around DelphiAST, is [WayBack] GitHub – MikhailIzvekov/DelphiSCA: Static code analysis tools for Delphi, which has a visual way to walk that AST. But it has not been maintained for years. The cool thing however, is that the AST is in sync with the code editor.

Finally, TestInsight uses DelphiAST to go to the right source code location.

--jeroen

Read the rest of this entry »

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

SysUtils.pas Why parameters of these anonymous not const? TProc = …

Posted by jpluimers on 2020/06/02

At [WayBack] SysUtils.pas Why parameters of these anonymous not const? TProc = reference to procedure (Arg1: T1; Arg2: T2); TProc = reference … – Jacek Laskowski – Google+, Hallvard Vasbotn made this nail on the head comment:

It could have been solved if the const’ness had been seen as a implementation detail by the compiler (which it really is) and made const and non-const signatures assignment compatible.

It was changes like the above that I had hoped for when writing Source: 15 months later: what happened to Delphi Language Enhancements? « The Wiert Corner – irregular stream of stuff.

Now we are another 27 months later, so this again is a reminder to check what the compiler team (man?) has improved on the language side.

–jeroen

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

Need to look at monospaced programmers fonts again

Posted by jpluimers on 2020/05/27

At the time of looking, FiraCode would not work in Delphi but would in Visual Studio. Reminder for me to look at it again: [WayBack] GitHub – tonsky/FiraCode: Monospaced font with programming ligatures.

A cool feature of the font is that it has ligatures for common multi-character combinations like := or ...

Back when scheduling this, I was still at Lucida Console because of its large x-height and small line spacing.

It is time to revisit my font choice, so lets include at least these candidates:

–jeroen

related:

Edit 20200527: observations by Uwe Schuster

Posted in .NET, Delphi, Development, Font, Power User, Programmers Font, Software Development, Visual Studio 2015, Visual Studio and tools, vscode Visual Studio Code | Leave a Comment »

Why the compiler generates a `”E2018 Record, object or class type required”` on typed types…

Posted by jpluimers on 2020/05/21

From [WayBack] Why would the compiler generate a "E2018 Record, object or class type required" helper when I use a ToUpperInvariant (or any TStringsHelper call) on t… – Jeroen Wiert Pluimers – Google+:

Why would the compiler generate a "E2018 Record, object or class type required" when I use a ToUpperInvariant (or any TStringsHelper call) on the Text property of a TEdit?

Full failing code is at [WayBack] https://gist.github.com/jpluimers/b5e3684f725216622bdcb80bf5f10698

Failing line is this:

Edit1.Text := Edit1.Text.ToUpperInvariant;
// the above line generates this error:
// [dcc32 Error] MainFormUnit.pas(29): E2018 Record, object or class type required

This fails as well:

Edit1.Text := TStringHelper.ToUpperInvariant(Edit1.Text);

Why would the compiler (in this case XE8) throw this error?

Note the workaround is simple:

var
  lText: string;
begin
  lText := Edit1.Text;
  Edit1.Text := lText.ToUpperInvariant;

My suspicion is that the Edit property is of type TCaption which is type string.

Could it be that simple?

To which David Heffernan responded:

Yup, the issue is TCaption has no helper. Pretty distressing.

Typed types are indeed different types. They have been there for a long time (to facilitate generating different type information so you can for instance hook up different property editors to TCaption (a typed string) or TColor (a typed integer).

It is explained at [WayBack] Declaring Types. but has existed since Delphi 1 or Delphi 2.

More on the implications is at [WayBack] pascal – Delphi Type equivalence and Type equality syntax – Stack Overflow.

–jeroen

Read the rest of this entry »

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

GitHub – NickRing/Delphi-Shortcut-Finder: Shows/find keyboard short-cuts have be assigned, that may be conflicting.

Posted by jpluimers on 2020/05/20

Reminder to self to eventually try to merge this into GExperts: [WayBackGitHub – NickRing/Delphi-Shortcut-Finder: Shows/find keyboard short-cuts have be assigned, that may be conflicting.

And a reminder to ensure if I ever bump into XE7 again, I need to ensure it is at least update 1: Source: QualityCentral Report # 127616: registry key has incorrect value, 20 should be 21.

–jeroen

via: [WayBack] I need some help from anyone who knows RTTI better than me. I’m writing an OTA tool to list all the actions or keybindings that are associated with a s… – David Hoyle – Google+

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

delphi – always pass SEM_FAILCRITICALERRORS to SafeLoadLibrary

Posted by jpluimers on 2020/05/19

The below is based on [WayBackdelphi – Is there any way to catch the error if loading a dll cannot find a dependency? – Stack Overflow which I got via:

The problem is that the [WayBack] SysUtils.SafeLoadLibrary Function (present since at least Delphi 2007, and a wrapper around the [WayBack] LoadLibrary function (Windows)) does many good things – maybe even too many – so you need to take all of them into account:

function SafeLoadLibrary(const FileName: string; ErrorMode: UINT = SEM_NOOPENFILEERRORBOX): HMODULE;
  1. SafeLoadLibrary loads a Windows DLL or Linux shared object file, as specified by Filename.
  2. SafeLoadLibrary preserves the current FPU control word, preventing library initialization code from permanently overwriting precision and exception masks.
  3. Note:
    • On Windows, SafeLoadLibrary temporarily sets the system error mode to ErrorMode. The default, SEM_NOOPENFILEERRORBOX, suppresses error dialogs. The previous error mode is restored before SafeLoadLibrary exits. For a list of error modes, refer to [Wayback1/Wayback2] SetErrorMode in the Microsoft documentation.
    • Note: On Linux, the Dummy argument is ignored.

Most important tips

Do not ever pass 0 (the number zero) as ErrorMode; I’ve seen lots of applications just passing zero for parameters they are not sure about, but in this case it is the worst solution as it will show all errors as a popup.

Do not forget a parameter either: the default value SEM_NOOPENFILEERRORBOX will only suppress a message box when it fails to find a file. But it will fail to enable SEM_FAILCRITICALERRORS which is what you really want.

Loading DLLs from resources

LoadLibrary and SafeLoadLibrary load the DLL from a file. But what if you want to load it from a resource?

Then this post from Thomas Mueller applies: he adopted the SafeLoadLibrary logic to load from a resource:

Other thoughts to keep in mind

The way Delphi sets the FPU control word is not thread safe: QualityCentral Report # 106943: Set8087CW/SetMXCSR are not thread-safe (you could work around in your implementation by using thread safe versions like mentioned in [WayBack] FastMM / Discussion / Open Discussion:Call to GetStackTrace changes 8087CW).

Calling SetErrorMode sets a global application wide setting (by default including all threads) of error code, so it is better to either:

  • decide for your whole application up front which error mode to use, save it and use the same value everywhere:

Because the error mode is set for the entire process, you must ensure that multi-threaded applications do not set different error-mode flags. Doing so can lead to inconsistent error handling.

Second, SEM_FAILCRITICALERRORS prevents an error to pop up when dependencies of the loaded file are not available. You might want to combine (bitwise or) it with other values like SEM_NOGPFAULTERRORBOX.

ErrorMode values

There are many more modes you can pass to the [WayBack] SetErrorMode function (Windows):

  • Value Meaning
    0
    Use the system default, which is to display all error dialog boxes.
     

    SEM_FAILCRITICALERRORS
    0x0001
    The system does not display the critical-error-handler message box. Instead, the system sends the error to the calling process.

    Best practice is that all applications call the process-wide SetErrorMode function with a parameter of SEM_FAILCRITICALERRORS at startup. This is to prevent error mode dialogs from hanging the application.

     

    SEM_NOALIGNMENTFAULTEXCEPT
    0x0004
    The system automatically fixes memory alignment faults and makes them invisible to the application. It does this for the calling process and any descendant processes. This feature is only supported by certain processor architectures. For more information, see the Remarks section.

    After this value is set for a process, subsequent attempts to clear the value are ignored.

     

    SEM_NOGPFAULTERRORBOX
    0x0002
    The system does not display the Windows Error Reporting dialog.
     

    SEM_NOOPENFILEERRORBOX
    0x8000
    The OpenFile function does not display a message box when it fails to find a file. Instead, the error is returned to the caller. This error mode overrides the OF_PROMPT flag.

–jeroen

all via:

Related:

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

Delphi 2007 – move from signature in interface to signature in implementation section

Posted by jpluimers on 2020/05/14

I always thought this was the Ctrl+Shift+Up / Ctrl+Shift+Down in ModelMaker Code Explorer, but it is not: the CnPack navigation is the one that comes most close:

[WayBack] Is there a way in the editor to move from the interface section declaration of a method to its implementation (signature)?… – Bill Meyer – Google+

–jeroen

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

Updating Actions (Don’t Do This) – Dave’s Development Blog

Posted by jpluimers on 2020/05/13

I remember fixing a high CPU toggling the Enabled property in an OnUpdate even handler on a TCustomAction descendant quite some time ago, but wasn’t completely sure of the exact cause.

My fix was to only set it once every clock tick (about every 20 milliseconds).

The best fix would have been not to toggle at all: just calculate the right result, then only set the Enabled property once: [WayBack] Updating Actions (Don’t Do This) – Dave’s Development Blog

–jeroen

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

“cushion treemap” delphi – Google Search

Posted by jpluimers on 2020/05/06

For my link archive below a few links from “cushion treemap” delphi – Google Search.

The reason: I like Sequoiaview a lot, but it has a few issues (of which I wrote in SequoiaView Homepage) and lacks a few things too.

WinDirStat is nice, but could be a lot cleaner. Both lack one feature I’d love to have: light-weight automatic updating on NTFS volumes.

Everything does the latter, but does not do graphical output as it is focused on being a blindingly fast indexing and searching tool (I like it a lot so there is even a category on my blog for it: Everything by VoidTools).

It would be cool if both could be hooked together, which would require a cushion treemap in Delphi and an API to access the Everything database.

So here are links that might help with the first:

–jeroen

 

 

Posted in Delphi, Development, Everything by VoidTools, Power User, Software Development, Windows | Leave a Comment »