Thursday, April 7, 2011

Checking if a folder is empty.

function IsDirectoryEmpty(const ADirectory: String): Boolean;
var
  searchRec: TSearchRec;
begin
   try
Result := (FindFirst(ADirectory+'\*.*', faAnyFile, searchRec) = 0) AND
  (FindNext(searchRec) = 0) AND
  (FindNext(searchRec) <> 0);
   finally
     FindClose(searchRec);
   end;
end;

Thursday, February 17, 2011

Block Alt-F4 in Delphi

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (Key = VK_F4) and (ssAlt in Shift) then
       Key := 0;
end;

Wednesday, February 16, 2011

How to Minimize All Windows

uses ComObj;

procedure MinimizeAll;
var
  Shell : OleVariant;
begin
  try
   Shell := CreateOleObject('Shell.Application') ;
   Shell.MinimizeAll;
  finally
  end;
end;