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 the ‘Delphi’ Category

delphi – Is AtomicCmpExchange reliable on all platforms? – Stack Overflow

Posted by jpluimers on 2017/09/19

TL;DR: yes it is.

Answer by Allen Bauer at delphi – Is AtomicCmpExchange reliable on all platforms? – Stack Overflow [WayBack]

On Windows, it directly translates into lock cmpxchg which is way faster than the Windows API call [WayBackInterlockedCompareExchange, as that is a jump to the actual code:

InterlockedCompareExchange:
00417CA8 FF2528E12901     jmp dword ptr [$0129e128]
KERNEL32.InterlockedCompareExchange:
75855E40 8BFF             mov edi,edi
75855E42 55               push ebp
75855E43 8BEC             mov ebp,esp
75855E45 8B550C           mov edx,[ebp+$0c]
75855E48 8B4D08           mov ecx,[ebp+$08]
75855E4B 8B4510           mov eax,[ebp+$10]
75855E4E F00FB111         lock cmpxchg [ecx],edx
75855E52 5D               pop ebp
75855E53 C20C00           ret $000c

whereas AtomicCmdExchange looks like this:

Test.pas.20: RestoreValue := AtomicCmpExchange(FieldToBeModfied, 1 {new value}, 0 {expected value}, Success {true if the expected value was found, and new value set});
0111A838 8B45FC           mov eax,[ebp-$04]
0111A83B 8D500C           lea edx,[eax+$0c]
0111A83E 33C0             xor eax,eax
0111A840 B901000000       mov ecx,$00000001
0111A845 F00FB10A         lock cmpxchg [edx],ecx
0111A849 0F9445F2         setz byte ptr [ebp-$0e]
0111A84D 8945D8           mov [ebp-$28],eax

–jeroen

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

Checking KeyPress is not the place to do your input validation

Posted by jpluimers on 2017/09/19

I have seen too many projects over the years trying to do input validation by checking KeyPress. This is not limited to Delphi projects (C#, VB and other projects suffer from this just as much). Most of these projects suffer from these::

  • Much of the KeyPress logic logic in the UI byusing half-baked copy-pasted code fragments.
  • They all fail missing important functionality (like paste, clear, Ctrl-key handling and such) either supporting or suppressing that functionality where needed

If doing Delphi, then that code should be rewritten in a generic way based on examples like like these:

–jeroen

Read the rest of this entry »

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

Delphi code of the day…

Posted by jpluimers on 2017/09/11

I was debugging an issue where a Delphi SOAP implementation was shoe-horned into an Indy server and came across the [WayBackTWebRequest.UpdateMethodType Method.

The further you get down the if/then/else tree, the more often the indexed property Method is accessed, same for the conversion/comparison code.

property Method: string index 0 read GetStringVariable;

So if the HTTP method is POST (very common), then the calls are being made 3 times:

procedure TWebRequest.UpdateMethodType;
begin
{$IFDEF NEXTGEN}
  if Method = 'GET' then  { do not localize }
    FMethodType := mtGet
  else if Method = 'PUT' then   { do not localize }
    FMethodType := mtPut
  else if Method = 'POST' then  { do not localize }
    FMethodType := mtPost
  else if Method = 'HEAD' then  { do not localize }
    FMethodType := mtHead
  else if Method = 'DELETE' then  { do not localize }
    FMethodType := mtDelete
  else if Method = 'PATCH' then  { do not localize }
    FMethodType := mtPatch;
{$ELSE !NEXTGEN}
  if System.AnsiStrings.AnsiStrComp(PAnsiChar(Method), 'GET') = 0 then  { do not localize }
    FMethodType := mtGet
  else if System.AnsiStrings.AnsiStrComp(PAnsiChar(Method), 'PUT') = 0 then   { do not localize }
    FMethodType := mtPut
  else if System.AnsiStrings.AnsiStrComp(PAnsiChar(Method), 'POST') = 0 then  { do not localize }
    FMethodType := mtPost
  else if System.AnsiStrings.AnsiStrComp(PAnsiChar(Method), 'HEAD') = 0 then  { do not localize }
    FMethodType := mtHead
  else if System.AnsiStrings.AnsiStrComp(PAnsiChar(Method), 'DELETE') = 0 then  { do not localize }
    FMethodType := mtDelete
  else if System.AnsiStrings.AnsiStrComp(PAnsiChar(Method), 'PATCH') = 0 then  { do not localize }
    FMethodType := mtPatch;
{$ENDIF NEXTGEN}
end;

–jeroen

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | 4 Comments »

Delphi analog to C# ?? null-coalescing operator and Light Table like debugger evaluation

Posted by jpluimers on 2017/09/05

Interesting stuff:

via:

In more detail:

Read the rest of this entry »

Posted in Conference Topics, Conferences, Delphi, Development, Event, Software Development | 3 Comments »

Windows – WorldTransform on the Printer’s Canvas can be a challenge…

Posted by jpluimers on 2017/09/05

// Don't use SetWorldTransform [WayBack] on Printer.
// Some drivers don't handle it correct
// We will only use ModifyWorldTransform [WayBack]
// Let Windows and Driver do the Job

Source: Hello, I use a component that do some nice things on the Printer’s Canvas…… [WayBack]

–jeroen

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

Delphi code completion but more relaxed

Posted by jpluimers on 2017/08/31

From my link archive:

Both via I remember someone in this group showed a prototype of a ‘code-completion’ replacement IDE expert, which supports fuzzy matching of method names you typed [WayBack]

If I remember correctly, the Kibitz compiler started to expose less functionality around the Delphi 7 or Galileo era rendering many of the GExperts additions useless. Not sure about the current state of that now.

–jeroen

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

Delphi TGridPanel – how to get all SizeStyle=ssPercent cells to get the same auto-calculated Value – via StackOverflow

Posted by jpluimers on 2017/08/31

If you want to set all columns to the same value, select all columns in the structure view and then (assuming SizeStyle [WayBack] is already set to ssPercent [WayBack]) set the Value [WayBack] to 0. This will trigger some automatism that makes all of the columns sized equal.

Great answer by Uwe Raabe [WayBack]

Source: Delphi How to use TGridPanel – Stack Overflow [WayBack]

–jeroen

Posted in Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

More beautiful code by Asbjørn Heid

Posted by jpluimers on 2017/08/25

If you’re in Delphi land, then Asbjørn Heid is a a guy to follow on G+.

He has some brilliant snippets (most can be found on paste.ie by searching for Asbjørn Delphi site:paste.ie).

This is actually one set:

Both via From the because-I-can department… Friday evening operator abuse. Tuple Duple [WayBack]

Then there are these:

–jeroen

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

Some links on Belise/Elise licensing server (yes, AppWave is dead or at least: should be)

Posted by jpluimers on 2017/08/15

Some links on the Embarcadero License Center server (formerly known as Belise and Elise) from my contributions to these G+ threads:

When for instance your workstations cannot communicate to the external license servers or you want to run concurrent Delphi/C++-Builder/RAD-Studio instances on your local network, you need to run the Elise licensing server on your network, which requires you to have a server with Java running somewhere.

URL Title
http://docwiki.embarcadero.com/ELC/en/Obtaining_License_Files [WayBackObtaining License Files – ELC
http://docwiki.embarcadero.com/ELC/en/Installing_the_Embarcadero_License_Center [WayBackInstalling the Embarcadero License Center – ELC
http://support.codegear.com/article/43557 [WayBackDelphi, C++Builder, RAD Studio XE5 Update 2 install for network licenses
http://license.embarcadero.com/lservers/elise.jsp [WayBackEmbarcadero License Center Setup
http://support.codegear.com/article/36588 [WayBackEmbarcadero License Server overview
http://support.codegear.com/license [WayBackLicense Server
https://docs.bmc.com/docs/display/Configipedia/Borland+License+Server [WayBackBorland License Server – Configipedia – BMC Documentation
http://borland.public.jbuilder.enterprise.narkive.com/dk5UBkGc/borland-license-server-instalation [WayBackBorland License Server Instalation

Despite some of the documentation, it runs on more recent Windows versions too.

Not sure about the money: it’s just that a few clients of mine use it as it makes it easier to manage licenses when you switch contractors or not having various team members only use Delphi part of the time.

Read the rest of this entry »

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

Experiments in Uniform Memory Management – grijjy blog

Posted by jpluimers on 2017/08/10

TL;DR of [WayBackExperiments in Uniform Memory Management – grijjy blog:

the closest we can get to uniform memory management is to use object interfaces

The reason is that cross platform memory management in Delphi is a mess.

Via: [WayBackErik van Bilsen – Google+ I share some results of my quest for a uniform memory management model across all platforms. For some reason, it also touches on old-school linked lists and new-school messaging…

–jeroen

 

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