home *** CD-ROM | disk | FTP | other *** search
- {=================================================
- Program: SysFile.Exe
- Version: 1.0
- Module: SysProt.pas
- Author: Wayne Niddery
- CopyRight ⌐ 1995 Wayne Niddery and WinWright
- =================================================}
- unit Sysprot;
-
- {SysProt is a very simple dialog with a TMemo that allows direct
- editing by the user to add or remove file names. The purpose is
- to protect against accidental deletion of files. This is needed as
- it's very easy to delete files using the popup menus.}
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, IniFiles;
-
- type
- TProtectDlg = class(TForm)
- Panel1: TPanel;
- ProtList: TMemo;
- Label1: TLabel;
- ProtOK: TBitBtn;
- ProtCancel: TBitBtn;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure ProtCancelClick(Sender: TObject);
- procedure ProtListKeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- ProtectDlg: TProtectDlg;
-
- implementation
-
- {$R *.DFM}
-
- uses
- SysGlb;
-
- {called when ProtectDlg first created}
- procedure TProtectDlg.FormCreate(Sender: TObject);
- var
- i: integer;
- s: string;
- begin
- if not FileExists(SysIni.FileName) then
- {first time run on this system, so use default list of files}
- for i := 0 to High(DefProt) do
- ProtList.Lines.Add(Defprot[i])
- else begin {read protection list from INI file}
- i := 0;
- repeat
- {the keys to each file name are numbers beginning with 0}
- s := SysIni.ReadString(iniProtect, IntToStr(i), '');
- if Length(s) > 0 then ProtList.Lines.Add(s);
- inc(i);
- until Length(s) = 0;
- ProtList.Modified := False; {user hasn't changed list yet}
- end;
- end;
-
- {called when program shuts down}
- procedure TProtectDlg.FormDestroy(Sender: TObject);
- var
- i: integer;
- begin
- {remove old list of names from protect section of INI}
- SysIni.EraseSection(iniProtect);
- {add current list back to INI}
- for i := 0 to ProtList.Lines.Count - 1 do
- SysIni.WriteString(iniProtect, IntToStr(i), ProtList.Lines[i]);
- end;
-
- {Cancel button clicked}
- procedure TProtectDlg.ProtCancelClick(Sender: TObject);
- var
- i: integer;
- s: string;
- begin
- {if any changes made to TMemo, then we need to reread file names
- from INI file in order to 'erase' changes}
- if ProtList.Modified then begin
- i := 0;
- ProtList.Lines.Clear; {remove all lines from TMemo}
- repeat
- s := SysIni.ReadString(iniProtect, IntToStr(i), '');
- if Length(s) > 0 then ProtList.Lines.Add(s);
- inc(i);
- until Length(s) = 0;
- ProtList.Modified := False;
- end;
- end;
-
- {This handles the OnKeyPress event and allows us to force uupercase}
- procedure TProtectDlg.ProtListKeyPress(Sender: TObject; var Key: Char);
- begin
- Key := UpCase(Key);
- end;
-
- end.
-