February 2012
    Get Version

January 2007
    Bezier Text

December 2005
    Rotated Ellipses

December 2004
    PDF Page Count

January 2003
» Boolean Blues

March 2002
    Networked Drives

January 2002
    Treeview Troubles
    Appending to Exe's

Freeware Components
Boolean Blues January 2003
It's easy to waste an hour or two tracking down the idiosyncracies resulting from different versions of Delphi and Windows. That is what happened to me the other day while implementing the FindFirstChangeNotification() Windows API function.

FindFirstChangeNotification() requires a longbool for its second parameter. In Delphi 2 the longbool type has a binary value of 1 or 0 for true or false respectively. In subsequent versions of Delphi, the longbool type has a binary value or -1 or 0. In Windows programming any non-zero value is usually treated as true by the OS. However, in Windows 98, the FindFirstChangeNotification() function does not obey this convention as the second parameter must be either 0 or 1 otherwise the function will return INVALID_HANDLE_VALUE. (Windows XP does follow the convention by treating any non-zero value as true.) Problems arise when passing a true longbool value in Delphi as the second parameter. See the code below to see how I circumvented this problem ...

[ For a component which properly encapsulates FindFirstChangeNotification within a watching thread see my freeware components. ]

Code snippet ...
procedure TForm1.Button1Click(Sender: TObject);
  FileChangeHandle : THandle;
  subFolders: longbool;
  //subFolders := true;
  //the above works in D2 only ...
  //(otherwise integer(subFolders) == -1)

  //subFolders := longbool(1);
  //the above works in D2 & D3 only ...
  //(otherwise integer(subFolders) == -1)

  //Delphi 2 to 7 ...
  cardinal(subFolders) := 1;

  FileChangeHandle :=
      FindFirstChangeNotification('c:\', subFolders, 
  if (FileChangeHandle = INVALID_HANDLE_VALUE) then
    self.caption := 'Bummer :-('
    self.caption := 'It worked!';

Copyright © 2002-2006 Angus Johnson