home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto04 / delphi10 / drwsutl3.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-25  |  101.7 KB  |  2,684 lines

  1. unit Drwsutl3;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22. type
  23.   { This is a descendant of TFileListbox }
  24.   { Which puts icons of files into the   }
  25.   { Objects array rather than the stand- }
  26.   { ard bitmaps.                         }
  27.   TIconFileListBox = class( TFileListBox )
  28.   public
  29.     { public methods and data }
  30.     procedure ReadFileNames; override;
  31.     function GetNextSelection( SourceDirectory : String;
  32.               var CurrentItem : Integer ) : String;
  33.     constructor Create(AOwner : TComponent); override; { override create    }
  34.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  35.   end;
  36.   TFileWorkBench = class( TComponent )
  37.   public
  38.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  39.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  40.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  41.     function StripNonRootTrailingBackSlash(
  42.               const TheFileName : String ) : String;
  43.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  44.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  45.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  46.                                  TheMessage : String; TheCode : Integer );
  47.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  48.                 TheCode : Integer );
  49.     function CopyFile( TargetPath ,
  50.                DestinationPath : String ) : Boolean;
  51.     procedure ChangeTheDirectory( NewPath : String );
  52.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  53.     procedure CopyTheFile( OldPath , NewPath : String );
  54.     procedure MoveTheFile( OldPath , NewPath : String );
  55.     procedure DeleteTheFile( ThePath : String );
  56.     procedure RenameTheFile( OldPath , NewName : String );
  57.     procedure CreateNewDirectory( NewPath : String );
  58.     procedure RemoveDirectory( ThePath : String );
  59.     procedure SetFileAttributes( TheFile  : String; TheAttributes : Integer );
  60.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  61.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  62.     procedure RecursivelyDeleteDirectory( ThePath : String );
  63.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  64.                ActionCode : Integer );
  65.   end;
  66.   TFileIconPanel = class( TPanel )
  67.   private
  68.     { Private declarations }
  69.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  70.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  71.     procedure TheMouseDown(Sender: TObject;
  72.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  73.     procedure TheMouseUp(Sender: TObject;
  74.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  75.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
  76.      message WM_LBUTTONDBLCLK;
  77.     procedure TheDragOver(Sender, Source: TObject; X,
  78.       Y: Integer; State: TDragState; var Accept: Boolean);
  79.     procedure TheDragDrop(Sender, Source: TObject; X,
  80.       Y: Integer);
  81.   protected                                   { event method procedure.      }
  82.     { Protected declarations }
  83.     procedure Paint; override;                { This allows custom painting  }
  84.   public
  85.     { Public declarations }
  86.     FTheIcon : TIcon;                         { This is the display icon    }
  87.     FTheName : String;                        { This is the filename        }
  88.     FTheLabel : TLabel;                       { This is the display label   }
  89.     Selected : Boolean;                       { This holds selection status }
  90.     constructor Create(AOwner : TComponent); override; { override create    }
  91.     procedure Initialize( PanelX              ,             { Left          }
  92.                           PanelY              ,             { Top           }
  93.                           PanelWidth          ,             { Width         }
  94.                           PanelHeight         ,             { Height        }
  95.                           PanelBevelWidth     ,             { Bevel Width   }
  96.                           LabelFontSize         : Integer;  { Font size     }
  97.                           PanelColor          ,             { Main color    }
  98.                           PanelHighlightColor ,             { Bright color  }
  99.                           PanelShadowColor    ,             { Dark color    }
  100.                           LabelTextColor        : TColor;   { Text color    }
  101.                           TheFilename         ,             { Filename      }
  102.                           LabelFontName         : String;   { Font name     }
  103.                           LabelFontStyle        : TFontStyles;  { Font style}
  104.                           ExtraData             : Integer       );  { Drive }
  105.     destructor Destroy; override;             { override destroy to free    }
  106.   end;
  107.   TFileIconPanelScrollBox = class( TScrollBox )
  108.   public
  109.     { Public methods and data }
  110.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  111.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  112.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  113.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  114.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  115.     TheStoredHandle    : HWnd;
  116.     TheParentForm      : TForm;
  117.     procedure Update;                                { Called to reset display }
  118.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  119.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  120.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  121.     procedure GetColorsForFileIcon( TheFile : String;
  122.                var BC , HC , SC , TC : TColor );
  123.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  124.     function GetNextSelection( SourceDirectory : String;
  125.               var CurrentItem : Integer ) : String;
  126.     procedure DisplayRecursiveSearchResults(
  127.       TheStartingDirectory : String );
  128.   end;
  129.   TIOManager = class( TComponent )
  130.   public
  131.     Parent : TForm;
  132.     WhichButton : TMouseButton;
  133.     WhichState  : TShiftState;
  134.     function WasLeftPressed : Boolean;
  135.     function WasRightPressed : Boolean;
  136.     function WasMiddlePressed : Boolean;
  137.     function WasALTPressed : Boolean;
  138.     function WasSHIFTPressed : Boolean;
  139.     function WasCTRLPressed : Boolean;
  140.     procedure OnF1Pressed(Sender: TObject; var Key: Word;
  141.      Shift: TShiftState);
  142.     procedure OnF2Pressed(Sender: TObject; var Key: Word;
  143.      Shift: TShiftState);
  144.     procedure OnF3Pressed(Sender: TObject; var Key: Word;
  145.      Shift: TShiftState);
  146.     procedure OnF4Pressed(Sender: TObject; var Key: Word;
  147.      Shift: TShiftState);
  148.     procedure OnF5Pressed(Sender: TObject; var Key: Word;
  149.      Shift: TShiftState);
  150.     procedure OnF6Pressed(Sender: TObject; var Key: Word;
  151.      Shift: TShiftState);
  152.     procedure OnF7Pressed(Sender: TObject; var Key: Word;
  153.      Shift: TShiftState);
  154.     procedure OnF8Pressed(Sender: TObject; var Key: Word;
  155.      Shift: TShiftState);
  156.     procedure OnF9Pressed(Sender: TObject; var Key: Word;
  157.      Shift: TShiftState);
  158.     procedure OnF10Pressed(Sender: TObject; var Key: Word;
  159.      Shift: TShiftState);
  160.     procedure OnF11Pressed(Sender: TObject; var Key: Word;
  161.      Shift: TShiftState);
  162.     procedure OnF12Pressed(Sender: TObject; var Key: Word;
  163.      Shift: TShiftState);
  164.  end;
  165.   { This procedure gets an icon for a file using FindExecutable  }
  166.   { and ExtractIcon. (assumes file/dir is passed)                }
  167.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  168.   { This procedure spaces out the bitbtn components on a tpanel }
  169.   procedure SpacePanelButtons( WhichPanel : TPanel );
  170.     procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  171.                GlobalErrorCode : Integer );
  172.  
  173. var TheIOManager : TIOManager;
  174.     GlobalAbortFlag : Boolean;
  175.  
  176. implementation
  177. {$R DRWSUTL3.RES}                 { Import custom resource file }
  178. uses UFMGR13;
  179.  
  180. { It has been edited to return viable error codes!             }
  181. procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  182.             GlobalErrorCode : Integer );
  183. var
  184.   CopyBuffer: Pointer; { buffer for copying }
  185.   BytesCopied: Longint;
  186.   TheAttr : Integer;
  187.   Source, Dest: Integer; { handles }
  188. const
  189.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  190. begin
  191.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  192.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  193.   if Source < 0 then
  194.   begin  { error creating source file }
  195.     GlobalErrorType := EOC_SOURCECOPY;
  196.     GlobalErrorCode := -IOResult;
  197.     if GlobalErrorCode = 0 then GlobalErrorCode := -157;
  198.     FreeMem( CopyBuffer, ChunkSize );
  199.     exit;
  200.   end;
  201.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  202.   if Dest < 0 then
  203.   begin  { error creating destination file }
  204.     FileClose( Source );
  205.     GlobalErrorType := EOC_DESTCOPY;
  206.     GlobalErrorCode := -IOResult;
  207.     if GlobalErrorCode = 0 then GlobalErrorCode := -159;
  208.     FreeMem( CopyBuffer , ChunkSize );
  209.     exit;
  210.   end;
  211.   {$I-}
  212.   repeat
  213.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  214.     if BytesCopied > 0 then { if we read anything... }
  215.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  216.   until BytesCopied < ChunkSize; { until we run out of chunks }
  217.   {$I+}
  218.   GlobalErrorCode := -IOResult;  { get any error code which happens during copying }
  219.   FileClose(Dest); { close the destination file }
  220.   FileClose(Source); { close the source file }
  221.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  222. end;
  223.  
  224. { This procedure spaces out the bitbtn components on a tpanel }
  225. procedure SpacePanelButtons( WhichPanel : TPanel );
  226. var TheCalculatedSpacing     ,            { Holds primary spacing }
  227.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  228.     Counter_1                  : Integer; { Loop counter          }
  229.     TotalIBs                   : Integer; { Gets total buttons    }
  230. begin
  231.   { Set up spacing values }
  232.   TotalIBs := WhichPanel.ControlCount;
  233.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  234.    div ( TotalIbs + 1 ));
  235.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  236.   { Loop through all imported buttons and set their Left values }
  237.   for Counter_1 := 1 to WhichPanel.ControlCount do
  238.   begin
  239.     if Counter_1 = 1 then
  240.     begin
  241.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  242.        TheCalculatedSpacing;
  243.     end
  244.     else
  245.     begin
  246.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  247.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  248.     end;
  249.   end;
  250. end;
  251.  
  252. { This procedure gets an icon for a file using FindExecutable  }
  253. { and ExtractIcon. (assumes file/dir is passed)                }
  254. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  255. var TheExt           : String; { File extension holder }
  256.     TheOtherPChar  ,           { Windows ASCIIZ string }
  257.     TheResultPChar ,           { Windows ASCIIZ string }
  258.     ThePChar         : PChar;  { Windows ASCIIZ string }
  259. begin
  260.   { Check for directory and if so get directory icon from RES file }
  261.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  262.   begin
  263.     { Set up the PChar to communicate with Windows }
  264.     GetMem( TheOtherPChar , 255 );
  265.     { Convert Pascal-style string to ASCIIZ Pchar }
  266.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  267.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  268.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  269.     { Release memory from PChar }
  270.     FreeMem( TheOtherPChar , 255 );
  271.     { Leave }
  272.     exit;
  273.   end;
  274.   { Assume archive file; get its extension }
  275.   TheExt := Uppercase( ExtractFileExt( TheName ));
  276.   { If not an executable/image file then use FindExecutable to get icon }
  277.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  278.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  279.   begin
  280.     { Grab three chunks of memory }
  281.     GetMem( TheOtherPChar , 255 );
  282.     GetMem( TheResultPChar , 255 );
  283.     GetMem( ThePChar , 255 );
  284.     { Set up the name and its directory in Windows string formats }
  285.     StrPCopy( ThePChar, TheName );
  286.     StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  287.     { Use FindExecutable API call to get path and name of owning file }
  288.     if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  289.     begin
  290.       { If get a result of 32 or more then try to get first icon of owner }
  291.       { Using ExtractIcon API call; 0 indicates first icon.               }
  292.       TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  293.       { If a handle is 0 then no icon in owner, get default icon from RES file }
  294.       if TheIcon.Handle = 0 then
  295.       begin
  296.         GetMem( TheOtherPChar , 255 );
  297.         StrPCopy( TheOtherPChar , 'NOICON' );
  298.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  299.         FreeMem( TheOtherPChar , 255 );
  300.         exit;
  301.       end;
  302.     end
  303.     else
  304.     { if no assigned executable, then get default icon from RES file }
  305.     begin
  306.       GetMem( TheOtherPChar , 255 );
  307.       StrPCopy( TheOtherPChar , 'NOICON' );
  308.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  309.       FreeMem( TheOtherPChar , 255 );
  310.       exit;
  311.     end;
  312.     FreeMem( TheOtherPChar , 255 );
  313.     FreeMem( TheResultPChar , 255 );
  314.     FreeMem( ThePChar , 255 );
  315.   end
  316.   else
  317.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  318.   begin
  319.     GetMem( ThePChar , 255 );
  320.     StrPCopy( ThePChar , TheName );
  321.     { If no icons in file then get default icon (note use FFFF for -1) }
  322.     if ExtractIcon( hInstance , ThePchar , 65535 ) = 0 then
  323.     begin
  324.       Freemem( ThePChar , 255 );
  325.       GetMem( TheOtherPChar , 255 );
  326.       StrPCopy( TheOtherPChar , 'NOICON' );
  327.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  328.       FreeMem( TheOtherPChar , 255 );
  329.       exit;
  330.     end
  331.     else
  332.     begin
  333.       { Try to get first icon for file }
  334.       TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  335.       FreeMem( ThePChar , 255 );
  336.       { If handle is 0 invalid icon format so use default from RES file }
  337.       if TheIcon.Handle = 0 then
  338.       begin
  339.         GetMem( TheOtherPChar , 255 );
  340.         StrPCopy( TheOtherPChar , 'NOICON' );
  341.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  342.         FreeMem( TheOtherPChar , 255 );
  343.         exit;
  344.       end;
  345.     end;
  346.   end;
  347. end;
  348.  
  349. { This procedure handles pressing of F1 for CCFileManagerForm }
  350. procedure TIoManager.OnF1Pressed(Sender: TObject; var Key: Word;
  351.   Shift: TShiftState);
  352. begin
  353.   MessageDlg( 'Help not implemented!' , mtInformation,[mbok],0);
  354. end;
  355.  
  356. { This procedure handles pressing of F2 for CCFileManagerForm }
  357. procedure TIoManager.OnF2Pressed(Sender: TObject; var Key: Word;
  358.   Shift: TShiftState);
  359. begin
  360.   TCCFileMgrForm( Parent ).BitBtn1Click( Sender );
  361. end;
  362.  
  363. { This procedure handles pressing of F3 for CCFileManagerForm }
  364. procedure TIoManager.OnF3Pressed(Sender: TObject; var Key: Word;
  365.   Shift: TShiftState);
  366. begin
  367.   TCCFileMgrForm( Parent ).BitBtn2Click( Sender );
  368. end;
  369.  
  370. { This procedure handles pressing of F4 for CCFileManagerForm }
  371. procedure TIoManager.OnF4Pressed(Sender: TObject; var Key: Word;
  372.   Shift: TShiftState);
  373. begin
  374.   TCCFileMgrForm( Parent ).BitBtn3Click( Sender );
  375. end;
  376.  
  377. { This procedure handles pressing of F5 for CCFileManagerForm }
  378. procedure TIoManager.OnF5Pressed(Sender: TObject; var Key: Word;
  379.   Shift: TShiftState);
  380. begin
  381.   TCCFileMgrForm( Parent ).BitBtn4Click( Sender );
  382. end;
  383.  
  384. { This procedure handles pressing of F6 for CCFileManagerForm }
  385. procedure TIoManager.OnF6Pressed(Sender: TObject; var Key: Word;
  386.   Shift: TShiftState);
  387. begin
  388.   TCCFileMgrForm( Parent ).BitBtn5Click( Sender );
  389. end;
  390.  
  391. { This procedure handles pressing of F7 for CCFileManagerForm }
  392. procedure TIoManager.OnF7Pressed(Sender: TObject; var Key: Word;
  393.   Shift: TShiftState);
  394. begin
  395.   TCCFileMgrForm( Parent ).BitBtn9Click( Sender );
  396. end;
  397.  
  398. { This procedure handles pressing of F8 for CCFileManagerForm }
  399. procedure TIoManager.OnF8Pressed(Sender: TObject; var Key: Word;
  400.   Shift: TShiftState);
  401. begin
  402.   TCCFileMgrForm( Parent ).BitBtn6Click( Sender );
  403. end;
  404.  
  405. { This procedure handles pressing of F9 for CCFileManagerForm }
  406. procedure TIoManager.OnF9Pressed(Sender: TObject; var Key: Word;
  407.   Shift: TShiftState);
  408. begin
  409.   TCCFileMgrForm( Parent ).Update;
  410. end;
  411.  
  412. { This procedure handles pressing of F10 for CCFileManagerForm }
  413. procedure TIoManager.OnF10Pressed(Sender: TObject; var Key: Word;
  414.   Shift: TShiftState);
  415. begin
  416.   TCCFileMgrForm( Parent ).BitBtn7Click( Sender );
  417. end;
  418.  
  419. { This procedure handles pressing of F11 for CCFileManagerForm }
  420. procedure TIoManager.OnF11Pressed(Sender: TObject; var Key: Word;
  421.   Shift: TShiftState);
  422. begin
  423.   TCCFileMgrForm( Parent ).BitBtn8Click( Sender );
  424. end;
  425.  
  426. { This procedure handles pressing of F12 for CCFileManagerForm }
  427. procedure TIoManager.OnF12Pressed(Sender: TObject; var Key: Word;
  428.   Shift: TShiftState);
  429. begin
  430.   TCCFileMgrForm( Parent ).BitBtn10Click( Sender );
  431. end;
  432.  
  433. { Returns True if the Left Button was pressed in the last mouse operation }
  434. function TIOManager.WasLeftPressed : Boolean;
  435. begin
  436.   if ( mbLeft = WhichButton ) then WasLeftPressed := true else
  437.    WasLeftPressed := false;
  438. end;
  439.  
  440. { Returns true if the Right Button was pressed in the last mouse operation }
  441. function TIOManager.WasRightPressed : Boolean;
  442. begin
  443.   if mbRight = WhichButton then WasRightPressed := true else
  444.    WasRightPressed := false;
  445. end;
  446.  
  447. { Returns true if the Middle Button was pressed in the last mouse operation }
  448. function TIOManager.WasMiddlePressed : Boolean;
  449. begin
  450.   if mbMiddle = WhichButton then WasMiddlePressed := true else
  451.    WasMiddlePressed := false;
  452. end;
  453.  
  454. { Returns true if the ALT key was down during the last IO operation }
  455. function TIOManager.WasALTPressed : Boolean;
  456. begin
  457.   if ssAlt in WhichState then WasALTPressed := true else
  458.    WasALTPressed := false;
  459. end;
  460.  
  461. { Returns true if either SHIFT key was down during the last IO operation }
  462. function TIOManager.WasSHIFTPressed : Boolean;
  463. begin
  464.   if ssShift in WhichState then WasSHIFTPressed := true else
  465.    WasSHIFTPressed := false;
  466. end;
  467.  
  468. { Returns true if the Control Key was down during the last IO operation }
  469. function TIOManager.WasCTRLPressed : Boolean;
  470. begin
  471.   if ssCtrl in WhichState then WasCTRLPressed := true else
  472.    WasCTRLPressed := false;
  473. end;
  474.  
  475.  
  476. { This procedure does a fully error-trapped change directory }
  477. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  478. var CurrentDirectory : String;
  479. begin
  480.   if NewPath = '..' then
  481.   begin { Back up one level }
  482.     {$I+}
  483.     try
  484.       { Find the current directory }
  485.       GetDir( 0 , CurrentDirectory );
  486.       { Use EFP to move up one level }
  487.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  488.       { Strip trailing \ if not root }
  489.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  490.       { Try the change to the new drive }
  491.       ChDir( CurrentDirectory );
  492.     except
  493.       { if any exception occurs instantiate exception and show }
  494.       On E:EInOutError do
  495.       begin
  496.         { Call custom error display/lookup procedure }
  497.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  498.          E.Message , E.ErrorCode );
  499.       end;
  500.     end;
  501.   end
  502.   else
  503.   begin { Change to explicit path }
  504.     {$I+}
  505.     try
  506.       { Get target directory path }
  507.       CurrentDirectory := NewPath;
  508.       { Strip trailing \ if not root }
  509.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  510.       { Try the change to the new drive }
  511.       ChDir( CurrentDirectory );
  512.     except
  513.       { if any exception occurs instantiate exception and show }
  514.       On E:EInOutError do
  515.       begin
  516.         { Call custom error display/lookup procedure }
  517.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  518.          E.Message , E.ErrorCode );
  519.       end;
  520.     end;
  521.   end;
  522. end;
  523.  
  524. { This procedure does a fully error-trapped change directory }
  525. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  526. var CurrentDirectory : String;
  527. begin
  528.   {$I+}
  529.   try
  530.     { Find the working directory on new drive }
  531.     GetDir( NewDrive , CurrentDirectory );
  532.     { Try the change to the new drive }
  533.     ChDir( CurrentDirectory );
  534.   except
  535.     { if any exception occurs instantiate exception and show }
  536.     On E:EInOutError do
  537.     begin
  538.       { Call custom error display/lookup procedure }
  539.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  540.        E.Message , E.ErrorCode );
  541.     end;
  542.   end;
  543. end;
  544.  
  545. { This procedure copies a single file with error trapping }
  546. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  547. var AResult : Boolean; { Internal data flag }
  548. begin
  549.   { If Copyfile returns false an error occurred }
  550.   AResult := CopyFile( OldPath , NewPath +
  551.    ExtractFileName( OldPath ));
  552.   { Display meaningful error message }
  553.   if not AResult then HandleDOSError( GlobalErrorType , OldPath, GlobalError );
  554. end;
  555.  
  556. { This procedure moves a file by copying and delete it }
  557. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  558. var AResult : Boolean; { Internal data flag }
  559.     TheFile : File;    { Use to get errors  }
  560. begin
  561.   { If Copyfile returns false an error occurred }
  562.   AResult := CopyFile( OldPath , NewPath +
  563.     ExtractFileName( OldPath ));
  564.   { Display meaningful error message }
  565.   if not AResult then HandleDOSError( GlobalErrorType ,
  566.     OldPath , GlobalError );
  567.   { After valid copying, delete source file }
  568.   {$I+}
  569.   if AResult then try
  570.     { Use this trick to get valid exception handling }
  571.     AssignFile( TheFile , OldPath );
  572.     { Use erase because Deletefile doesn't give exceptions! }
  573.     Erase( TheFile );
  574.   except
  575.     { if any exception occurs instantiate exception and show }
  576.     On E:EInOutError do
  577.     begin
  578.       { Call custom error display/lookup procedure }
  579.       HandleIOException( EOC_DELETEFILE , OldPath ,
  580.        E.Message , E.ErrorCode );
  581.     end;
  582.   end;
  583. end;
  584.  
  585. { This procedure safely deletes a single file }
  586. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  587. var TheFile : File; { Internal file handle }
  588. begin
  589.   {$I+}
  590.   try
  591.     { Use this trick to get valid exception handling }
  592.     AssignFile( TheFile , ThePath );
  593.     { Use erase because Deletefile doesn't give exceptions! }
  594.     Erase( TheFile );
  595.   except
  596.     { if any exception occurs instantiate exception and show }
  597.     On E:EInOutError do
  598.     begin
  599.       { Call custom error display/lookup procedure }
  600.       HandleIOException( EOC_DELETEFILE , ThePath ,
  601.        E.Message , E.ErrorCode );
  602.     end;
  603.   end;
  604. end;
  605.  
  606. { This procedure renames a file with full error trapping }
  607. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  608. var TheFile : File; { Internal file handle }
  609. begin
  610.   {$I+}
  611.   try
  612.     { Use this trick to get valid exception handling }
  613.     AssignFile( TheFile , OldPath );
  614.     { Use this because RenameFile doesn't give exceptions! }
  615.     Rename( TheFile , NewName );
  616.   except
  617.     { if any exception occurs instantiate exception and show }
  618.     On E:EInOutError do
  619.     begin
  620.       { Call custom error display/lookup procedure }
  621.       HandleIOException( EOC_RENAMEFILE , OldPath  ,
  622.        E.Message , E.ErrorCode );
  623.     end;
  624.   end;
  625. end;
  626.  
  627. { This procedure creates a new directory with full error trapping }
  628. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  629. begin
  630.   {$I+}
  631.   try
  632.     Mkdir( NewPath );
  633.   except
  634.     { if any exception occurs instantiate exception and show }
  635.     On E:EInOutError do
  636.     begin
  637.       { Call custom error display/lookup procedure }
  638.       HandleIOException( EOC_MAKEDIR , NewPath  ,
  639.        E.Message , E.ErrorCode );
  640.     end;
  641.   end;
  642. end;
  643.  
  644. { This procedure remove a directory with full error trapping }
  645. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  646. begin
  647.   {$I+}
  648.   try
  649.     Rmdir( ThePath );
  650.   except
  651.     { if any exception occurs instantiate exception and show }
  652.     On E:EInOutError do
  653.     begin
  654.       { Call custom error display/lookup procedure }
  655.       HandleIOException( EOC_DELETEDIR , ThePath  ,
  656.        E.Message , E.ErrorCode );
  657.     end;
  658.   end;
  659. end;
  660.  
  661. { Use this to set the attributes of a file with error trapping }
  662. procedure TFileWorkBench.SetFileAttributes( TheFile  : String;
  663.            TheAttributes : Integer );
  664. var TheResult : Integer; { Holds error code if any }
  665. begin
  666.   { Attempt to set the attributes }
  667.   TheResult := FileSetAttr( TheFile , TheAttributes );
  668.   { if negative number error, so signal }
  669.   if TheResult < 0 then
  670.    HandleDOSError( EOC_SETATTR , TheFile , -TheResult );
  671. end;
  672.  
  673. { This procedure recursively copies a directory to a new path }
  674. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  675. var TheDir : String; { Holds source directory }
  676. begin
  677.   { Get the source directory to copy }
  678.   TheDir := ExtractFileName( OldPath );
  679.   { Force a backslash to the newpath variable }
  680.   NewPath := ForceTrailingBackSlash( NewPath );
  681.   { Add the source directory to the target path }
  682.   NewPath := NewPath + TheDir;
  683.   { Create a new directory with the new name }
  684.   CreateNewDirectory( NewPath );
  685.   { Force a backslash for compatibility }
  686.   NewPath := FOrcetrailingBackSlash( NewPath );
  687.   { Do the recursive call }
  688.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  689. end;
  690.  
  691. { This procedure recursively moves a directory tree }
  692. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  693. var TheDir    : String; { Holds source directory  }
  694.     SavedPath : String; { Holds saved dir to kill }
  695. begin
  696.   { Get the source directory to move }
  697.   TheDir := ExtractFileName( OldPath );
  698.   { Force a backslash to the newpath variable }
  699.   NewPath := ForceTrailingBackSlash( NewPath );
  700.   { Save the starting path just in case }
  701.   SavedPath := OldPath;
  702.   { Add the source directory to the target path }
  703.   NewPath := NewPath + TheDir;
  704.   { Create a new directory with the new name }
  705.   CreateNewDirectory( NewPath );
  706.   { Force a backslash for compatibility }
  707.   NewPath := FOrcetrailingBackSlash( NewPath );
  708.   { Do the recursive call }
  709.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  710.   { Remove the source directory }
  711.   RemoveDirectory( SavedPath );
  712. end;
  713.  
  714. { This procedure handles recursively deleting an entire directory tree }
  715. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  716. begin
  717.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  718. end;
  719.  
  720.  
  721. { This is the generic routine to copy, move, and delete whole directory trees }
  722. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  723.            ActionCode : Integer );
  724. { VITAL!!! These variables MUST be local for recursrion to work! }
  725. var
  726.     Finished        : Boolean;         { Loop flag              }
  727.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  728.     TheResult       : Integer;         { return variable        }
  729.     TargetPath ,
  730.     FileMask   ,
  731.     TheWorkingDirectory ,
  732.     TheStoredWorkingDirectory ,
  733.     ModifiedDirectory  : String;       { path for FF/FN         }
  734.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  735.     ButtonColor   ,                    { main panel color       }
  736.     ButtonHLColor ,                    { bright panel color     }
  737.     ButtonSColor  ,                    { dark panel color       }
  738.     Textcolor       : TColor;          { label text color       }
  739.     TheFile         : File;
  740.  
  741. begin
  742.   { Set up the initial variables }
  743.   Finished := false;
  744.   TheWorkingDirectory := StartingPath;
  745.   TheStoredWorkingDirectory := TheWorkingDirectory;
  746.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  747.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  748.   { Make the call to FindFirst set to get any file }
  749.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  750.   { loop through all files in the directory and delete them }
  751.   while not Finished do
  752.   begin
  753.     { Make call to FindNext, using only SearchRecord from FindFirst }
  754.     TheResult := FindNext( TheSR );
  755.     { A -1 result means no more files so exit }
  756.     if TheResult < 0 then finished := true else
  757.     begin
  758.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  759.        <> faDirectory ) then
  760.       begin { A File }
  761.         case ActionCode of
  762.           FAC_COPY :
  763.               begin
  764.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  765.               end;
  766.           FAC_MOVE :
  767.               begin
  768.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  769.               end;
  770.           FAC_DELETE :
  771.               begin { Delete }
  772.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  773.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  774.                     DeleteTheFile( TargetPath + TheSR.Name );
  775.               end;
  776.         end;
  777.       end;
  778.     end;
  779.   end;
  780.   { Call FindClose for Windows NT/Windows 95 compatibility }
  781.   FindClose( TheSR );
  782.   { Set up the variables to do recursive calls on all directories}
  783.   Finished := false;
  784.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  785.   { Make the call to FindFirst set to get any file, ignore result }
  786.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  787.   while not Finished do
  788.   begin
  789.     { Make call to FindNext, using only SearchRecord from FindFirst }
  790.     TheResult := FindNext( TheSR );
  791.     { A -1 result means no more files so exit }
  792.     if TheResult < 0 then
  793.       finished := true
  794.     else
  795.     begin
  796.       if TheSR.Name <> '..' then { Ignore backup in this case }
  797.       begin
  798.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  799.          = faDirectory ) then
  800.         begin
  801.           { Send in the new directory name }
  802.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  803.            TheSR.Name;
  804.           { Reproduce directory structure for recursion in copy/move }
  805.           NewPath := NewPath + TheSR.Name;
  806.           case ActionCode of
  807.             FAC_COPY , FAC_MOVE :
  808.                begin { Create ahead for move and copy }
  809.                  { Make the new directory for moving and copying }
  810.                  CreateNewDirectory( NewPath );
  811.                  { Force a backslash for compatibility }
  812.                  NewPath := ForceTrailingBackSlash( NewPath );
  813.                end;
  814.             FAC_DELETE :
  815.                begin  { No prior action needed for Delete }
  816.                end;
  817.           end;
  818.           { Do the recursive call }
  819.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  820.           case ActionCode of
  821.             FAC_COPY :
  822.                begin { no action for copy }
  823.                end;
  824.             FAC_MOVE , FAC_DELETE :
  825.                begin  { Delete }
  826.                  { Get a confirmation }
  827.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  828.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  829.                    RemoveDirectory( TargetPath + TheSR.Name );
  830.                end;
  831.           end;
  832.         end;
  833.       end;
  834.     end;
  835.   end;
  836. end;
  837.  
  838. { This is a generic copy routine taken from Delphi sample code }
  839. { This function calls the sample Copy code and handles errors }
  840. function TFileWorkBench.CopyFile( TargetPath ,
  841.           DestinationPath : String ) : Boolean;
  842. begin
  843.   { Set global error value to no error }
  844.   GlobalError := 0;
  845.   { Call the sample procedure to do the copy }
  846.   FMXUCopyFile( TargetPath, DestinationPath , GlobalErrorType , GlobalError );
  847.   { If no error return true else return false }
  848.   if GlobalError < 0 then CopyFile := false else
  849.    CopyFile := true;
  850. end;
  851.  
  852. { This procedure handles displaying a user-friendly Dialog box with a }
  853. { Message for Delphi IO exception errors.                             }
  854. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  855.            ThePath : String; TheMessage : String; TheCode : Integer );
  856. var ErrorMessageString : String;  { Holds internal data }
  857.     OperationString    : String;  { Holds internal data }
  858. begin
  859.   { clear to check for unrecognized code }
  860.   ErrorMessageString := '';
  861.   { Check against imported code }
  862.   case TheCode of
  863.     2    : ErrorMessageString := 'File not found';
  864.     3    : ErrorMessageString := 'Path not found';
  865.     4    : ErrorMessageString := 'Too many open files';
  866.     5    : ErrorMessageString := 'File access denied';
  867.     6    : ErrorMessageString := 'Invalid file handle';
  868.     12    : ErrorMessageString := 'Invalid file access code';
  869.     15    : ErrorMessageString := 'Invalid drive number';
  870.     16  : ErrorMessageString := 'Cannot remove current directory';
  871.     17    : ErrorMessageString := 'Cannot rename across drives';
  872.     100    : ErrorMessageString := 'Disk read error';
  873.     101    : ErrorMessageString := 'Disk write error';
  874.     102    : ErrorMessageString := 'File not assigned';
  875.     103    : ErrorMessageString := 'File not open';
  876.     104    : ErrorMessageString := 'File not open for input';
  877.     105    : ErrorMessageString := 'File not open for output';
  878.   end;
  879.   case TheOpCode of
  880.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  881.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  882.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  883.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  884.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  885.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  886.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  887.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  888.   end;
  889.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  890.   if ErrorMessageString = '' then
  891.   begin
  892.     Screen.Cursor := crDefault;
  893.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  894.      TheMessage , mtError , [mbOK],0);
  895.   end
  896.   else
  897.   begin
  898.     { Recognized DOS exception, reset cursor for neatness }
  899.     Screen.Cursor := crDefault;
  900.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  901.      ErrorMessageString , mtError , [mbOK], 0 );
  902.   end;
  903. end;
  904.  
  905. { This procedure handles displaying a user-friendly Dialog box with a }
  906. { Message for DOS error codes.                                        }
  907. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  908.            ThePath : String;  TheCode : Integer );
  909. var ErrorMessageString : String;  { internal message holder }
  910.     OperationString : String;     { internal message holder }
  911. begin
  912.   { clear the message holder to check for unrecognized code }
  913.   ErrorMessageString := '';
  914.   { Negate the code back to normal number and check to set string }
  915.   case -TheCode of
  916.     2    : ErrorMessageString := 'File not found';
  917.     3    : ErrorMessageString := 'Path not found';
  918.     4    : ErrorMessageString := 'Too many open files';
  919.     5    : ErrorMessageString := 'File access denied';
  920.     6    : ErrorMessageString := 'Invalid file handle';
  921.     12    : ErrorMessageString := 'Invalid file access code';
  922.     15    : ErrorMessageString := 'Invalid drive number';
  923.     16  : ErrorMessageString := 'Cannot remove current directory';
  924.     17    : ErrorMessageString := 'Cannot rename across drives';
  925.     100    : ErrorMessageString := 'Disk read error';
  926.     101    : ErrorMessageString := 'Disk write error';
  927.     102    : ErrorMessageString := 'File not assigned';
  928.     103    : ErrorMessageString := 'File not open';
  929.     104    : ErrorMessageString := 'File not open for input';
  930.     105    : ErrorMessageString := 'File not open for output';
  931.     157 : ErrormessageString := 'Could not open Source File';
  932.     159 : ErrormessageString := 'Could not open Target File';
  933.   end;
  934.   case TheOpCode of
  935.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  936.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  937.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  938.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  939.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  940.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  941.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  942.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  943.   end;
  944.   { If the string is empty an unrecognized code was sent in }
  945.   if ErrorMessageString = '' then
  946.   begin
  947.     { Sent up db based on source or target error; reset cursor for neatness }
  948.     Screen.Cursor := crDefault;
  949.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  950.      IntToStr( TheCode ) , mtError , [mbOK],0);
  951.   end
  952.   else  { Code is recognized, use message from case statement }
  953.   begin
  954.     { Format the output for source or target error }
  955.     Screen.Cursor := crDefault;
  956.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  957.      ErrorMessageString , mtError , [mbOK], 0 );
  958.   end;
  959. end;
  960.  
  961. { This procedure sets the imported booleans to the file's attributes }
  962. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  963.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  964.             IsSysFile : Boolean );
  965. var TheResult : Integer; { Traps for error code on VolumeID }
  966. begin
  967.   { Clear the imported flags for default }
  968.   IsDirectory := false;
  969.   IsArchive := false;
  970.   IsVolumeID := false;
  971.   IsHidden := False;
  972.   IsReadOnly := false;
  973.   IsSysFile := false;
  974.   { Make the Dos call }
  975.   TheResult := FileGetAttr( TheFile );
  976.   if TheResult < 0 then
  977.   begin
  978.     { Volume ID returns -2 (?) }
  979.     IsVolumeID := true;
  980.     { It has no other properties }
  981.     exit;
  982.   end;
  983.   { Use AND test to set all other properties }
  984.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  985.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  986.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  987.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  988.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  989.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  990. end;
  991.  
  992. { This function makes sure a pathname has a trailing \ }
  993. function TFileWorkBench.ForceTrailingBackSlash(
  994.           const TheFileName : String ) : String;
  995. var TempString : String;  { Used to hold function result }
  996. begin
  997.   { If no trailing \ add one (root will already have one.) }
  998.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  999.    TempString := TheFileName + '\' else TempString := TheFileName;
  1000.   { Return modified or non-modified string }
  1001.   ForceTrailingBackslash := TempString;
  1002. end;
  1003.  
  1004. { This function makes sure a non-root dir has no trailing \ }
  1005. function TFileWorkBench.StripNonRootTrailingBackSlash(
  1006.           const TheFileName : String ) : String;
  1007. var TempString : String ; { Used to hold function result }
  1008. begin
  1009.   { Default is no change }
  1010.   TempString := TheFileName;
  1011.   { If not root then }
  1012.   if Length( TheFileName ) > 3 then
  1013.   begin
  1014.     { If has a trailing backslash remove it }
  1015.     if TheFileName[ Length( TheFileName )] = '\' then
  1016.     begin
  1017.       TempString := Copy( TheFileName , 1 ,
  1018.        Length( TheFileName ) - 1 );
  1019.     end;
  1020.   end;
  1021.   { Export the final result }
  1022.   StripNonRootTrailingBackSlash := TempString;
  1023. end;
  1024.  
  1025. { This gets the next selected listbox item }
  1026. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  1027.           var CurrentItem : Integer ): String;
  1028. var TheResult : String;  { Internal storage }
  1029.     finished  : boolean; { Loop flag        }
  1030. begin
  1031.   { If out of items to check signal and exit }
  1032.   if CurrentItem > Items.Count then TheResult := '' else
  1033.   begin
  1034.     { Otherwise scan from current position till match or end }
  1035.     finished := false;
  1036.     while not finished do
  1037.     begin
  1038.       { Check against selected property }
  1039.       if Selected[ CurrentItem - 1 ] then
  1040.       begin
  1041.         { If selected then return it and abort loop }
  1042.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  1043.         finished := true;
  1044.         { Increment current position }
  1045.         CurrentItem := CurrentItem + 1;
  1046.      end
  1047.       else
  1048.       begin
  1049.         { Increment current position }
  1050.         CurrentItem := CurrentItem + 1;
  1051.         { Otherwise check for end of data and abort if out of entries }
  1052.         if CurrentItem > Items.Count then
  1053.         begin
  1054.           TheResult := '';
  1055.           finished := true;
  1056.         end;
  1057.       end;
  1058.     end;
  1059.   end;
  1060.   { Return stored result }
  1061.   GetNextSelection := TheResult;
  1062. end;
  1063.  
  1064. { Modified from VCL Source Copyright 1995 }
  1065. { Borland International, Inc.             }
  1066. { Use this to override display with icons }
  1067. procedure TIconFileListBox.ReadFileNames;
  1068. var
  1069.   AttrIndex   : TFileAttr;
  1070.   i           : Integer;
  1071.   FileExt     : string;
  1072.   MaskPtr     : PChar;
  1073.   Ptr         : PChar;
  1074.   AttrWord    : Word;
  1075.   TempPicture : TPicture;
  1076.   TempBmp     : TBitmap;
  1077.   TempIcon    : TIcon;
  1078. const
  1079.   Attributes: array[TFileAttr] of Word =
  1080.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  1081.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  1082. begin
  1083.   { if no handle allocated yet, this call will force         }
  1084.   { one to be allocated incorrectly (i.e. at the wrong time. }
  1085.   { In due time, one will be allocated appropriately.        }
  1086.   AttrWord := DDL_READWRITE;
  1087.   if HandleAllocated then
  1088.   begin
  1089.     { Set attribute flags based on values in FileType }
  1090.     for AttrIndex := ftReadOnly to ftArchive do
  1091.      if AttrIndex in FileType then
  1092.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  1093.  
  1094.     { Use Exclusive bit to exclude normal files }
  1095.     if not ( ftNormal in FileType ) then
  1096.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  1097.  
  1098.     ChDir( FDirectory ); { go to the directory we want }
  1099.     Clear;               { clear the list }
  1100.  
  1101.     MaskPtr := FMask;
  1102.     while MaskPtr <> nil do
  1103.     begin
  1104.       Ptr := StrScan ( MaskPtr , ';' );
  1105.       if Ptr <> nil then  Ptr^ := #0;
  1106.       { build the list }
  1107.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  1108.       if Ptr <> nil then
  1109.       begin
  1110.         Ptr^ := ';';
  1111.         Inc ( Ptr );
  1112.       end;
  1113.       MaskPtr := Ptr;
  1114.     end;
  1115.     { Now add the bitmaps }
  1116.     {---------------------------- begin custom code --------------------------}
  1117.     { Create the TPicture for exchange purposes }
  1118.     TempPicture := TPicture.Create;
  1119.     { Set it to icon widths }
  1120.     TempPicture.Bitmap.Width := 32;
  1121.     TempPicture.Bitmap.Height := 32;
  1122.     { Run down the list }
  1123.     for i := 0 to Items.Count - 1 do
  1124.     begin
  1125.       { Create a new temporary icon }
  1126.       TempIcon := TIcon.Create;
  1127.       { Call the custom DRWS routine to get icon for a file }
  1128.       GetIconForFile( Items[ i ] , TempIcon );
  1129.       { Put the icon on the bitmap for the picture via draw }
  1130.       { Note 1 , 1 due to bug in Draw?                      }
  1131.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  1132.       { Create a temporary bitmap }
  1133.       TempBmp := TBitmap.Create;
  1134.       { Set its width to those of the previous object's bitmaps }
  1135.       TempBmp.Width := 16;
  1136.       TempBmp.Height := 15;
  1137.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  1138.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  1139.        TempPicture.Bitmap );
  1140.       { Set the Objects list to the bitmap }
  1141.       Items.Objects[ i ] := TempBmp;
  1142.       { Free the icon each iteration; don't free the TempBmp as list does }
  1143.       TempIcon.Free;
  1144.     end;
  1145.     { Free the TPicture exchange element }
  1146.     TempPicture.Free;
  1147.     {------------------------ end custom code --------------------------------}
  1148.     Change;
  1149.   end;
  1150. end;
  1151.  
  1152. { Use this to respond to dbl-clicking FLB filename }
  1153. procedure TIconFileListBox.TheDblClick(Sender: TObject);
  1154. begin
  1155.   { Call shellexec as a wrapper around ShellExecute API call }
  1156.   { False indicates failure, signal error                    }
  1157.   if not ShellExec( ExpandFileName( Items[ ItemIndex ] ), '' , '', false ,
  1158.    SW_SHOWNORMAL , false ) then MessageDlg('Could not Shell out to ' +
  1159.     Items[ ItemIndex ] , mtError, [mbOK], 0);
  1160. end;
  1161.  
  1162. { Create method for FIP                                }
  1163. constructor TIconFileListBox.Create( AOwner : TComponent );
  1164. begin
  1165.   { call inherited -- VITAL! }
  1166.   inherited Create( AOwner );
  1167.   { set the mouse method }
  1168.   OnDblClick := TheDblClick;
  1169. end;
  1170.  
  1171. { Create method for FIP                                }
  1172. constructor TFileIconPanel.Create( AOwner : TComponent );
  1173. begin
  1174.   { call inherited -- VITAL! }
  1175.   inherited Create( AOwner );
  1176.   { create icon and label components, making self owner/displayer }
  1177.   FTheIcon := TIcon.Create;
  1178.   FTheLabel := TLabel.Create( Self );
  1179.   FThelabel.Parent := Self;
  1180.   { Set own and labels mouse methods to stored methods }
  1181.   OnMouseUp := TheMouseUp;
  1182.   OnMouseDown := TheMouseDown;
  1183.   OnDragOver := TheDragOver;
  1184.   OnDragDrop := TheDragDrop;
  1185.   { Set alignment and autosize properties of the label }
  1186.   FTheLabel.Autosize := false;
  1187.   FTheLabel.Alignment := taCenter;
  1188.   { Set selected to false }
  1189.   Selected := false;
  1190. end;
  1191.  
  1192. procedure TFileIconPanel.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1193. var CurrentDirectory : String;    { Use to store dirs }
  1194.     TheDrive         : String;    { Get drive letter  }
  1195.     WhichDrive       : Integer;   { Get drive number  }
  1196.     ErrorCheck       : Integer;
  1197.     TheFWB           : TFileWorkBench;
  1198. begin
  1199.   { Create FileWorkBench for later use }
  1200.   TheFWB := TFileWorkBench.Create( Self );
  1201.   { Check for label or FIP sender }
  1202.   if FTheLabel.Caption = '..' then
  1203.   begin { deal with backup request }
  1204.     { Change to new directory }
  1205.     TheFWB.ChangeTheDirectory( '..' );
  1206.     { Call special method due to SendMessage problem! }
  1207.     TFileIconPanelScrollBox( Parent ).Update;
  1208.   end
  1209.   else
  1210.   begin
  1211.     { Check for DRIVE id in name }
  1212.     if Pos( 'DRIVE' , FTheName ) <> 0 then
  1213.     begin { Double Click on a Drive Icon }
  1214.       { Pull out the letter from name }
  1215.       TheDrive := Copy( FtheName , 7 , 1 );
  1216.       { Convert it to a number }
  1217.       WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1218.       TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1219.       { Call special method due to SendMessage problem! }
  1220.       TFileIconPanelScrollBox( Parent ).Update;
  1221.     end
  1222.     else
  1223.     begin { Double click on a dir/file icon }
  1224.       if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1225.       begin { A directory, change to it }
  1226.         { Since full path in name, simply change to it! }
  1227.         TheFWB.ChangeTheDirectory( FTheName );
  1228.         { Call special method due to SendMessage problem! }
  1229.         TFileIconPanelScrollBox( Parent ).Update;
  1230.       end
  1231.       else
  1232.       begin { A file; attempt to shellexecute it }
  1233.         { Call shellexec as a wrapper around ShellExecute API call }
  1234.         { False indicates failure, signal error                    }
  1235.         if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1236.          then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1237.           [mbOK], 0);
  1238.       end;
  1239.     end;
  1240.   end;
  1241.   TheFWB.Free; { This prevents resource leak }
  1242. end;
  1243.  
  1244. { Initialization method for FIP                                         }
  1245. procedure TFileIconPanel.Initialize( PanelX              ,
  1246.                                      PanelY              ,
  1247.                                      PanelWidth          ,
  1248.                                      PanelHeight         ,
  1249.                                      PanelBevelWidth     ,
  1250.                                      LabelFontSize         : Integer;
  1251.                                      PanelColor          ,
  1252.                                      PanelHighlightColor ,
  1253.                                      PanelShadowColor    ,
  1254.                                      LabelTextColor        : TColor;
  1255.                                      TheFilename         ,
  1256.                                      LabelFontName         : String;
  1257.                                      LabelFontStyle        : TFontStyles;
  1258.                                      ExtraData             : Integer );
  1259.  
  1260. var TheLabelHeight ,             { Holder for label pixel height }
  1261.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1262.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1263. begin
  1264.   { Set the basic properties based on imported parameters }
  1265.   Left := PanelX;
  1266.   Top := PanelY;
  1267.   Width := PanelWidth;
  1268.   Height := PanelHeight;
  1269.   Color := PanelColor;
  1270.   BevelWidth := PanelBevelWidth;
  1271.   FHighlightColor := PanelHighlightColor;
  1272.   FShadowColor := PanelShadowColor;
  1273.   FTheName := TheFilename;
  1274.   { If the ExtraData field is non-0 then a drive is being sent in }
  1275.   if ExtraData <> 0 then
  1276.   begin
  1277.     { Use the data field value to determine which icon to get from RES file }
  1278.     case ExtraData of
  1279.       1 : begin
  1280.             GetMem( TheOtherPChar , 255 );
  1281.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  1282.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1283.             FreeMem( TheOtherPChar , 255 );
  1284.           end;
  1285.       2 : begin
  1286.             GetMem( TheOtherPChar , 255 );
  1287.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  1288.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1289.             FreeMem( TheOtherPChar , 255 );
  1290.           end;
  1291.       3 : begin
  1292.             GetMem( TheOtherPChar , 255 );
  1293.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  1294.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1295.             FreeMem( TheOtherPChar , 255 );
  1296.           end;
  1297.       4 : begin
  1298.             GetMem( TheOtherPChar , 255 );
  1299.             StrPCopy( TheOtherPChar , 'CDROM' );
  1300.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1301.             FreeMem( TheOtherPChar , 255 );
  1302.           end;
  1303.       5 : begin
  1304.             GetMem( TheOtherPChar , 255 );
  1305.             StrPCopy( TheOtherPChar , 'RAM' );
  1306.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1307.             FreeMem( TheOtherPChar , 255 );
  1308.           end;
  1309.     end;
  1310.     { The FileNme property is already set up for the caption; use directly }
  1311.     FTheLabel.Caption := TheFilename;
  1312.     { Set up the hint for later use (make sure to set ShowHint) }
  1313.     Hint := 'Change to ' + TheFileName;
  1314.     ShowHint := true;
  1315.     { Set up all imported label properties and center it for drawing }
  1316.     with FTheLabel do
  1317.     begin
  1318.       Font.Name := LabelFontName;
  1319.       Font.Size := LabelFontSize;
  1320.       Font.Style := LabelFontStyle;
  1321.       Font.Color := LabelTextColor;
  1322.       Canvas.Brush.Color := PanelColor;
  1323.       Canvas.Font := Font;
  1324.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  1325.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  1326.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  1327.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  1328.       Top := Top + Round( Self.Height * 0.75 );
  1329.       Height := TheLabelHeight;
  1330.       Width := TheLabelWidth;
  1331.     end;
  1332.   end
  1333.   else
  1334.   begin
  1335.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  1336.     { icon either from the file, its owner, or a RES file default.          }
  1337.     GetIconForFile( FTheName , FTheIcon );
  1338.     { Check for the Backup caption and set it specially }
  1339.     if ExtractfileName( FThename ) = '..' then
  1340.     begin
  1341.       FTheLabel.Caption := '..';
  1342.       Hint := 'Up One Level';
  1343.     end
  1344.     else
  1345.     begin
  1346.       { Otherwise just get the filename for the label caption }
  1347.       { And the full path for the hint (used later.)          }
  1348.       FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  1349.       Hint := FTheName;
  1350.     end;
  1351.     { Activate showhint so hints are seen }
  1352.     ShowHint := true;
  1353.     { Set label properties with imported values and center for display }
  1354.     with FTheLabel do
  1355.     begin
  1356.       Font.Name := LabelFontName;
  1357.       Font.Size := LabelFontSize;
  1358.       Font.Style := LabelFontStyle;
  1359.       Font.Color := LabelTextColor;
  1360.       Canvas.Brush.Color := PanelColor;
  1361.       Canvas.Font := Font;
  1362.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  1363.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  1364.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  1365.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  1366.       Top := Top + Round( Self.Height * 0.75 );
  1367.       Height := TheLabelHeight;
  1368.       Width := TheLabelWidth;
  1369.     end;
  1370.   end;
  1371. end;
  1372.  
  1373. { Destroy method for FIP }
  1374. destructor TFileIconPanel.Destroy;
  1375. begin
  1376.   { free component resources }
  1377.   FTheIcon.Free;
  1378.   FTheLabel.Free;
  1379.   { call inherited -- VITAL! }
  1380.   inherited Destroy;
  1381. end;
  1382.  
  1383. { Mousedown method for FIP; used to allow dragging }
  1384. procedure TFileIconPanel.TheMouseDown(Sender: TObject;
  1385.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1386. begin
  1387.   { Begin a conditional drag operation (false allows timer) }
  1388.   TheIOManager.WhichButton := Button;
  1389.   TheIOManager.WhichState := Shift;
  1390.   BeginDrag( false );
  1391.   { Currently ignore drive clicks }
  1392.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  1393.   { Flip status of bevels }
  1394.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  1395.    BevelOuter := bvRaised;
  1396.   { Flip selected variable }
  1397.   Selected := not Selected;
  1398.   { Set redisplay }
  1399. end;
  1400.  
  1401. { Mouseup Method for FIP; used to allow dragging }
  1402. procedure TFileIconPanel.TheMouseUp(Sender: TObject;
  1403.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1404. begin
  1405.   { End a drag operation without dropping; if dragged OK }
  1406.   { already handled.                                     }
  1407.   EndDrag( false );
  1408.   { If the right button is clicked, perform magic! }
  1409.   if Button = mbRight then
  1410.    TCCFileMgrForm( TFileIconPanelScrollbox( Parent ).
  1411.     TheParentForm ).BitBtn6Click( Self );
  1412.   { Redisplay on general principles }
  1413.   Invalidate;
  1414. end;
  1415.  
  1416. { Use this to generically OK DnD from FIPs }
  1417. procedure TFileIconPanel.TheDragOver(Sender, Source: TObject; X,
  1418.   Y: Integer; State: TDragState; var Accept: Boolean);
  1419. begin
  1420.   { Only accept from FileIconPanel components }
  1421.   if Source is TFileIconPanel then Accept := true else Accept := false;
  1422. end;
  1423.  
  1424. { Use this to accept Drag and Drop from other FIPs }
  1425. procedure TFileIconPanel.TheDragDrop(Sender, Source: TObject; X,
  1426.   Y: Integer);
  1427. var CurrentName ,                 { Holds work name}
  1428.     TheOldString : String;        { Holds Dir      }
  1429.     TargetDir    : String;        { target of op   }
  1430.     TheResult       : Integer;    { Modal res hold }
  1431.     SourceDirectory,
  1432.     TargetDirectory,
  1433.     CurrentDirectory : String;    { Use to store dirs }
  1434.     TheDrive         : String;    { Get drive letter  }
  1435.     WhichDrive       : Integer;   { Get drive number  }
  1436.     ErrorCheck       : Integer;
  1437.     TheFWB           : TFileWorkBench;
  1438.     ThePosition : Integer;
  1439.     Finished : Boolean;
  1440.     TheFIPSB : TFileIconPanelScrollBox;
  1441. begin
  1442.   { If drop target is .. then ignore }
  1443.   if FTheLabel.Caption = '..' then exit;
  1444.   { Likewise ignore Dnd from drive icons }
  1445.   if Pos( 'DRIVE' , TFileIconPanel( Source ).FtheName ) > 0 then exit;
  1446.   { Obtain the parent of the source FIP; may not be self }
  1447.   TheFIPSB := TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent );
  1448.   { Obtain source directory either as Dir or filepath }
  1449.   if (( FileGetAttr( TFileIconPanel( Source ).FTheName )
  1450.    and faDirectory ) = faDirectory ) then
  1451.   begin  { Directory; take whole path }
  1452.     SourceDirectory := TFileIconPanel( Source ).FTheName;
  1453.   end
  1454.   else
  1455.   begin { File; get pathname }
  1456.     SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  1457.   end;
  1458.   Sourcedirectory := TheFIPSB.TheFWB.ForceTrailingBackSlash( SourceDirectory );
  1459.   if Pos( 'DRIVE' , FTheName ) > 0 then
  1460.   begin { Drop onto a drive icon; perform action to its default dir }
  1461.     { Pull out the letter from name }
  1462.     TheDrive := Copy( FtheName , 7 , 1 );
  1463.     { Convert it to a number }
  1464.     WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1465.     { Determine the target directory and drive }
  1466.     GetDir( WhichDrive , TargetDirectory );
  1467.     TargetDirectory := TheFIPSB.TheFWB.ForceTrailingbackSlash( TargetDirectory );
  1468.     { Check for shift to operate on all selections }
  1469.     if TheIOManager.WasSHIFTPressed then
  1470.     begin { Operate on all selections }
  1471.       { Obtain the parent directory of the FIP dragged over }
  1472.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  1473.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  1474.       { If SourceDir subset of TargetDir then abort; recursive failure }
  1475.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  1476.       begin
  1477.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  1478.         exit;
  1479.       end;
  1480.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1481.       begin { Copy to different drives }
  1482.         if TheIOManager.WasALTPressed then
  1483.         begin { ALT overrides and does move }
  1484.           { Set up to get all current selections }
  1485.           ThePosition := 1;
  1486.           finished := false;
  1487.           while not finished do
  1488.           begin
  1489.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1490.                    ThePosition );
  1491.             { If returns blank string then out of selections }
  1492.             if CurrentName = '' then finished := true else
  1493.             begin
  1494.               { If a directory signal error }
  1495.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1496.               begin
  1497.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1498.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1499.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1500.                    TargetDirectory );
  1501.               end
  1502.               else
  1503.               begin
  1504.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1505.               end;
  1506.             end;
  1507.             { Reset to normal cursor }
  1508.             Screen.Cursor := crDefault;
  1509.           end;
  1510.         end
  1511.         else
  1512.         begin { Default is to do copy like file manager }
  1513.           { Set up to get all current selections }
  1514.           ThePosition := 1;
  1515.           finished := false;
  1516.           while not finished do
  1517.           begin
  1518.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1519.                    ThePosition );
  1520.             { If returns blank string then out of selections }
  1521.             if CurrentName = '' then finished := true else
  1522.             begin
  1523.               { If a directory signal error }
  1524.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1525.               begin
  1526.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1527.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1528.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1529.                    TargetDirectory );
  1530.               end
  1531.               else
  1532.               begin
  1533.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1534.               end;
  1535.             end;
  1536.             { Reset to normal cursor }
  1537.             Screen.Cursor := crDefault;
  1538.           end;
  1539.         end;
  1540.       end
  1541.       else
  1542.       begin { Copy to same drive }
  1543.         if TheIOManager.WasCTRLPressed then
  1544.         begin { CTRL overrides and does copy }
  1545.           { Set up to get all current selections }
  1546.           ThePosition := 1;
  1547.           finished := false;
  1548.           while not finished do
  1549.           begin
  1550.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1551.                    ThePosition );
  1552.             { If returns blank string then out of selections }
  1553.             if CurrentName = '' then finished := true else
  1554.             begin
  1555.               { If a directory signal error }
  1556.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1557.               begin
  1558.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1559.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1560.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1561.                    TargetDirectory );
  1562.               end
  1563.               else
  1564.               begin
  1565.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1566.               end;
  1567.             end;
  1568.             { Reset to normal cursor }
  1569.             Screen.Cursor := crDefault;
  1570.           end;
  1571.         end
  1572.         else
  1573.         begin { Default is to do move like file manager }
  1574.           { Set up to get all current selections }
  1575.           ThePosition := 1;
  1576.           finished := false;
  1577.           while not finished do
  1578.           begin
  1579.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1580.                    ThePosition );
  1581.             { If returns blank string then out of selections }
  1582.             if CurrentName = '' then finished := true else
  1583.             begin
  1584.               { If a directory signal error }
  1585.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1586.               begin
  1587.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1588.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1589.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1590.                    TargetDirectory );
  1591.               end
  1592.               else
  1593.               begin
  1594.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1595.               end;
  1596.             end;
  1597.             { Reset to normal cursor }
  1598.             Screen.Cursor := crDefault;
  1599.           end;
  1600.         end;
  1601.       end;
  1602.     end
  1603.     else
  1604.     begin { Operate on only source }
  1605.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1606.       begin { Copy to different drives }
  1607.         if TheIOManager.WasALTPressed then
  1608.         begin { ALT overrides and does move }
  1609.           with Source as TFileIconPanel do
  1610.           begin
  1611.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  1612.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1613.               TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  1614.           end;
  1615.         end
  1616.         else
  1617.         begin { Default is to do copy like file manager }
  1618.           with Source as TFileIconPanel do
  1619.           begin
  1620.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1621.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1622.               TheFIPSB.TheFWB.CopyTheFile( FtheName , TargetDirectory );
  1623.           end;
  1624.         end;
  1625.       end
  1626.       else
  1627.       begin { Copy to same drive }
  1628.         if TheIOManager.WasCTRLPressed then
  1629.         begin { CTRL overrides and does copy }
  1630.           with Source as TFileIconPanel do
  1631.           begin
  1632.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1633.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1634.               TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  1635.           end;
  1636.         end
  1637.         else
  1638.         begin { Default is to do move like file manager }
  1639.           with Source as TFileIconPanel do
  1640.           begin
  1641.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  1642.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1643.              TheFIPSB.TheFWB.MoveTheFile( FtheName , TargetDirectory );
  1644.           end;
  1645.         end;
  1646.       end;
  1647.     end;
  1648.   end
  1649.   else
  1650.   begin { Drop onto dir or file icon }
  1651.     if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1652.     begin { Drop onto a directory; use its path as target }
  1653.       TargetDirectory := FTheName;
  1654.     end
  1655.     else
  1656.     begin { Drop onto a file; use its parent as target }
  1657.       TargetDirectory := ExtractFilePath( FTheName );
  1658.     end;
  1659.     Targetdirectory := TheFIPSB.TheFWB.ForceTrailingbackslash( TargetDirectory );
  1660.     { Check for shift to operate on all selections }
  1661.     if TheIOManager.WasSHIFTPressed then
  1662.     begin { Operate on all selections }
  1663.       { Obtain the parent directory of the FIP dragged over }
  1664.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  1665.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  1666.       { If SourceDir subset of TargetDir then abort; recursive failure }
  1667.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  1668.       begin
  1669.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  1670.         exit;
  1671.       end;
  1672.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1673.       begin { Copy to different drives }
  1674.         if TheIOManager.WasALTPressed then
  1675.         begin { ALT overrides and does move }
  1676.           { Set up to get all current selections }
  1677.           ThePosition := 1;
  1678.           finished := false;
  1679.           while not finished do
  1680.           begin
  1681.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1682.                    ThePosition );
  1683.             { If returns blank string then out of selections }
  1684.             if CurrentName = '' then finished := true else
  1685.             begin
  1686.               { If a directory signal error }
  1687.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1688.               begin
  1689.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1690.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1691.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1692.                    TargetDirectory );
  1693.               end
  1694.               else
  1695.               begin
  1696.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1697.               end;
  1698.             end;
  1699.             { Reset to normal cursor }
  1700.             Screen.Cursor := crDefault;
  1701.           end;
  1702.         end
  1703.         else
  1704.         begin { Default is to do copy like file manager }
  1705.           { Set up to get all current selections }
  1706.           ThePosition := 1;
  1707.           finished := false;
  1708.           while not finished do
  1709.           begin
  1710.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1711.                    ThePosition );
  1712.             { If returns blank string then out of selections }
  1713.             if CurrentName = '' then finished := true else
  1714.             begin
  1715.               { If a directory signal error }
  1716.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1717.               begin
  1718.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1719.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1720.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1721.                    TargetDirectory );
  1722.               end
  1723.               else
  1724.               begin
  1725.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1726.               end;
  1727.             end;
  1728.             { Reset to normal cursor }
  1729.             Screen.Cursor := crDefault;
  1730.           end;
  1731.         end;
  1732.       end
  1733.       else
  1734.       begin { Copy to same drive }
  1735.         if TheIOManager.WasCTRLPressed then
  1736.         begin { CTRL overrides and does copy }
  1737.           { Set up to get all current selections }
  1738.           ThePosition := 1;
  1739.           finished := false;
  1740.           while not finished do
  1741.           begin
  1742.             { Call generic file getting routine based on current view}
  1743.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1744.                    ThePosition );
  1745.             { If returns blank string then out of selections }
  1746.             if CurrentName = '' then finished := true else
  1747.             begin
  1748.               { If a directory signal error }
  1749.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1750.               begin
  1751.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  1752.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1753.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  1754.                    TargetDirectory );
  1755.               end
  1756.               else
  1757.               begin
  1758.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  1759.               end;
  1760.             end;
  1761.             { Reset to normal cursor }
  1762.             Screen.Cursor := crDefault;
  1763.           end;
  1764.         end
  1765.         else
  1766.         begin { Default is to do move like file manager }
  1767.           { Set up to get all current selections }
  1768.           ThePosition := 1;
  1769.           finished := false;
  1770.           while not finished do
  1771.           begin
  1772.             { Call generic file getting routine based on current view}
  1773.               CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  1774.                    ThePosition );
  1775.             { If returns blank string then out of selections }
  1776.             if CurrentName = '' then finished := true else
  1777.             begin
  1778.               { If a directory signal error }
  1779.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  1780.               begin
  1781.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  1782.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1783.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  1784.                    TargetDirectory );
  1785.               end
  1786.               else
  1787.               begin
  1788.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  1789.               end;
  1790.             end;
  1791.             { Reset to normal cursor }
  1792.             Screen.Cursor := crDefault;
  1793.           end;
  1794.         end;
  1795.       end;
  1796.     end
  1797.     else
  1798.     begin { Operate on only source }
  1799.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  1800.       begin { Copy to different drives }
  1801.         if TheIOManager.WasALTPressed then
  1802.         begin { ALT overrides and does move }
  1803.           with Source as TFileIconPanel do
  1804.           begin
  1805.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1806.             begin
  1807.               if MessageDlg( 'Move Directory ' + FTheName + ' to ' +
  1808.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1809.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  1810.                  TargetDirectory );
  1811.             end
  1812.             else
  1813.             begin
  1814.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  1815.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1816.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  1817.             end;
  1818.           end;
  1819.         end
  1820.         else
  1821.         begin { Default is to do copy like file manager }
  1822.           with Source as TFileIconPanel do
  1823.           begin
  1824.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1825.             begin
  1826.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  1827.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1828.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  1829.                  TargetDirectory );
  1830.             end
  1831.             else
  1832.             begin
  1833.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1834.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1835.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  1836.             end;
  1837.           end;
  1838.         end;
  1839.       end
  1840.       else
  1841.       begin { Copy to same drive }
  1842.         if TheIOManager.WasCTRLPressed then
  1843.         begin { CTRL overrides and does copy }
  1844.           with Source as TFileIconPanel do
  1845.           begin
  1846.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1847.             begin
  1848.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  1849.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1850.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  1851.                  TargetDirectory );
  1852.             end
  1853.             else
  1854.             begin
  1855.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  1856.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1857.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  1858.             end;
  1859.           end;
  1860.         end
  1861.         else
  1862.         begin { Default is to do move like file manager }
  1863.           with Source as TFileIconPanel do
  1864.           begin
  1865.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1866.             begin
  1867.               if MessageDlg( 'Move Directory ' + FtheName + ' to ' +
  1868.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1869.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  1870.                  TargetDirectory );
  1871.             end
  1872.             else
  1873.             begin
  1874.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  1875.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1876.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  1877.             end;
  1878.           end;
  1879.         end;
  1880.       end;
  1881.     end;
  1882.   end;
  1883.   { Call special method due to SendMessage problem! }
  1884.   TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent ).Update;
  1885.   TFileIconPanelScrollBox( Parent ).Update;
  1886. end;
  1887.  
  1888. { Paint method for FIP; overrides normal paint }
  1889. procedure TFileIconPanel.Paint;
  1890. var
  1891.   TheOtherRect   : TRect;   { Holds clientrect   }
  1892.   TopColor     ,            { Holds bright color }
  1893.   BottomColor    : TColor;  { Holds dark color   }
  1894.  
  1895. { These methods are from Borland Intl., copyright 1995 }
  1896. procedure Frame3D(    Canvas       : TCanvas;
  1897.                   var TheRect      : TRect;
  1898.                       TopColor   ,
  1899.                       BottomColor  : TColor;
  1900.                       Width        : Integer );
  1901.  
  1902. procedure DoRect;
  1903. var
  1904.   TopRight, BottomLeft: TPoint;
  1905. begin
  1906.   with Canvas, TheRect do
  1907.   begin
  1908.     TopRight.X := Right;
  1909.     TopRight.Y := Top;
  1910.     BottomLeft.X := Left;
  1911.     BottomLeft.Y := Bottom;
  1912.     Pen.Color := TopColor;
  1913.     PolyLine([BottomLeft, TopLeft, TopRight]);
  1914.     Pen.Color := BottomColor;
  1915.     Dec(BottomLeft.X);
  1916.     PolyLine([TopRight, BottomRight, BottomLeft]);
  1917.   end;
  1918. end;
  1919.  
  1920. begin
  1921.   Canvas.Pen.Width := 1;
  1922.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  1923.   while Width > 0 do
  1924.   begin
  1925.     Dec(Width);
  1926.     DoRect;
  1927.     InflateRect(TheRect, -1, -1);
  1928.   end;
  1929.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  1930. end;
  1931.  
  1932. procedure AdjustColors(Bevel: TPanelBevel);
  1933. begin
  1934.   TopColor := FHighlightColor;
  1935.   if Bevel = bvLowered then TopColor := FShadowColor;
  1936.   BottomColor := FShadowColor;
  1937.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  1938. end;
  1939.  
  1940. { Custom code begins here }
  1941. begin
  1942.   { Get the rectangle of the control with API/method call }
  1943.   TheOtherRect := GetClientRect;
  1944.   { draw basic rectangle with basic color }
  1945.   with Canvas do
  1946.   begin
  1947.     Brush.Color := Color;
  1948.     FillRect(TheOtherRect);
  1949.   end;
  1950.   { Set up for top "icon" frame  and draw it with frame3d }
  1951.   TheOtherRect.Right := Width;
  1952.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  1953.   if BevelOuter <> bvNone then
  1954.   begin
  1955.     AdjustColors(BevelOuter);
  1956.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1957.   end;
  1958.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1959.   if BevelInner <> bvNone then
  1960.   begin
  1961.     AdjustColors(BevelInner);
  1962.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1963.   end;
  1964.   { Do the same for the lower "label" frame }
  1965.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  1966.   TheOtherRect.Left := 0;
  1967.   TheOtherRect.Bottom := Height;
  1968.   TheOtherRect.Right := Width;
  1969.   if BevelOuter <> bvNone then
  1970.   begin
  1971.     AdjustColors(BevelOuter);
  1972.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1973.   end;
  1974.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1975.   if BevelInner <> bvNone then
  1976.   begin
  1977.     AdjustColors(BevelInner);
  1978.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1979.   end;
  1980.   { Then draw the icon using canvas draw method }
  1981.   Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  1982.   ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  1983. end;
  1984.  
  1985. { This procedure clears a scrollbox of all FileIconPanels }
  1986. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  1987. var Counter_1 : Integer;
  1988.     TheComponent : TComponent;
  1989. begin
  1990.   { Note that must use while loop since component count continually }
  1991.   { decreases as removes are made!                                  }
  1992.   while ComponentCount > 0 do
  1993.   begin
  1994.     { Save the component as a generic TComponent }
  1995.     TheComponent := Components[ 0 ];
  1996.     { Call removecomponent to pull it out of the owner list for sb }
  1997.     { This avoids GPF when freeing the sb.                         }
  1998.     RemoveComponent( Components[ 0 ]);
  1999.     if ControlCount > 0 then
  2000.      RemoveControl( Controls[ 0 ] );
  2001.     { Typecast the pointer and free it to release memory and res. }
  2002.     TheParentForm.InsertComponent( TheComponent );
  2003.   end;
  2004. end;
  2005.  
  2006. { This procedure scans for drives and obtains their type and creates file }
  2007. { icon panels to represent them.                                          }
  2008. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  2009.            YCounter : Integer );
  2010. type
  2011.   { This if from filectrl unit; reproduce here for completeness }
  2012.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  2013.                 dtRAM);
  2014. var
  2015.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  2016.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  2017.   DriveChar       : Char;            { Used to hold drive letter           }
  2018.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  2019.   Finished        : Boolean;         { Loop flag                           }
  2020.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  2021.   ButtonColor   ,                    { Main panel color                    }
  2022.   ButtonHLColor ,                    { Bright panel color                  }
  2023.   ButtonSColor  ,                    { Dark panel color                    }
  2024.   Textcolor       : TColor;          { Label text color                    }
  2025.  
  2026. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2027. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  2028. {  and the drive is using a CD driver                                   }
  2029.  
  2030. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  2031. asm
  2032.   MOV   AX,1500h { look for MSCDEX }
  2033.   XOR   BX,BX
  2034.   INT   2fh
  2035.   OR    BX,BX
  2036.   JZ    @Finish
  2037.   MOV   AX,150Bh { check for using CD driver }
  2038.   MOV   CX,DriveNum
  2039.   INT   2fh
  2040.   OR    AX,AX
  2041.   @Finish:
  2042. end;
  2043.  
  2044. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2045. { Check whether drive is a RAM drive.                                   }
  2046. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  2047. var
  2048.   TempResult: Boolean;
  2049. asm
  2050.   MOV   TempResult,False
  2051.   PUSH  DS
  2052.   MOV   BX,SS
  2053.   MOV   DS,BX
  2054.   SUB   SP,0200h
  2055.   MOV   BX,SP
  2056.   MOV   AX,DriveNum
  2057.   MOV   CX,1
  2058.   XOR   DX,DX
  2059.   INT   25h  { read boot sector }
  2060.   ADD   SP,2
  2061.   JC    @ItsNot
  2062.   MOV   BX,SP
  2063.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  2064.   JNE   @ItsNot
  2065.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  2066.   JNE   @ItsNot
  2067.   MOV   TempResult,True
  2068.   @ItsNot:
  2069.   ADD   SP,0200h
  2070.   POP   DS
  2071.   MOV   AL, TempResult
  2072. end;
  2073.  
  2074. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2075. { Finds the type of a drive letter.                                     }
  2076. function FindDriveType(DriveNum: Integer): TDriveType;
  2077. begin
  2078.   Result := TDriveType(GetDriveType(DriveNum));
  2079.   if (Result = dtFixed) or (Result = dtNetwork) then
  2080.   begin
  2081.     if IsCDROM(DriveNum) then Result := dtCDROM
  2082.     else if (Result = dtFixed) then
  2083.     begin
  2084.         { do not check for RAMDrive under Windows NT }
  2085.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  2086.         Result := dtRAM;
  2087.     end;
  2088.   end;
  2089. end;
  2090.  
  2091. begin
  2092.   { Set the button colors to an aquamarine color scheme for drives }
  2093.   ButtonColor := clTeal;
  2094.   ButtonHLColor := clAqua;
  2095.   ButtonSColor := clNavy;
  2096.   TextColor := clblack;
  2097.   { Set initial variables before looping for all drives }
  2098.   finished := false;
  2099.   DriveNum := 0;
  2100.   while not finished do
  2101.   begin
  2102.     { Start with no drive found }
  2103.     IconType := 0;
  2104.     { Call the Borland method to get the drive info }
  2105.     DriveType := FindDriveType(DriveNum);
  2106.     { Set its letter and make it uppercase }
  2107.     DriveChar := Chr(DriveNum + ord('a'));
  2108.     DriveChar := Upcase(DriveChar);
  2109.     { Assign an icon based on the drive type; if no drive exists type is nil }
  2110.     case DriveType of
  2111.       dtFloppy  : IconType := 1;
  2112.       dtFixed   : IconType := 2;
  2113.       dtNetwork : IconType := 3;
  2114.       dtCDROM   : IconType := 4;
  2115.       dtRAM     : IconType := 5;
  2116.     end;
  2117.     { Set to check next drive letter }
  2118.     DriveNum := DriveNum + 1;
  2119.     { But if no match then out of drives so set exit flag }
  2120.     if IconType = 0 then finished := true;
  2121.     { If drive was valid then set up the new FileIconPanel on the imported }
  2122.     { Scrollbox                                                            }
  2123.     if not finished then
  2124.     begin
  2125.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  2126.       TheFIP := TFileIconPanel.Create( Self );
  2127.       TheFIP.Parent := Self;
  2128.       { Call its initialize method with imported position values and the   }
  2129.       { preset color scheme, a drive caption, and a minimum font. Note the }
  2130.       { setting of the ExtraData field to non-zero; this signals a drive   }
  2131.       { rather than a file being sent in.                                  }
  2132.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2133.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2134.         7 , ButtonColor, ButtonHLColor,
  2135.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  2136.        IconType );
  2137.       { Increment the column counter; if it exceeds max move to new row      }
  2138.       { Note that these are 'var' parameters and will export final position. }
  2139.       XCounter := XCounter + 1;
  2140.       if XCounter > MaxIconsInARow then
  2141.       begin
  2142.         XCounter := 1;
  2143.         YCounter := YCounter + 1;
  2144.       end;
  2145.     end;
  2146.   end;
  2147. end;
  2148.  
  2149. { This procedure assigns colors to FIP's based on file attributes }
  2150. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  2151.            var BC , HC , SC , TC : TColor );
  2152. var AmADir      ,             { Booleans hold file attribs }
  2153.     AmAnArchive ,
  2154.     AmAVolumeId ,
  2155.     AmHidden    ,
  2156.     AmReadOnly  ,
  2157.     AmSystem      : Boolean;
  2158. begin
  2159.   { Make the call to internal fileworkbench to set attributes }
  2160.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  2161.    AmHidden , AmReadOnly , AmSystem );
  2162.   { Volume ID has no subtypes }
  2163.   if AmAVolumeID then
  2164.   begin
  2165.     BC := clOlive;
  2166.     HC := clYellow;
  2167.     SC := clBlack;
  2168.     TC := clWhite;
  2169.     exit;
  2170.   end;
  2171.   { Check all directory combinations }
  2172.   if AmADir then
  2173.   begin
  2174.     BC := clNavy;
  2175.     HC := clBlue;
  2176.     SC := clBlack;
  2177.     TC := clWhite;
  2178.     if AmHidden then
  2179.     begin
  2180.       if AmReadOnly then
  2181.       begin
  2182.         if AmSystem then
  2183.         begin { One HECK of a file! }
  2184.           BC := clBlack;
  2185.           HC := clSilver;
  2186.           SC := clGray;
  2187.           TC := clWhite;
  2188.         end
  2189.         else
  2190.         begin { Dir,RO,Hid }
  2191.           BC := clMaroon;
  2192.           HC := clFuchsia;
  2193.           SC := clGreen;
  2194.           TC := clWhite;
  2195.         end;
  2196.       end
  2197.       else
  2198.       begin { Dir,Hid }
  2199.         BC := clPurple;
  2200.         HC := clFuchsia;
  2201.         SC := clBlack;
  2202.         TC := clWhite;
  2203.       end;
  2204.     end
  2205.     else
  2206.     begin
  2207.       if AmReadOnly then
  2208.       begin
  2209.         if AmSystem then
  2210.         begin { Dir,RO,Sys }
  2211.           BC := clMaroon;
  2212.           HC := clLime;
  2213.           SC := clGreen;
  2214.           TC := clWhite;
  2215.         end
  2216.         else
  2217.         begin { Dir,RO }
  2218.           BC := clGreen;
  2219.           HC := clLime;
  2220.           SC := clBlack;
  2221.           TC := clWhite;
  2222.         end;
  2223.       end
  2224.       else
  2225.       begin
  2226.         if AmSystem then
  2227.         begin { Dir,Sys }
  2228.           BC := clMaroon;
  2229.           HC := clRed;
  2230.           SC := clBlack;
  2231.           TC := clWhite;
  2232.         end;
  2233.       end;
  2234.     end;
  2235.   end
  2236.   else { Archive Only; check all combinations }
  2237.   begin
  2238.     BC := clSilver;
  2239.     HC := clWhite;
  2240.     SC := clGray;
  2241.     TC := clBlack;
  2242.     if AmHidden then
  2243.     begin
  2244.       if AmReadOnly then
  2245.       begin
  2246.         if AmSystem then
  2247.         begin { Hid,RO,Sys }
  2248.           BC := clRed;
  2249.           HC := clLime;
  2250.           SC := clPurple;
  2251.           TC := clBlack;
  2252.         end
  2253.         else
  2254.         begin { RO,Hid }
  2255.           BC := clLime;
  2256.           HC := clFuchsia;
  2257.           SC := clMaroon;
  2258.           TC := clBlack;
  2259.         end;
  2260.       end
  2261.       else
  2262.       begin { Hid }
  2263.         BC := clFuchsia;
  2264.         HC := clWhite;
  2265.         SC := clPurple;
  2266.         TC := clBlack;
  2267.       end;
  2268.     end
  2269.     else
  2270.     begin
  2271.       if AmReadOnly then
  2272.       begin
  2273.         if AmSystem then
  2274.         begin { RO,Sys }
  2275.           BC := clRed;
  2276.           HC := clLime;
  2277.           SC := clMaroon;
  2278.           TC := clBlack;
  2279.         end
  2280.         else
  2281.         begin { RO }
  2282.           BC := clLime;
  2283.           HC := clWhite;
  2284.           SC := clGreen;
  2285.           TC := clBlack;
  2286.         end;
  2287.       end
  2288.       else
  2289.       begin
  2290.         if AmSystem then
  2291.         begin { System }
  2292.           BC := clRed;
  2293.           HC := clWhite;
  2294.           SC := clMaroon;
  2295.           TC := clBlack;
  2296.         end;
  2297.       end;
  2298.     end;
  2299.   end;
  2300. end;
  2301.  
  2302. { This procedure gets all icons for an given directory, including drives and }
  2303. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  2304. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  2305.             TargetPath  : String );
  2306. var Finished        : Boolean;         { Loop flag              }
  2307.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  2308.     TheResult       : Integer;         { return variable        }
  2309.     TempPath        : String;          { path for FF/FN         }
  2310.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  2311.     RowCounter    ,                    { position in row of FIP }
  2312.     ColumnCounter   : Integer;         { position in col of FIP }
  2313.     ButtonColor   ,                    { main panel color       }
  2314.     ButtonHLColor ,                    { bright panel color     }
  2315.     ButtonSColor  ,                    { dark panel color       }
  2316.     Textcolor       : TColor;          { label text color       }
  2317.     IsADir ,                           { Variable for file attr }
  2318.     IsAnArchive ,
  2319.     IsAVolumeID,
  2320.     IsAReadOnlyFile,
  2321.     IsAHiddenFile ,
  2322.     IsASystemFile     : Boolean;
  2323.     MaxTextLength     : Integer;       { Used to safely set size}
  2324. begin
  2325.   { hide during refresh }
  2326.   Visible := false;
  2327.   { Get the icon sizes }
  2328.   TheFIP := TFileIconPanel.Create( Self );
  2329.   TheFIP.Parent := Self;
  2330.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  2331.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  2332.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  2333.   TheFIP.Free;
  2334.   TheIconSize := MaxTextLength + 13;
  2335.   TheIconSpacing := TheIconSize + 5;
  2336.   { Set up maximum icons per row based on screen size }
  2337.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  2338.   { Set up the position counters }
  2339.   RowCounter := 1;
  2340.   ColumnCounter := 1;
  2341.   { Get the drives for the current machine }
  2342.   AddDriveIcons( ColumnCounter , RowCounter  );
  2343.   { Set up the initial variables }
  2344.   Finished := false;
  2345.   TempPath := TargetPath + '*.*';
  2346.   { Make the call to FindFirst set to get any file; will return '.' }
  2347.   { so discard it.                                                  }
  2348.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  2349.   { loop through all files in the directory and look for directories }
  2350.   while not Finished do
  2351.   begin
  2352.     { Make call to FindNext, using only SearchRecord from FindFirst }
  2353.     TheResult := FindNext( TheSR );
  2354.     { A -1 result means no more files so exit }
  2355.     if TheResult < 0 then finished := true else
  2356.     begin
  2357.       { Otherwise check for a directory attribute }
  2358.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  2359.        faDirectory ) then
  2360.       begin
  2361.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2362.          ButtonHLColor , ButtonSColor , TextColor );
  2363.         { If found create a new FileIconPanel on the imported scrollbox }
  2364.         { Note sending 0 ExtraData parameter to indicate file not drive }
  2365.         TheFIP := TFileIconPanel.Create( Self );
  2366.         TheFIP.Parent := Self;
  2367.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  2368.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  2369.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2370.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2371.         { Increment column counter and move to new row if past limit }
  2372.         ColumnCounter := ColumnCounter + 1;
  2373.         if ColumnCounter > MaxIconsInARow then
  2374.         begin
  2375.           ColumnCounter := 1;
  2376.           RowCounter := RowCounter + 1;
  2377.         end;
  2378.       end;
  2379.     end;
  2380.   end;
  2381.   { Call FindClose for Windows NT/Windows 95 compatibility }
  2382.   FindClose( TheSR );
  2383.   { Set up new initialization variables }
  2384.   Finished := false;
  2385.   TempPath := TargetPath + '*.*';
  2386.   { Make needed call to FindFirst and discard '.' }
  2387.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  2388.   while not Finished do
  2389.   begin
  2390.     { Loop through file again, this time getting only archive files }
  2391.     TheResult := FindNext( TheSR );
  2392.     { Result of -1 indicates no more files }
  2393.     if TheResult < 0 then Finished := true else
  2394.     begin
  2395.       { If faArchive file then add new FileIconPanel }
  2396.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  2397.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  2398.         IsASystemFile );
  2399.       if (( IsAnArchive ) and ( not IsADir )) then
  2400.       begin
  2401.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2402.          ButtonHLColor , ButtonSColor , TextColor );
  2403.         { Initialize new FileIconPanel and call initialize, sending 0 ED }
  2404.         TheFIP := TFileIconPanel.Create( Self );
  2405.         TheFIP.Parent := Self;
  2406.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  2407.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  2408.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2409.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2410.         { Increment column counter and if needed row counter }
  2411.         ColumnCounter := ColumnCounter + 1;
  2412.         if ColumnCounter > MaxIconsInARow then
  2413.         begin
  2414.           ColumnCounter := 1;
  2415.           RowCounter := RowCounter + 1;
  2416.         end;
  2417.       end;
  2418.     end;
  2419.   end;
  2420.   { Call findclose for w95 and exit }
  2421.   FindClose( TheSR );
  2422.   { Reset to visible }
  2423.   Visible := true;
  2424. end;
  2425.  
  2426. { Update method for FIPscrollbox }
  2427. procedure TFileIconPanelScrollBox.Update;
  2428. begin
  2429.   IconsNeedRefreshing := true;
  2430.   { Force a repaint }
  2431.   InvalidateRect( TheStoredHandle , nil , true );
  2432. end;
  2433.  
  2434. { Create method for FIPScrollbox }
  2435. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  2436. begin
  2437.   inherited Create( AOwner );
  2438.   TheFWB := TFileWorkBench.Create( Self );
  2439. end;
  2440.  
  2441. { This function returns the next selected file's name }
  2442. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  2443.                            var CurrentItem : Integer ) : String;
  2444. var TheResult    : String;      { Holds result of function }
  2445.     TheComponent : TComponent;  { Used for typecast        }
  2446.     finished     : boolean;     { Loop control variable    }
  2447.     TheComponentCount : Integer;
  2448. begin
  2449.   TheComponentCount := ComponentCount;
  2450.   { If past end of components exit with no result }
  2451.   if CurrentItem > TheComponentCount then TheResult := '' else
  2452.   begin
  2453.     { Set loop counter and run till find match or run out }
  2454.     finished := false;
  2455.     while not finished do
  2456.     begin
  2457.       { Pull component out of the list and check it }
  2458.       TheComponent := Components[ CurrentItem - 1 ];
  2459.       { Increment counter for later }
  2460.       CurrentItem := CurrentItem + 1;
  2461.       { Do the typecast with AS }
  2462.       if TheComponent is TFileIconPanel then
  2463.       with TheComponent as TFileIconPanel do
  2464.       begin
  2465.         { If its selected make sure OK }
  2466.         if Selected then
  2467.         begin
  2468.           { Don't accept backup for this level of operation }
  2469.           if FTheLabel.Caption <> '..' then
  2470.           begin
  2471.             { Otherwise return the name and abort the loop }
  2472.             TheResult := FTheName;
  2473.             finished := true;
  2474.           end;
  2475.         end
  2476.         else
  2477.         begin
  2478.           { Check to see if out of components }
  2479.           if CurrentItem > TheComponentCount then
  2480.           begin
  2481.             { If so signal error and abort }
  2482.             TheResult := '';
  2483.             finished := true;
  2484.           end;
  2485.         end;
  2486.       end;
  2487.     end;
  2488.   end;
  2489.   GetNextSelection := TheResult;
  2490. end;
  2491.  
  2492. { This procedure places a selection of files in the display based on wildcards }
  2493. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  2494.            TheStartingDirectory : String );
  2495. var XCounter ,
  2496.     YCounter   : Integer;
  2497.  
  2498. { This procedure does a recursive file search by first getting all matches (in-}
  2499. { cluding directories) and adding them to the list. Then it checks for ALL the }
  2500. { subdirectories and does the same trick on them til there are no more matches }
  2501. { and no more subdirectories, at which point it exits and recurses back up.    }
  2502. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  2503.                                YCounter : Integer );
  2504.  
  2505. { VITAL!!! These variables MUST be local for recursrion to work! }
  2506. var
  2507.     Finished        : Boolean;         { Loop flag              }
  2508.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  2509.     TheResult       : Integer;         { return variable        }
  2510.     TargetPath ,
  2511.     FileMask   ,
  2512.     TheStoredWorkingDirectory ,
  2513.     ModifiedDirectory  : String;       { path for FF/FN         }
  2514.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  2515.     ButtonColor   ,                    { main panel color       }
  2516.     ButtonHLColor ,                    { bright panel color     }
  2517.     ButtonSColor  ,                    { dark panel color       }
  2518.     Textcolor       : TColor;          { label text color       }
  2519.  
  2520. begin
  2521.   { Jump out if abort pressed }
  2522.   if GlobalAbortFlag then exit;
  2523.   { Set up the initial variables }
  2524.   Finished := false;
  2525.   TheStoredWorkingDirectory := TheWorkingDirectory;
  2526.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  2527.   FileMask := ExtractFileName( TheWorkingDirectory );
  2528.   { Make the call to FindFirst set to get any file }
  2529.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  2530.   if TheResult < 0 then finished := true;
  2531.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  2532.   then begin
  2533.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  2534.      faDirectory ) then
  2535.     begin { A directory }
  2536.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2537.        ButtonHLColor , ButtonSColor , TextColor );
  2538.       { If found create a new FileIconPanel on the imported scrollbox }
  2539.       { Note sending 0 ExtraData parameter to indicate file not drive }
  2540.       TheFIP := TFileIconPanel.Create( Self );
  2541.       TheFIP.Parent := Self;
  2542.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2543.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2544.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  2545.          + TheSr.Name , 'MS Serif' , [] , 0 );
  2546.       { Increment column counter and move to new row if past limit }
  2547.       XCounter := XCounter + 1;
  2548.       if XCounter > MaxIconsInARow then
  2549.       begin
  2550.         XCounter := 1;
  2551.         YCounter := YCounter + 1;
  2552.       end;
  2553.     end
  2554.     else
  2555.     begin { A File }
  2556.       { Set up the default color scheme for files }
  2557.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2558.        ButtonHLColor , ButtonSColor , TextColor );
  2559.       { If found create a new FileIconPanel on the imported scrollbox }
  2560.       { Note sending 0 ExtraData parameter to indicate file not drive }
  2561.       TheFIP := TFileIconPanel.Create( Self );
  2562.       TheFIP.Parent := Self;
  2563.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2564.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  2565.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  2566.          + TheSr.Name , 'MS Serif' , [] , 0 );
  2567.       { Increment column counter and move to new row if past limit }
  2568.       XCounter := XCounter + 1;
  2569.       if XCounter > MaxIconsInARow then
  2570.       begin
  2571.         XCounter := 1;
  2572.         YCounter := YCounter + 1;
  2573.       end;
  2574.     end;
  2575.   end;
  2576.   { loop through all files in the directory and look for matches }
  2577.   while not Finished do
  2578.   begin
  2579.     { Allow keyboard processing and jump out if c-break hit }
  2580.     Application.ProcessMessages;
  2581.     if GlobalAbortFlag then exit;
  2582.     { Make call to FindNext, using only SearchRecord from FindFirst }
  2583.     TheResult := FindNext( TheSR );
  2584.     { A -1 result means no more files so exit }
  2585.     if TheResult < 0 then finished := true else
  2586.     begin
  2587.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  2588.        faDirectory ) then
  2589.       begin { A directory }
  2590.         { Set up the blue color scheme for directories }
  2591.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2592.          ButtonHLColor , ButtonSColor , TextColor );
  2593.         { If found create a new FileIconPanel on the imported scrollbox }
  2594.         { Note sending 0 ExtraData parameter to indicate file not drive }
  2595.         TheFIP := TFileIconPanel.Create( Self );
  2596.         TheFIP.Parent := Self;
  2597.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2598.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2599.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2600.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2601.         { Increment column counter and move to new row if past limit }
  2602.         XCounter := XCounter + 1;
  2603.         if XCounter > MaxIconsInARow then
  2604.         begin
  2605.           XCounter := 1;
  2606.           YCounter := YCounter + 1;
  2607.         end;
  2608.       end
  2609.       else
  2610.       begin { A File }
  2611.         { Set up the default color scheme for files }
  2612.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  2613.          ButtonHLColor , ButtonSColor , TextColor );
  2614.         { If found create a new FileIconPanel on the imported scrollbox }
  2615.         { Note sending 0 ExtraData parameter to indicate file not drive }
  2616.         TheFIP := TFileIconPanel.Create( Self );
  2617.         TheFIP.Parent := Self;
  2618.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2619.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2620.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  2621.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  2622.         { Increment column counter and move to new row if past limit }
  2623.         XCounter := XCounter + 1;
  2624.         if XCounter > MaxIconsInARow then
  2625.         begin
  2626.           XCounter := 1;
  2627.           YCounter := YCounter + 1;
  2628.         end;
  2629.       end;
  2630.     end;
  2631.   end;
  2632.   { Call FindClose for Windows NT/Windows 95 compatibility }
  2633.   FindClose( TheSR );
  2634.   { Set up the variables to do recursive calls on all directories}
  2635.   Finished := false;
  2636.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  2637.   { Make the call to FindFirst set to get any file, ignore result }
  2638.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  2639.   while not Finished do
  2640.   begin
  2641.     { Allow keyboard input and jump out if c-break hit }
  2642.     Application.ProcessMessages;
  2643.     if GlobalAbortFlag then exit;
  2644.     { Make call to FindNext, using only SearchRecord from FindFirst }
  2645.     TheResult := FindNext( TheSR );
  2646.     { A -1 result means no more files so exit }
  2647.     if TheResult < 0 then finished := true
  2648.     else
  2649.     begin
  2650.       if TheSR.Name <> '..' then { Ignore backup in this case }
  2651.       begin
  2652.         { Do second check due to bug in FindNext }
  2653.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  2654.         = faDirectory ) then
  2655.         begin
  2656.           { Set up modified directory to recurse into }
  2657.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  2658.            TheSR.Name + '\' + FileMask;
  2659.           { Perform the recursion }
  2660.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  2661.         end;
  2662.       end;
  2663.     end;
  2664.   end;
  2665. end;
  2666.  
  2667. begin
  2668.   { Keep the scrollbox from updating during refresh }
  2669.   Visible := false;
  2670.   { Make the clear call }
  2671.   ClearTheFIPs;
  2672.   XCounter := 1;
  2673.   YCounter := 1;
  2674.   { Get the drives for the current machine }
  2675.   AddDriveIcons( XCounter , YCounter );
  2676.   { Clear the global abort flag prior to processing }
  2677.   GlobalAbortFlag := false;
  2678.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  2679.   { Make the scrollbox visible again }
  2680.   Visible := true;
  2681. end;
  2682.  
  2683. end.
  2684.