PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/cleandir/frmlog.pp

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