/examples/cleandir/frmlog.pp

http://github.com/graemeg/lazarus · Puppet · 116 lines · 92 code · 24 blank · 0 comment · 5 complexity · d71780e4a74dd0190c6db384986834af MD5 · raw file

  1. { Directory cleaning component logging window
  2. Copyright (C) 2007 Michael Van Canneyt michael@freepascal.org
  3. This library is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Library General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or (at your
  6. option) any later version with the following modification:
  7. As a special exception, the copyright holders of this library give you
  8. permission to link this library with independent modules to produce an
  9. executable, regardless of the license terms of these independent modules,and
  10. to copy and distribute the resulting executable under terms of your choice,
  11. provided that you also meet, for each linked independent module, the terms
  12. and conditions of the license of that module. An independent module is a
  13. module which is not derived from or based on this library. If you modify
  14. this library, you may extend this exception to your version of the library,
  15. but you are not obligated to do so. If you do not wish to do so, delete this
  16. exception statement from your version.
  17. This program is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  20. for more details.
  21. You should have received a copy of the GNU Library General Public License
  22. along with this library; if not, write to the Free Software Foundation,
  23. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. }
  25. unit frmlog;
  26. {$mode objfpc}{$H+}
  27. interface
  28. uses
  29. Forms, Dialogs, LazUTF8, StdCtrls, dircleaner;
  30. type
  31. { TLogForm }
  32. TLogForm = class(TForm)
  33. BClose: TButton;
  34. BSave: TButton;
  35. Label1: TLabel;
  36. LBLog: TListBox;
  37. SDlog: TSaveDialog;
  38. procedure BCloseClick(Sender: TObject);
  39. procedure BSaveClick(Sender: TObject);
  40. procedure FormShow(Sender: TObject);
  41. private
  42. FCleaner: TCleanDirs;
  43. FRunning : Boolean;
  44. procedure SetCleaner(const AValue: TCleanDirs);
  45. { private declarations }
  46. public
  47. { public declarations }
  48. Procedure OnLog(Msg : String);
  49. Property Cleaner : TCleanDirs Read FCleaner Write SetCleaner;
  50. end;
  51. var
  52. LogForm: TLogForm;
  53. implementation
  54. {$R *.lfm}
  55. resourcestring
  56. SClose = '&Close';
  57. { TLogForm }
  58. procedure TLogForm.BSaveClick(Sender: TObject);
  59. begin
  60. If SDLog.execute then
  61. LBLog.Items.SaveToFile(UTF8ToSys(SDLog.FileName));
  62. end;
  63. procedure TLogForm.BCloseClick(Sender: TObject);
  64. begin
  65. if FRunning then
  66. FCleaner.Cancel
  67. else
  68. Close;
  69. end;
  70. procedure TLogForm.FormShow(Sender: TObject);
  71. begin
  72. FRunning:=True;
  73. Try
  74. FCleaner.execute;
  75. BClose.Caption:=SClose;
  76. Finally
  77. FRunning:=False;
  78. end;
  79. end;
  80. procedure TLogForm.SetCleaner(const AValue: TCleanDirs);
  81. begin
  82. if FCleaner=AValue then exit;
  83. FCleaner:=AValue;
  84. If Assigned(FCleaner) then
  85. FCleaner.OnLog:=@Self.OnLog;
  86. end;
  87. procedure TLogForm.OnLog(Msg: String);
  88. begin
  89. LBLog.Items.Add(Msg);
  90. Application.ProcessMessages;
  91. end;
  92. end.