2020-03-30 18:01:44 +00:00
|
|
|
unit OptionsUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
2020-08-17 14:51:27 +00:00
|
|
|
{$include ../../LazStats.inc}
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-08-20 21:02:55 +00:00
|
|
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
2020-08-17 14:51:27 +00:00
|
|
|
StdCtrls, ExtCtrls, Clipbrd, EditBtn,
|
2020-03-30 18:01:44 +00:00
|
|
|
Globals, ContextHelpUnit;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TOptionsFrm }
|
|
|
|
|
|
|
|
TOptionsFrm = class(TForm)
|
|
|
|
Bevel1: TBevel;
|
|
|
|
CancelBtn: TButton;
|
2020-08-20 21:38:09 +00:00
|
|
|
DataFilePathEdit: TDirectoryEdit;
|
2020-08-17 14:51:27 +00:00
|
|
|
LHelpPathEdit: TFileNameEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
HelpBtn: TButton;
|
2020-08-17 14:51:27 +00:00
|
|
|
Label2: TLabel;
|
2020-03-30 18:01:44 +00:00
|
|
|
SaveBtn: TButton;
|
|
|
|
Label1: TLabel;
|
|
|
|
FractionTypeGrp: TRadioGroup;
|
|
|
|
MissValsGrp: TRadioGroup;
|
|
|
|
JustificationGrp: TRadioGroup;
|
|
|
|
procedure CancelBtnClick(Sender: TObject);
|
|
|
|
procedure FormActivate(Sender: TObject);
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
procedure HelpBtnClick(Sender: TObject);
|
|
|
|
procedure SaveBtnClick(Sender: TObject);
|
|
|
|
|
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
FAutoSized: Boolean;
|
|
|
|
FSavedOptions: TOptions;
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
procedure ControlsToOptions(var AOptions: TOptions);
|
|
|
|
procedure OptionsToControls(const AOptions: TOptions);
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
OptionsFrm: TOptionsFrm;
|
|
|
|
|
|
|
|
procedure LoadOptions;
|
|
|
|
procedure SaveOptions;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2020-08-20 21:02:55 +00:00
|
|
|
Math, FileUtil, LazFileUtils;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
OPTIONS_FILE = 'options.txt';
|
|
|
|
|
2020-08-20 21:02:55 +00:00
|
|
|
function GetOptionsPath: String;
|
|
|
|
begin
|
|
|
|
Result := GetAppConfigDirUTF8(false, true) + OPTIONS_FILE;
|
|
|
|
end;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure LoadOptions;
|
|
|
|
var
|
|
|
|
filename: String;
|
|
|
|
pathname: string;
|
|
|
|
F: TextFile;
|
|
|
|
i: integer;
|
|
|
|
approved: integer;
|
|
|
|
begin
|
2020-08-20 21:02:55 +00:00
|
|
|
filename := GetOptionsPath;
|
2020-03-30 18:01:44 +00:00
|
|
|
if not FileExists(fileName) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
AssignFile(F, fileName);
|
|
|
|
Reset(F);
|
|
|
|
|
|
|
|
// approved
|
|
|
|
ReadLn(F, approved);
|
|
|
|
LoggedOn := (approved <> 0);
|
|
|
|
|
|
|
|
// Fraction type
|
|
|
|
ReadLn(F, i);
|
|
|
|
Options.FractionType := TFractionType(i);
|
|
|
|
DefaultFormatSettings.DecimalSeparator := FractionTypeChars[Options.FractionType];
|
|
|
|
|
|
|
|
// Default missing value
|
|
|
|
ReadLn(F, i);
|
|
|
|
Options.DefaultMiss := TMissingValueCode(i);
|
|
|
|
|
|
|
|
// Default justification
|
|
|
|
ReadLn(F, i);
|
|
|
|
Options.DefaultJust := TJustification(i);
|
|
|
|
|
|
|
|
// Default path
|
|
|
|
ReadLn(F, pathName);
|
|
|
|
if (pathname = '') or (not DirectoryExists(pathname)) then
|
2020-08-20 21:38:09 +00:00
|
|
|
Options.DefaultDataPath := GetCurrentDir
|
2020-03-30 18:01:44 +00:00
|
|
|
else
|
2020-08-20 21:38:09 +00:00
|
|
|
Options.DefaultDataPath := pathname;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-08-17 14:51:27 +00:00
|
|
|
// LHelp path
|
|
|
|
Readln(F, pathName);
|
|
|
|
Options.LHelpPath := pathname;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
Close(F);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure SaveOptions;
|
|
|
|
var
|
|
|
|
filename: string;
|
|
|
|
F: TextFile;
|
|
|
|
begin
|
2020-08-20 21:02:55 +00:00
|
|
|
filename := GetOptionsPath;
|
2020-03-30 18:01:44 +00:00
|
|
|
AssignFile(F, fileName);
|
|
|
|
Rewrite(F);
|
2020-08-20 21:02:55 +00:00
|
|
|
WriteLn(F, ord(LoggedOn));
|
2020-03-30 18:01:44 +00:00
|
|
|
WriteLn(F, ord(Options.FractionType));
|
|
|
|
WriteLn(F, ord(Options.DefaultMiss));
|
|
|
|
WriteLn(F, ord(Options.DefaultJust));
|
2020-08-20 21:38:09 +00:00
|
|
|
WriteLn(F, Options.DefaultDataPath);
|
2020-08-17 14:51:27 +00:00
|
|
|
WriteLn(F, Options.LHelpPath);
|
2020-03-30 18:01:44 +00:00
|
|
|
CloseFile(F);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TOptionsFrm }
|
|
|
|
|
|
|
|
procedure TOptionsFrm.ControlsToOptions(var AOptions: TOptions);
|
|
|
|
begin
|
|
|
|
AOptions.FractionType := TFractionType(FractionTypeGrp.ItemIndex);
|
|
|
|
AOptions.DefaultMiss := TMissingValueCode(MissValsGrp.ItemIndex);
|
|
|
|
AOptions.DefaultJust := TJustification(JustificationGrp.ItemIndex);
|
2020-08-20 21:38:09 +00:00
|
|
|
AOptions.DefaultDataPath := DataFilePathEdit.Text;
|
2020-08-20 21:02:55 +00:00
|
|
|
if LHelpPathEdit.FileName = Application.Location + 'lhelp' + GetExeExt then
|
2020-08-17 14:51:27 +00:00
|
|
|
AOptions.LHelpPath := '<default>'
|
|
|
|
else
|
|
|
|
AOptions.LHelpPath := LHelpPathEdit.FileName;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TOptionsFrm.OptionsToControls(const AOptions: TOptions);
|
|
|
|
begin
|
|
|
|
FractionTypeGrp.ItemIndex := ord(AOptions.FractionType);
|
|
|
|
MissValsGrp.ItemIndex := Ord(AOptions.DefaultMiss);
|
|
|
|
JustificationGrp.ItemIndex := Ord(AOptions.DefaultJust);
|
2020-08-20 21:38:09 +00:00
|
|
|
DataFilePathEdit.Text := AOptions.DefaultDataPath;
|
2020-08-17 14:51:27 +00:00
|
|
|
if AOptions.LHelpPath = '<default>' then
|
|
|
|
LHelpPathEdit.FileName := Application.Location + 'lhelp' + GetExeExt
|
|
|
|
else
|
|
|
|
LHelpPathEdit.FileName := AOptions.LHelpPath;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TOptionsFrm.FormActivate(Sender: TObject);
|
|
|
|
var
|
|
|
|
w: Integer;
|
|
|
|
begin
|
|
|
|
if FAutoSized then
|
|
|
|
exit;
|
|
|
|
|
2020-08-17 14:51:27 +00:00
|
|
|
{$IFDEF USE_EXTERNAL_HELP_VIEWER}
|
|
|
|
Label2.Visible := false;
|
|
|
|
LHelpPathEdit.Visible := false;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
w := MaxValue([HelpBtn.Width, SaveBtn.Width, CancelBtn.Width]);
|
2020-03-30 18:01:44 +00:00
|
|
|
HelpBtn.Constraints.MinWidth := w;
|
|
|
|
SaveBtn.Constraints.MinWidth := w;
|
|
|
|
CancelBtn.Constraints.MinWidth := w;
|
|
|
|
|
|
|
|
Constraints.MinWidth := Width;
|
|
|
|
Constraints.MinHeight := Height;
|
|
|
|
Constraints.MaxHeight := Height;
|
|
|
|
|
|
|
|
FAutoSized := true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TOptionsFrm.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
OptionsToControls(Options);
|
|
|
|
ControlsToOptions(FSavedOptions);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TOptionsFrm.HelpBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if ContextHelpForm = nil then
|
|
|
|
Application.CreateForm(TContextHelpForm, ContextHelpForm);
|
|
|
|
ContextHelpForm.HelpMessage((Sender as TButton).tag);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TOptionsFrm.SaveBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ControlsToOptions(Options);
|
|
|
|
SaveOptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TOptionsFrm.CancelBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Options := FSavedOptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
{$I optionsunit.lrs}
|
|
|
|
|
|
|
|
end.
|
|
|
|
|