Rxdirfrm.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 1998 Master-Bank                }
  6. {                                                       }
  7. {*******************************************************}
  8. unit RxDirFrm;
  9. interface
  10. uses {$IFDEF WIN32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF} Messages,
  11.   SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, RXCtrls,
  12.   Placemnt;
  13. type
  14.   TDirectoryListDialog = class(TForm)
  15.     DirectoryList: TTextListBox;
  16.     AddBtn: TButton;
  17.     RemoveBtn: TButton;
  18.     ModifyBtn: TButton;
  19.     OKBtn: TButton;
  20.     CancelBtn: TButton;
  21.     Storage: TFormStorage;
  22.     procedure AddBtnClick(Sender: TObject);
  23.     procedure ModifyBtnClick(Sender: TObject);
  24.     procedure RemoveBtnClick(Sender: TObject);
  25.     procedure DirectoryListClick(Sender: TObject);
  26.     procedure FormShow(Sender: TObject);
  27.     procedure DirectoryListDragDrop(Sender, Source: TObject; X,
  28.       Y: Integer);
  29.     procedure DirectoryListDragOver(Sender, Source: TObject; X, Y: Integer;
  30.       State: TDragState; var Accept: Boolean);
  31.     procedure FormCreate(Sender: TObject);
  32.   private
  33.     { Private declarations }
  34.     procedure CheckButtons;
  35.   public
  36.     { Public declarations }
  37.   end;
  38. function EditFolderList(Folders: TStrings): Boolean;
  39. implementation
  40. uses FileUtil, BoxProcs, RxConst;
  41. {$R *.DFM}
  42. function EditFolderList(Folders: TStrings): Boolean;
  43. begin
  44.   with TDirectoryListDialog.Create(Application) do
  45.   try
  46.     if Assigned(Folders) then
  47.       DirectoryList.Items.Assign(Folders);
  48.     Result := ShowModal = mrOk;
  49.     if Result and Assigned(Folders) then
  50.       Folders.Assign(DirectoryList.Items);
  51.   finally
  52.     Free;
  53.   end;
  54. end;
  55. { TDirectoryListDialog }
  56. procedure TDirectoryListDialog.CheckButtons;
  57. begin
  58.   ModifyBtn.Enabled := (DirectoryList.Items.Count > 0) and
  59.     (DirectoryList.ItemIndex >= 0);
  60.   RemoveBtn.Enabled := ModifyBtn.Enabled;
  61. end;
  62. procedure TDirectoryListDialog.AddBtnClick(Sender: TObject);
  63. var
  64.   I: Integer;
  65.   S: string;
  66. begin
  67.   S := '';
  68.   if BrowseDirectory(S, '', 0) then begin
  69.     I := DirectoryList.Items.Add(S);
  70.     DirectoryList.ItemIndex := I;
  71.     CheckButtons;
  72.   end;
  73. end;
  74. procedure TDirectoryListDialog.ModifyBtnClick(Sender: TObject);
  75. var
  76.   I: Integer;
  77.   S: string;
  78. begin
  79.   I := DirectoryList.ItemIndex;
  80.   if I >= 0 then begin
  81.     S := DirectoryList.Items[I];
  82.     if BrowseDirectory(S, '', 0) then begin
  83.       DirectoryList.Items[I] := S;
  84.     end;
  85.   end;
  86. end;
  87. procedure TDirectoryListDialog.RemoveBtnClick(Sender: TObject);
  88. var
  89.   I: Integer;
  90. begin
  91.   I := DirectoryList.ItemIndex;
  92.   if I >= 0 then begin
  93.     DirectoryList.Items.Delete(I);
  94.     CheckButtons;
  95.   end;
  96. end;
  97. procedure TDirectoryListDialog.DirectoryListClick(Sender: TObject);
  98. begin
  99.   CheckButtons;
  100. end;
  101. procedure TDirectoryListDialog.FormShow(Sender: TObject);
  102. begin
  103.   CheckButtons;
  104. end;
  105. procedure TDirectoryListDialog.DirectoryListDragDrop(Sender,
  106.   Source: TObject; X, Y: Integer);
  107. begin
  108.   BoxMoveFocusedItem(DirectoryList, DirectoryList.ItemAtPos(Point(X, Y), True));
  109.   CheckButtons;
  110. end;
  111. procedure TDirectoryListDialog.DirectoryListDragOver(Sender,
  112.   Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  113. begin
  114.   BoxDragOver(DirectoryList, Source, X, Y, State, Accept, DirectoryList.Sorted);
  115.   CheckButtons;
  116. end;
  117. procedure TDirectoryListDialog.FormCreate(Sender: TObject);
  118. begin
  119. {$IFDEF WIN32}
  120.   with Storage do begin
  121.     UseRegistry := True;
  122.     IniFileName := SDelphiKey;
  123.   end;
  124. {$ELSE}
  125.   if not NewStyleControls then Font.Style := [fsBold];
  126. {$ENDIF}
  127. end;
  128. end.