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

Archive for April, 2021

Tidy First?

Posted by jpluimers on 2021/04/08

Reminder to myself to check out of the Tidy First? book by Kent Beck got out yet.

I discovered he was writing it after reading this tweet:

Like Extreme Programming, which I used before I even know about the term, Tidy First is my natural way of approaching code: step by step tidying small spots, so I get a feel on the why and how of the code. For me, tidying consists of very small refactorings. I am anxious to see what it means for Kent.

Related links:

–jeroen

Read the rest of this entry »

Posted in Uncategorized | Leave a Comment »

Delphi TestInsight: when supporting it, test if it is running at all. Same library has a deferer pattern.

Posted by jpluimers on 2021/04/08

Interesting idea by Cesar Romero (who has some interesting repositories at [WayBack] cesarliws (Cesar Romero) · GitHub and [WayBack] cesarliws — Bitbucket) when using TestInsight for Delphi: first test if TestInsight is running at all: [WayBack] foundation-4-delphi/Foundation.Test.Utils.pas at master · cesarliws/foundation-4-delphi · GitHub.

function IsTestInsightRunning: Boolean;
{$IFDEF TESTINSIGHT}
var
  TestInsightClient: ITestInsightClient;
begin
  TestInsightClient := TTestInsightRestClient.Create;
  TestInsightClient.StartedTesting(0);
  Result := not TestInsightClient.HasError;
end;
{$ELSE}
begin
  Result := False;
end;
{$ENDIF}

procedure RunRegisteredTests;
begin
  ReportMemoryLeaksOnShutdown := True;

{$IFDEF TESTINSIGHT}
  if IsTestInsightRunning then
    TestInsight.DUnit.RunRegisteredTests
  else
{$ENDIF}
    DUnitTestRunner.RunRegisteredTests;
end;

Another interesting bit from the same library is the deferer pattern (which is different from the promise pattern!)  in [WayBack] foundation-4-delphi/Foundation.System.pas at master · cesarliws/foundation-4-delphi · GitHub with the below code examples.

I think a better name might be DeferExecutionToEndOfScopeFor.

procedure ProcessFile (const FileName: string);
var
  File: TFile;
begin
  File: = TFile.Open (FileName);
  Defer (File.Close);
  while not File.EOF
  begin
    // ... process file
  end;
end; // Defer will be executed here [File.Close]

procedure ExecSql (const ConnectionString, Sql: string);
var
  Database: TDatabase;
  Exec: IDeferred;
  Query: TQuery;
begin
  Database: = TDatabase.Create (ConnectionString);
  Exec: = Defer (Database.Free);
  Database.Open;
  Exec.Defer (Database.Close);

  Query: = Database.Query (SQL);
  Exec.Defer (Query.Free);
  Exec.Defer (Query.Close);
  if Query.IsEmpty then
   Exit;

  while not Query.EOF
  begin
    // ... process query
  end;

  Exec.Defer (
    procedure
    begin
      Writeln ('Finished ExecSql');
    end
  );
end; // Defer will be executed here [Writeln, Query.Close, Database.Close, Database.Free]

–jeroen

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

Small batch file to recursively compact a directory using NTFS compression

Posted by jpluimers on 2021/04/07

compact-directory-recursively.bat:

if [%1]==[] goto :eof
call compact /s /c %1 %1\*.*

Example usage:

compact-directory-recursively.bat C:\ProgramData\{51D553F1-B483-41C2-B35E-6D461D9E0F9C}

compact-directory-recursively.bat "C:\ProgramData\Package Cache"

@for /d %d in (*.*) do @call compact-directory-recursively.bat "%d"

The @ signs are to get less output clutter.

–jeroen

Posted in Batch-Files, Development, Scripting, Software Development | Leave a Comment »

Maintaining timestamps for future dates when you know the associated location

Posted by jpluimers on 2021/04/07

For past timestamps (or date-times), as long as you know the associated location, you always know the time zone rule that applies, no matter if you store them in UTC or local time zone.

For future dates, UTC might not be the best option, as you have no knowledge on future time zone rules. There you need to have at least three fields:

Read the rest of this entry »

Posted in .NET, Algorithms, Development, Jon Skeet, Software Development | Leave a Comment »

ReturnAddressUnit to provide ReturnAddress to Delphi versions not supporting it, and prevent CallerAddr warnings for Delphi versions having ReturnAddress. See https://bitbucket.org/jeroenp/wiert.me/src/8ae6cf29ffc601fde7c1182dead740adddb13fb8/Native/Delphi/Library/RTL/ReturnAddressUnit.pas

Posted by jpluimers on 2021/04/07

From a check-in a while ago, when some Delphi versions complained about CallerAddr having been replaced by ReturnAddress and other versions not understanding ReturnAddress, but having CallerAddr.

The code in the [WayBack] gist and on [WayBack] BitBucket:

ReturnAddressUnit to provide ReturnAddress to Delphi versions not supporting it, and prevent CallerAddr warnings for Delphi versions having ReturnAddress. See https://bitbucket.org/jeroenp/wiert.me/src/…/Native/Delphi/Library/RTL/ReturnAddressUnit.pas

Basically the code maps a variable having a variable ReturnAddress that is a function reference returning a pointer to a function and redirects to CallerAddr when there is no ReturnAddress available. This is the case for anything below Delphi XE2, and avoids W1000 Symbol 'CallerAddr' is deprecated: 'Use ReturnAddress' for Delphi XE2 and up

It is an extract from [WayBack] dunit-extension/TestCaseExtension.pas at master · fabriciocolombo/dunit-extension · GitHub.

There is more interesting code in [WayBack] GitHub – fabriciocolombo/dunit-extension: Extended DUnit TestCase provides assertions to the types Date, Enumerator, Double, and other types, and a class to help run tests with output as XML, text and GUI mode and even more in [WayBack] fabriciocolombo (Fabricio Colombo) · GitHub , which are on my list of things to play with in the future.

Some more [WayBack] commits are at [WayBack] GitHub – cesarliws/dunit-extension (more on [WayBack] Cesar Romero tomorrow).

I think the code from Fabricio is inspired by [WayBack] ZeosLib/TestFrameWork.pas at master · svn2github/ZeosLib · GitHub as it uses the same HAS_BUILTIN_RETURNADDRESS define.

The code by Fabricio is smarter though.

Via: “Delphi” “CallerAddr” “ReturnAddress” – Google Search

–jeroen

Read the rest of this entry »

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

LeanEssays: What If Your Team Wrote the Code for the 737 MCAS System?

Posted by jpluimers on 2021/04/06

[WayBack] LeanEssays: What If Your Team Wrote the Code for the 737 MCAS System?.

When involved in writing systems, I always ask the question “Is a large crisis possible because of this system?”. When yes, such a system needs engineering mode, resulting much more vigorously asking questions on the things that can wrong and how to prevent anything that can go wrong.

So I wholeheartedly agree with Mary Poppendieck making these statements in the above article:

  1. One thing we knew for sure – we were responsible for designing safe systems, and we were not going to delegate that responsibility to anyone else. Another thing we knew for sure was that anything that could go wrong would eventually go wrong – so every element of our systems had to be designed to fail safely; every input to our system was suspect; and no output could be guaranteed to reach its destination. And because my seasoned engineering colleagues were suspicious of automation, they added manual (and very visible) emergency stop systems that could easily and quickly override my automated controls.
  2. would you write the code as specified, or would you ask some questions – such as “What if the stall signal is wrong, and there really isn’t a stall?” Or “Under what conditions do we NOT send an adjustment signal?” Or “When and how can the system be disabled?”

Software engineers need to understand what civil engineers learn as undergraduates – safety is not someone else’s job; it is the responsibility of every engineer involved in the design and implementation of a system whose failure might cause harm. If your team is not ready to accept this responsibility, then call yourselves developers or programmers or technicians – but not engineers.

Proper engineers can do this, even in an agile environment.

–jeroen

Via [WayBack] Mary Poppendieck on Twitter: “It was not a software malfunction that caused two 737 MAX airplanes to crash – the software did exactly what it was supposed to do. But does this mean that software engineers have no responsibility for safety? My 2 cents: …”

Read the rest of this entry »

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

msbuild verbosity is not passed to the Delphi command-line compiler any more, but for found units, you can use /p:DCC_OutputDependencies and for dfm/resource files /p:DCC_OutputDependencies

Posted by jpluimers on 2021/04/06

Last week, I wrote about msbuild verbosity levels. The post was both for my own documentation, but also out of need as I wanted to have way more verbose logging for a Delphi build process involving search path configurations.

When using my Delphi build script you can both pass msbuild options and Delphi compiler options:

Run-Dependend-rsvars-From-Path.bat 5 msbuild -verbosity:detailed "/p:DCC_OutputDependencies=true" MyProject.dproj

The bold one is the msbuild parameter, the italic one the Delphi compiler parameter for unit dependencies. They are directly passed to msbuild:

...\msbuild.exe /target:build /p:DCC_BuildAllUnits=true /p:config=Debug -verbosity:detailed "/p:DCC_OutputDependencies=true" MyProject.dproj

You can multiple options too:

Run-Dependend-rsvars-From-Path.bat 5 msbuild -verbosity:detailed "/p:DCC_OutputDependencies=true" "/p:DCC_Quiet=false" MyProject.dproj

In addition to unit dependencies, you can also get an overview of .dfm and other resource file dependencies by passing /p:DCC_OutputDRCFile=true on the command-line this will generate a DRC file that not just has all the resource string constants in it, but also a comment section specifying all resource files including these file types:

Both DCC_OutputDependencies and DCC_OutputDRCFile can also be set to true in a .dproj file and are configurable under two different project option paths:

  • DCC_OutputDependencies: “Project Options” -> “Delphi Compiler” -> “Compiling” -> “Output unit dependency information”
  • DCC_OutputDRCFile: “Project Options” -> “” -> “Delphi Compiler” -> “Linking” -> “Ouput resource string .drc file”

The -verbosity:detailed however, is not passed to the various Delphi DCC compilers, as somewhere along the line, the CodeGear.Delphi.Targets got changed to Quiet="true" somewhere in-between Delphi 2007 and Delphi 2010.

Delphi 2007 had from Borland.Delphi.Targets files containing from Quiet="$(DCC_Quiet)"; the file got renamed and changes likely in Delphi 2009. See these related posts:

This means as of then on, the DCC commandline compilers will always output non-verbose logging. Even specifying "/p:DCC_AdditionalSwitches=-Q-" will not help: you will just get blank lines.

In the past, one of the things the verbose DCC logging would help you to see which files where accessed using the actual build. This was a tremendous help when figuring out search path problems that kick in every now and then.

For units, there is a little trick you can use here: it’s the /p:DCC_OutputDependencies=true" option you see above.

It will output an additional file with the .d extension that:

  • on the first two lines are an empty line followed by lining having the the .dpr filenamea space and a backslash
  • continues with units in reverse order of dependency:
    • optional lines having two tabs, a full .dcu filename (even if the file was actually a .pas file), a space and a backslash
    • a final line having two tabs, a full .dcu filename (even if the file was actually a .pas file) but no space or backslash

That file is relatively easy to scan or parse for path problems.

Project settings

I am not sure at which Delphi version the depends feature became a project setting, but it is. The odd thing: it does not always work, at least not in the Delphi 102. Tokyo installations I have used.

In a .dproj file, it is inside this element: <DCC_OutputDependencies>true</DCC_OutputDependencies> just like the msbuild name.

In the UI, you can find it here:

Related

–jeroen

Posted in Continuous Integration, Delphi, Development, msbuild, Software Development | Leave a Comment »

Delphi TestInsight: running both DUnitX and DUnit tests in a test project

Posted by jpluimers on 2021/04/06

If you want to run both DUnitX and DUnit tests in a test project using TestInsight as runner encapsulation, then you need to be aware that when there are no DUnitX tests, it will raise an exception.

So use this code to prevent that:

    try
      TestInsight.DUnitX.RunRegisteredTests;
    finally
      TestInsight.DUnit.RunRegisteredTests;
    end;

–jeroen

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

Why I love choco-cleaner for chocolatey

Posted by jpluimers on 2021/04/05

A while ago, I wrote about Installing Windows software with Chocolatey: a few notes and A choco install list, mentioned choco-cleaner in both (see first quote below) but forgot to show where this excels.

This is what I wrote:

since there is no choco cleanup yet [WayBack] you need to either:

If you want to clean cruft:

choco install --yes choco-cleaner

It helps a lot for situations where chocolatey updates a package, but you still have the old software running. In that case, the old version will be in %ProgramData%\chocolatey\lib-bkp, potentially taking up a lot of disk space.

This happed to me for instance when still having Process Explorer open while upgrading.

This is what happened:

 ShimGen has successfully created a shim for ZoomIt.exe
This is try 1/3. Retrying after 300 milliseconds.
 Error converted to warning:
 Toegang tot het pad procexp.exe is geweigerd.
This is try 2/3. Retrying after 400 milliseconds.
 Error converted to warning:
 Toegang tot het pad procexp.exe is geweigerd.
Maximum tries of 3 reached. Throwing error.
Attempted to remove 'C:\ProgramData\chocolatey\lib-bkp\sysinternals' but had an error::
 Toegang tot het pad procexp.exe is geweigerd.
 The upgrade of sysinternals was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\sysinternals\tools'

Chocolatey upgraded 1/21 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Upgraded:
 - sysinternals v2019.3.18

C:\>C:\ProgramData\chocolatey\lib\choco-cleaner\tools\choco-cleaner-manual.bat
Choco-Cleaner.ps1 v0.0.5.2 (01/09/2019) - deletes unnecessary residual Chocolatey files to free up disk space
Copyleft 2017-2019 Bill Curran (bcurran3@yahoo.com) - free for personal and commercial use
Choco-Cleaner Summary:
  **  Deleting unnecessary Chocolatey _processed.txt (WTF?) file...
  **  Deleting unnecessary Chocolatey .ignore files...
  **  Deleting unnecessary Chocolatey .old files...
  **  Deleting unnecessary Chocolatey cache files...
  **  Deleting unnecessary Chocolatey config backup files...
  **  Deleting unnecessary Chocolatey lib-bad package files...
  **  Deleting unnecessary Chocolatey lib-bkp package files...
  **  Deleting unnecessary Chocolatey extracted file logs...
  **  Deleting unnecessary Chocolatey log files...
  **  Deleting unnecessary Chocolatey package embedded archive files in toolsDir...
  **  Deleting unnecessary Chocolatey package embedded archives and executables in .nupkg files...
  **  Deleting unnecessary Chocolatey package embedded license files...
  **  Deleting unnecessary Chocolatey package embedded Microsoft installers...
  **  Deleting unnecessary Chocolatey package embedded various read me files...
  **  Deleting unnecessary Nuget cache files...
Choco-Cleaner finished deleting unnecessary Chocolatey files and saved you 85.008 KB!
Found Choco-Cleaner.ps1 useful?
Buy me a beer at https://www.paypal.me/bcurran3donations
Become a patron at https://www.patreon.com/bcurran3

–jeroen

Posted in Chocolatey, Power User, Windows | Leave a Comment »

CP1500EPFCLCD – Backup UPS Systems | CyberPower

Posted by jpluimers on 2021/04/05

Reminder to self to write a bit more on the usage of a UPS my brother has got for a while now: CyberPower CP1500EPFCLCD which is Line-Interactive with Pure Sine Wave output.

Before buying the ESXi support seemed incredible.

Some links to start with:

 

Read the rest of this entry »

Posted in CP1500EPFCLCD, CyberPower, Hardware, Power User, UPS | 2 Comments »