home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softwarová Záchrana 3
/
Softwarova-zachrana-3.bin
/
StartRight
/
source.zip
/
UnitFrmOptions.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2004-10-08
|
7KB
|
238 lines
unit UnitFrmOptions;
{
Purpose:
Save all the options to an INI file and automatically load the items
when created
}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, INIFiles, Registry, UnitMyRegistry, ComCtrls;
type
TFrmOptions = class(TForm)
bSave: TButton;
bCancel: TButton;
cbShowStartupDialog: TCheckBox;
cbDisableSysTrayNotification: TCheckBox;
cbAutoDisable: TCheckBox;
cbDisableMoveDialog: TCheckBox;
Label4: TLabel;
GroupBox1: TGroupBox;
Label1: TLabel;
txtIntInitPause: TEdit;
Label3: TLabel;
txtIntRunkeyPause: TEdit;
Label2: TLabel;
txtIntStartupPause: TEdit;
cbDisableAutoTune: TCheckBox;
procedure bCancelClick(Sender: TObject);
procedure bSaveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
filename : string;
r : TMyRegistry;
DisableAutoTune : boolean;
procedure ProcessRegistryWrite(key_value : string; data : string); overload;
procedure ProcessRegistryWrite(key_value : string; data : integer); overload;
function ProcessRegistryRead(key_value : string) : string;
procedure ProcessRegistry(ReadOnly : boolean; key_value : string; var data : string; IsIntegerData : boolean = false);
public
{ Public declarations }
procedure SetAutoTuneDisabled;
end;
var
FrmOptions: TFrmOptions;
implementation
uses UnitMyKeys;
{$R *.dfm}
procedure TFrmOptions.bCancelClick(Sender: TObject);
begin
self.ModalResult := mrOk;
end;
procedure TFrmOptions.bSaveClick(Sender: TObject);
var i : integer;
c : TComponent;
ini : TInifile;
s : string;
const pname = 'StartRight';
begin
try
StrToInt(txtIntRunkeyPause.text);
StrToInt(txtIntStartupPause.text);
StrToInt(txtIntInitPause.text);
except on e : exception do
begin
ShowMessage('Millisecond fields must be numbers only');
EXIT;
end;
end;
ini := TInifile.create(self.filename);
for i := 0 to self.ComponentCount - 1 do begin
c := self.Components[i];
s := '';
if (c is TCheckBox) then begin
ini.WriteBool(TCheckBox(c).Name, TCheckBox(c).Name, TCheckBox(c).Checked);
end else if (c is TEdit) then begin
if pos('txtInt', TEdit(c).Name) <> 0 then begin
ProcessRegistryWrite(TEdit(c).Hint, StrToInt(TEdit(c).text));
end else begin
ProcessRegistryWrite(TEdit(c).Hint, TEdit(c).text);
end;
ini.WriteString(TEdit(c).Name, TEdit(c).Name, TEdit(c).text);
end else if (c is TRadioButton) then begin
ini.WriteBool(TRadioButton(c).Name, TRadioButton(c).Name, TRadioButton(c).Checked);
end;
end;
ini.Free;
self.ModalResult := mrOk;
end;
procedure TFrmOptions.FormCreate(Sender: TObject);
var i : integer;
c : TComponent;
ini : TInifile;
const pname = 'StartRight';
begin
r := TMyRegistry.Create;
self.filename := IncludeTrailingPathDelimiter(
ExtractFilePath(Application.ExeName)
) + 'options.ini';
ini := TInifile.create(self.filename);
for i := 0 to self.ComponentCount - 1 do begin
c := self.Components[i];
if (c is TCheckBox) then begin
TCheckbox(c).Checked := ini.ReadBool(TCheckbox(c).Name, TCheckbox(c).Name, false);
end else if (c is TEdit) then begin
TEdit(c).text := ini.ReadString(TEdit(c).Name, TEdit(c).Name, '');
if TEdit(c).hint <> '' then begin
TEdit(c).text := ProcessRegistryRead(TEdit(c).Hint);
end;
end else if (c is TRadioButton) then begin
TRadioButton(c).Checked := ini.ReadBool(TRadioButton(c).Name, TRadioButton(c).Name, false);
end;
end;
ini.Free;
if self.DisableAutoTune then begin
self.cbDisableAutoTune.Checked := true;
end;
end;
procedure TFrmOptions.FormShow(Sender: TObject);
begin
self.FormCreate(self);
end;
procedure TFrmOptions.ProcessRegistry(ReadOnly : boolean; key_value : string; var data : string; isIntegerData : boolean);
var key, value : string;
i, slashPos : integer;
begin
if (key_value = '') then EXIT;
slashPos := 0;
for i := length(key_value) downto 1 do begin
if (key_value[i] = '\') then begin
slashPos := i;
BREAK;
end;
end;
if (slashPos <> 0) then begin
// chopy before and after the last slash
key := Copy(key_value, 1, slashPos - 1);
value := StringReplace(key_value, key + '\', '',[]);
key := IncludeTrailingPathDelimiter(UnitMyKeys.SR_HOME_KEY) + key;
end else begin
key := UnitMyKeys.SR_HOME_KEY;
value := key_value;
end;
if ReadOnly then begin
try
data := r.GetDataString(key, value);
except on e : exception do begin
try
data := IntToStr(r.GetDataInteger(key, value));
except on e : exception do begin
ShowMessage(
e.message + #13#10 +
'Unable to read registry item: ' + value
);
end;
end;
end;
end;
end else begin
try
if IsIntegerData then begin
r.SetDataInteger(key, value, StrToInt(data));
end else begin
r.SetDataString(key, value, data);
end;
except on e : exception do
begin
ShowMessage('Registry write failed' +#13#10 +
e.message);
end;
end;
end;
end;
function TFrmOptions.ProcessRegistryRead(key_value : string) : string;
var data : string;
begin
ProcessRegistry(True, key_value, data);
result := data;
end;
procedure TFrmOptions.ProcessRegistryWrite(key_value : string; data : string);
begin
ProcessRegistry(False, key_value, data);
end;
procedure TFrmOptions.ProcessRegistryWrite(key_value: string;
data: integer);
var s : string;
begin
s := IntToStr(data);
ProcessRegistry(False, key_value, s, true);
end;
procedure TFrmOptions.SetAutoTuneDisabled;
begin
self.cbDisableAutoTune.Checked := true;
self.DisableAutoTune := true;
end;
end.