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, SHA-3 and streaming

Posted by jpluimers on 2019/08/15

If I ever need to use SHA-3 in Delphi: [WayBack] Does anyone know of any implementations of SHA-3, that can support TStream? – Nicholas Ring – Google+

The comments have a nice list of libraries supporting SHA-3, and how to do streaming hashing.

–jeroen

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

QualityCentral 56524: tanh function from Delphi 7 till Delphi XE was buggy; XE2 fixed it

Posted by jpluimers on 2019/08/13

In case you maintain code in older versions of Delphi, be aware that the function tanh was broken starting in Delphi 7 and only got fixed in Delphi XE2: QualityCentral QualityCentral 56524: tanh function from Delphi 7 till Delphi XE was buggy; XE2 fixed it.

For big inputs, it would just fail, instead of returning 1.

The reason is that in the buggy versions, tanh got replaced from an old working version into a simple sinh/cosh, which mathematically is correct, but if your numeric data type has limited accuracy, you need to account for the boundaries where the result fits, but intermediates do not.

the [WayBack] Math.Tanh Function implements the hyperbolic tangent, for which you can find the definition at Hyperbolic function – Wikipedia: Definitions.

By now it is implemented for all floating point types the same way (only the parameter type changes in each implementation)

function Tanh(const X: Extended): Extended; overload;
const
  MaxTanhDomain = 23;
  C1of3 = 1/3;
  CBorder = 1.8145860519450699870567321328132e-5; // 2 ^(-63 / 4)
  CLn2Div2 = 0.34657359027997265470861606072909; // Ln2 / 2
var
  y, z: Extended;
begin
  FClearExcept;
  case TExtendedRec(X).SpecialType of
    fsPositive,
    fsNegative:
      begin
        z := X;
        if X < 0 then z := -z;
        if (z > MaxTanhDomain) then
          Result := 1.0
        else if (z < CBorder) then
          Result := z  - z * z * z * c1of3
        else if (z < CLn2Div2) then
        begin
          y := ExpMinus1(2*z);
          Result := y / (2 + y);
        end
        else
        begin
          y := Exp(2*z);
          Result := 1 - (2/(y + 1));
        end;
        if X < 0 then Result := -Result;
      end;
    else
      Result := X;
  end;
  FCheckExcept;
end;

–jeroen

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

NativeInt / NativeUInt type in various Delphi versions – twm’s blog

Posted by jpluimers on 2019/08/08

Reminder to Self (and note that Delphi <= 2007 does not reference NativeInt/NativeUInt in System.pas): [WayBack] NativeInt / NativeUInt type in various Delphi versions – twm’s blog

Just in case you are maintaining Delphi code for several older versions of Delphi: Be aware that the declarations of NativeInt and NativeUInt are wrong in some of them.

Delphi version SizeOf(Native(U)Int) Win32 SizeOf(Native(U)Int) Win64
1 to 6 not available not available
7 to 2007
8 ← this is wrong
not available
2009 to XE 4 not available
XE2 to XE8 4 8
10.x 4 8

Relevant GExperts commit: [WayBack] GExperts / Code / Commit [r2399]

Via  [WayBack] Just in case you are maintaining Delphi code for several older versions of Delphi: Be aware that the declarations of NativeInt and NativeUInt are wrong … – Thomas Mueller (dummzeuch) – Google+

–jeroen

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

Using PE Flags in Delphi – twm’s blog

Posted by jpluimers on 2019/08/08

For my link archive: [WayBackUsing PE Flags in Delphi – twm’s blog with information about and links to:

The flags themselves are documented at [WayBack] IMAGE_FILE_HEADER structure (Windows)

–jeroen

Via: [WayBack] There was a discussion about using the PE flag IMAGE_FILE_LARGE_ADDRESS_AWARE… – Thomas Mueller (dummzeuch) – Google+

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

More on new .NET path handling – Jeremy Kuhne’s Blog

Posted by jpluimers on 2019/08/07

When it was at the age natural people are allowed to drive in the USA, the .NET framework behaved far less brain dead handling various (especially long or strange) paths: [WayBackMore on new .NET path handling – Jeremy Kuhne’s Blog.

Path handling has frustrated me in many development environments, so I wonder if ones that are beyond the (USA) legal age of drinking follow.

–jeroen

via: [WayBack] Some time ago, the .net developers finally saw sense and removed path normalization and long path limit code in System.IO… Does anybody know if Embarcadero have come to their senses… – David Heffernan – Google+

Posted in .NET, Delphi, Development, Java, Java Platform, Software Development | Leave a Comment »

GitHub – Purik/AIO: Coroutine-based multithreading library for Delphi

Posted by jpluimers on 2019/08/06

On my list of things to try: [WayBack] GitHub – Purik/AIO: Coroutine-based multithreading library for Delphi which are similar to what golang does.

Coroutine-based multithreading library for Delphi. Contribute to Purik/AIO development by creating an account on GitHub.

Via [WayBack] What you think about coroutine-based multithreading concurrency in Delphi like GoLang https://github.com/Purik/AIO Probably evolution paths, actuality… – Павел Миненков – Google+

–jeroen

Posted in Delphi, Development, Go (golang), Software Development | Leave a Comment »

Delphi XE2: IDE out of memory problem? Check the library path length

Posted by jpluimers on 2019/08/06

Curious, but somehow shortening the library path solved the problem Alberto had: [WayBack] Hello Everybody, I have an application developed in XE2 (Hot Fix 2 + IDE Fix Pack installed) that has started giving me the “out of memory” error message… – Alberto Paganini – Google+:

Alberto Paganini

It turned out the length of the library path was the culprit of the IDE out of memory error messages.
I have reduced the length of the library path and the error messages have reduced dramatically.
There are still a few out of memory messages tho.

–jeroen

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

New in 10.2.2: Component icons – Community Blogs – Embarcadero Community

Posted by jpluimers on 2019/07/31

A well balanced post that shows what you can attain by thinking in advance and remembering backward compatibility: [WayBack] New in 10.2.2: Component icons – Community Blogs – Embarcadero Community

Larger icons can now be in PNG format (future IDE versions will use 128×128 for HiDPI screens) so older IDE versions do not get confused. Since newer IDE versions prefer PNG over BMP icons, backward compatibility is easier.

Via: [WayBack] A look at the new component icons in 10.2.2.  – David Millington – Google+

–jeroen

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

It’s a blong, blong, blong road…: ‘What if?’ scenario analysis in the CPU window

Posted by jpluimers on 2019/07/31

Patching code at debug-time: [WayBackIt’s a blong, blong, blong road…: ‘What if?’ scenario analysis in the CPU window.

Remember:

  • There are dragons
  • Patching too many bytes will kill a kitten and likely your application.
  • Bytes in memory might not be what they seem, especially when having breakpoints (and the debugger frantically trying to set/remove $CC bytes for the INT 3 instruction)

I’ve done this for 20+ years and usually use the $90 byte (NOP instruction) though your experience may be different.

–jeroen

 

Posted in Debugging, Delphi, Development, Pascal, Software Development, Turbo Pascal | Leave a Comment »

Sometimes a race condition is in just two lines of code

Posted by jpluimers on 2019/07/30

A race condition can be this small:

if Assigned(Setting.OnChanged) then
  Setting.OnChanged(Setting);

If in between these lines, the value of Setting.OnChanged becomes nil, then you have an access violation.

It is a very slim, but real chance.

–jeroen

Posted in Delphi, Development, Multi-Threading / Concurrency, Software Development | 4 Comments »