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 2,947 other followers

Archive for September 19th, 2017

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:

00417CA8 FF2528E12901     jmp dword ptr [$0129e128]
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


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:


Read the rest of this entry »

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

%d bloggers like this: