Advertisement
Guest User

classe

a guest
Sep 5th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. unit uUtils.Dialog;
  2.  
  3. interface uses
  4.  
  5. Vcl.Dialogs,
  6. Vcl.FileCtrl,
  7. System.SysUtils,
  8. IOUtils;
  9.  
  10. type
  11. TDialogService = Class
  12. public
  13. class function ShowFileDialog(AFilter,ADefaultExt:String):String; overload;
  14. class function ShowFileDialog(ATitle,AInitialDir, AFilter, ADefaultExt:String):String; overload;
  15. class function SelectFolder(APath:String):String;
  16.  
  17. End;
  18.  
  19. implementation
  20.  
  21. const
  22. SELDIRHELP = 1000;
  23.  
  24.  
  25.  
  26. { TDialogService }
  27.  
  28. class function TDialogService.ShowFileDialog(AFilter, ADefaultExt: String): String;
  29. begin
  30. result := TDialogService.ShowFileDialog(' Selecione um Arquivo. ',
  31. TDirectory.GetCurrentDirectory(),
  32. AFilter,ADefaultExt);
  33. end;
  34.  
  35. class function TDialogService.SelectFolder(APath: String): String;
  36. var
  37. lDir: string;
  38. begin
  39. result := '';
  40. if Length(APath) <= 0 then
  41. lDir := TDirectory.GetCurrentDirectory()
  42. else
  43. lDir := APath;
  44.  
  45. if SelectDirectory(lDir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
  46. result:= lDir;
  47. end;
  48.  
  49. class function TDialogService.ShowFileDialog(ATitle,AInitialDir, AFilter, ADefaultExt : String): String;
  50. var
  51. ADialog : TOpenDialog;
  52. begin
  53. result := '';
  54. try
  55. ADialog := TOpenDialog.Create(nil);
  56. with ADialog do
  57. begin
  58. Title := ATitle;
  59. InitialDir := AInitialDir;
  60. Filter := AFilter;
  61. DefaultExt := ADefaultExt;
  62. if Execute then
  63. result := FileName;
  64. end;
  65. finally
  66. FreeAndNil(ADialog);
  67. end;
  68. end;
  69.  
  70. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement