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

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 »

Rewritten version (free for non-commercial; small price for commercial use) GitHub – pleriche/FastMM5: FastMM is a fast replacement memory manager for Embarcadero Delphi applications that scales well across multiple threads and CPU cores, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.

Posted by jpluimers on 2020/05/05

It has been mentioned a few times already, but for my link archive: [WayBack] GitHub – pleriche/FastMM5: FastMM is a fast replacement memory manager for Embarcadero Delphi applications that scales well across multiple threads and CPU cores, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.

From the [WayBack] README.md:

Version 5 is a complete rewrite of FastMM. It is designed from the ground up to simultaneously keep the strengths and address the shortcomings of version 4.992:

  • Multithreaded scaling across multiple CPU cores is massively improved, without memory usage blowout. It can be configured to scale close to linearly for any number of CPU cores.
  • In the Fastcode memory manager benchmark tool FastMM 5 scores 15% higher than FastMM 4.992 on the single threaded benchmarks, and 30% higher on the multithreaded benchmarks. (I7-8700K CPU, EnableMMX and AssumeMultithreaded options enabled.)
  • It is fully configurable runtime. There is no need to change conditional defines and recompile to change options. (It is however backward compatible with many of the version 4 conditional defines.)
  • Debug mode uses the same debug support library as version 4 (FastMM_FullDebugMode.dll) by default, but custom stack trace routines are also supported. Call FastMM_EnterDebugMode to switch to debug mode (“FullDebugMode”) and call FastMM_ExitDebugMode to return to performance mode. Calls may be nested, in which case debug mode will be exited after the last FastMM_ExitDebugMode call.
  • Supports 8, 16, 32 or 64 byte alignment of all blocks. Call FastMM_EnterMinimumAddressAlignment to request a minimum block alignment, and FastMM_ExitMinimumAddressAlignment to rescind a prior request. Calls may be nested, in which case the coarsest alignment request will be in effect.
  • All event notifications (errors, memory leak messages, etc.) may be routed to the debugger (via OutputDebugString), a log file, the screen or any combination of the three. Messages are built using templates containing mail-merge tokens. Templates may be changed runtime to facilitate different layouts and/or translation into any language. Templates fully support Unicode, and the log file may be configured to be written in UTF-8 or UTF-16 format, with or without a BOM.
  • It may be configured runtime to favour speed, memory usage efficiency or a blend of the two via the FastMM_SetOptimizationStrategy call.

Read the rest of this entry »

Posted in Delphi, Development, FastMM, Software Development | 6 Comments »

GitHub – pyscripter/pyscripter: Pyscripter is a feature-rich but lightweight Python IDE

Posted by jpluimers on 2020/04/28

Just in case I ever need to develop Python scripts on Windows (nowadays it’s mostly on Linux/BSD based systems):[WayBack] GitHub – pyscripter/pyscripter: Pyscripter is a feature-rich but lightweight Python IDE.

If you like that, you can (also) help with this project: [WayBack] PyScripter localization Translate PyScripter into your own language.

Via: [WayBack] The PyScripter IDE, which is written in Delphi is looking for translators. We have set up a translation project on transifex.com and would be happy if s… – Lübbe Onken – Google+

–jeroen

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

Bipartite matching algorithm in Delphi… John Kouraklis – Google+

Posted by jpluimers on 2020/04/23

In the thread is an actual implementation: [WayBack] I am looking for an implementation of Bipartite matching algorithm in Delphi or Pascal. Does anyone have a suggestion? Thanks – John Kouraklis – Google+

As I probably need it one day (:

–jeroen

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

Is there no shortcut in the IDE for Quick Edit?

Posted by jpluimers on 2020/04/21

I hope this feature gets added: [WayBack] Is there no shortcut in the IDE for Quick Edit? – Reinier Sterkenburg – Google+.

The thread evolved into a few posts about failing keyboard handling (including Shift-F10) which has been failing for a long time and known to the development team for almost that time.

Hopefully things like that get fixed one day as well.

–jeroen

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

GitHub – JensBorrisholt/GoogleSpeak: This repository demonstrates how to Use Google for implementing Text to Speech. You’ll find both a Delphi version and a C# version

Posted by jpluimers on 2020/04/15

For my link archive, as I will likely need this one day: [WayBackGitHub – JensBorrisholt/GoogleSpeak: This repository demonstrates how to Use Google for implementing Text to Speech. You’ll find both a Delphi version and a C# version

–jeroen

Posted in .NET, C#, Delphi, Development, Software Development | Leave a Comment »