Files
lazarus-ccr/applications/lazstats/source_orig/optionsunit.pas
wp_xxyyzz e1c5977e0d LazStats: Adding original source, part 6.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7885 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2020-11-16 11:16:49 +00:00

195 lines
4.7 KiB
ObjectPascal

unit OptionsUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, Globals, Clipbrd, EditBtn, contexthelpunit;
type
{ TOptionsFrm }
TOptionsFrm = class(TForm)
BrowseBtn: TButton;
CancelBtn: TButton;
HelpBtn: TButton;
SaveBtn: TButton;
FilePathEdit: TEdit;
Label1: TLabel;
FractionTypeGrp: TRadioGroup;
MissValsGrp: TRadioGroup;
JustificationGrp: TRadioGroup;
SelDir: TSelectDirectoryDialog;
procedure BrowseBtnClick(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure FractionTypeGrpClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure JustificationGrpClick(Sender: TObject);
procedure MissValsGrpClick(Sender: TObject);
procedure SaveBtnClick(Sender: TObject);
procedure InitOptions(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
DefaultPath : string;
FractionType : integer;
DefaultMiss : integer;
DefaultJust : integer;
end;
var
OptionsFrm: TOptionsFrm;
implementation
{ TOptionsFrm }
procedure TOptionsFrm.FormShow(Sender: TObject);
begin
InitOptions(Self);
end;
procedure TOptionsFrm.HelpBtnClick(Sender: TObject);
begin
ContextHelpForm.HelpMessage((Sender as TButton).tag);
end;
procedure TOptionsFrm.JustificationGrpClick(Sender: TObject);
begin
DefaultJust := JustificationGrp.ItemIndex;
end;
procedure TOptionsFrm.MissValsGrpClick(Sender: TObject);
begin
DefaultMiss := MissValsGrp.ItemIndex;
end;
procedure TOptionsFrm.SaveBtnClick(Sender: TObject);
var
pathname : string;
filename : string;
priorfile : string;
F : TextFile;
i : integer;
approved : integer;
begin
if LoggedOn then approved := 1 else approved := 0;
if FilePathEdit.Text <> '' then pathname := FilePathEdit.Text
else pathname := OpenStatPath;
FractionType := FractionTypeGrp.ItemIndex;
DefaultMiss := MissValsGrp.ItemIndex;
DefaultJust := JustificationGrp.ItemIndex;
filename := 'Options.txt';
AssignFile(F,filename);
ReWrite(F);
Writeln(F,approved);
Writeln(F,FractionType);
Writeln(F,DefaultMiss);
Writeln(F,DefaultJust);
Writeln(F,pathname);
{ for i := 0 to 7 do
begin
priorfile := OS3MainFrm.MainMenu1.Items[0].Items[11].Items[i].Caption;
Writeln(F,priorfile);
end; }
CloseFile(F);
end;
procedure TOptionsFrm.CancelBtnClick(Sender: TObject);
begin
OptionsFrm.Hide;
end;
procedure TOptionsFrm.BrowseBtnClick(Sender: TObject);
begin
if SelDir.Execute then
begin
FilePathEdit.Text := SelDir.FileName;
end;
end;
procedure TOptionsFrm.FractionTypeGrpClick(Sender: TObject);
begin
if FractionTypeGrp.ItemIndex = 0 then
begin
FractionType := 0;
DecimalSeparator := '.'
end
else begin
FractionType := 1;
DecimalSeparator := ',';
end;
end;
procedure TOptionsFrm.InitOptions(Sender: TObject);
label full;
var
pathname : string;
filename : string;
priorfile : string;
F : TextFile;
i : integer;
approved : integer;
begin
ChDir(OpenStatPath);
filename := 'Options.txt';
if fileexists(filename) then
begin
AssignFile(F,filename);
Reset(F);
Readln(F,approved);
if approved = 0 then LoggedOn := false else LoggedOn := true;
Readln(F,FractionType);
FractionTypeGrp.ItemIndex := FractionType;
Readln(F,DefaultMiss);
MissValsGrp.ItemIndex := DefaultMiss;
Readln(F,DefaultJust);
JustificationGrp.ItemIndex := DefaultJust;
Readln(F,pathname);
FilePathEdit.Text := pathname;
i := 0;
{ while NOT Eof(F) do
begin
Readln(F,priorfile);
OS3MainFrm.MainMenu1.Items[0].Items[11].Items[i].Action := OS3MainFrm.ActionList1.Actions[i];
OS3MainFrm.MainMenu1.Items[0].Items[11].Items[i].Caption := priorfile;
i := i + 1;
if i > 7 then goto full;
end; }
full: CloseFile(F);
end;
if FilePathEdit.Text = '' then
begin
pathname := GetCurrentDir;
ChDir(pathname);
FilePathEdit.Text := pathname;
end;
{ else begin
pathname := FilePathEdit.Text;
ChDir(pathname);
end; }
if FractionTypeGrp.ItemIndex = 0 then
begin
FractionType := 0;
DecimalSeparator := '.'
end
else begin
FractionType := 1;
DecimalSeparator := ',';
end;
end;
initialization
{$I optionsunit.lrs}
end.