FileForums

FileForums (https://fileforums.com/index.php)
-   Conversion Tutorials (https://fileforums.com/forumdisplay.php?f=55)
-   -   Write on an ini file (https://fileforums.com/showthread.php?t=99496)

lupetto77 27-08-2017 16:07

Write on an ini file
 
Using Inno Setup Compiler I have added a screen with the various components, I should read the content that is inserted into a textbox and write it in an ini file.

Same thing with the combobox component.

I added the section
Code:
[Ini]
Filename: {app} \ fileProva.ini; Section: prova1; Key: nomeTextBox1
Filename: {app} \ fileProva.ini; Section: Prova2; Key: nomeTextBox2

Is that okay?

Or should I add something else?

JRD! 28-08-2017 12:50

function GetIniBool(const Section, Key: String; const: Boolean; const Filename: String): Boolean;
function GetIniInt(const Section, Key: String; const Default, Min, Max: Longint; const Filename: String): Longint;
function GetIniString(const Section, Key, Default, Filename: String): String;
Code:


Example:

var
  sCaption: string;
  iLeft, iTop, iWidth, iHeight: integer;
  bChecked: boolean;

  sCaption:=GetIniString('chkb', 'Caption', 'Component 1', ExpandConstant('{src}') + '\YourFile.ini');
  iLeft:=GetIniInt('chkb', 'Left', '30', ExpandConstant('{src}') + '\YourFile.ini');
  iTop:=GetIniInt('chkb', 'Top', '50', ExpandConstant('{src}') + '\YourFile.ini'); 
  iWidth:=GetIniInt('chkb', 'Width', '150', ExpandConstant('{src}') + '\YourFile.ini');
  iHeight:=GetIniInt('chkb', 'Height', '20', ExpandConstant('{src}') + '\YourFile.ini');
  bChecked=GetIniBool('chkb', 'Checked', 'true', ExpandConstant('{src}') + '\YourFile.ini');

  CheckBox1.Caption:=sCaption;
  CheckBox1.SetBounds(iLeft, iTop, iWidth, iHeight);
  CheckBox1.Checked:=bChecked;


JRD! 28-08-2017 14:13

function SetIniBool(const Section, Key: String; const Value: Boolean; const Filename: String): Boolean;
function SetIniInt(const Section, Key: String; const Value: Longint; const Filename: String): Boolean;
function SetIniString(const Section, Key, Value, Filename: String): Boolean;

Code:

[Setup]
AppName='Write to ini example';
AppVerName=0.0.0.0
CreateAppDir=false
OutputDir=".\"

[ Code ]
const
  INIFILE = 'config.ini';

procedure OnChange(Sender: TObject);
begin
  SetIniString(TControl(Sender).Name, 'Text', TEdit(Sender).Text, ExpandConstant('{src}\') + INIFILE);
end;

procedure OnClick(Sender: TObject);
begin
  SetIniBool(TControl(Sender).Name, 'State', (Sender as TCheckBox).Checked, ExpandConstant('{src}\') + INIFILE);
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  Confirm:=False
  Cancel:=True
end;

procedure InitializeWizard();
begin

  with WizardForm do
  begin
    BorderStyle := bsToolWindow;
    Position := poScreenCenter;
    AutoScroll := False;
    ClientWidth := ScaleX(300);
    ClientHeight := ScaleY(100);
    Caption:={#SetupSetting("AppName")};
    InnerNotebook.Hide;
    OuterNotebook.Hide;
  end;

  with TLabel.Create(WizardForm) do
  begin
    Parent := WizardForm;
    SetBounds(5, 8, 40, 15);
    Caption:='Edit1: ';
    Font.Size:=10;
  end;
 
  with TEdit.Create(WizardForm) do
  begin
    Parent := WizardForm;
    SetBounds(50, 5, WizardForm.ClientWidth - 60, 15);
    OnChange:=@OnChange;
    Name:='Edit1';
  end;

  with TLabel.Create(WizardForm) do
  begin
    Parent := WizardForm;
    SetBounds(5, 33, 40, 15);
    Caption:='Edit2: ';
    Font.Size:=10;
  end;

  with TEdit.Create(WizardForm) do
  begin
    Parent := WizardForm;
    SetBounds(50, 30, WizardForm.ClientWidth - 60, 15);
    OnChange:=@OnChange;
    Name:='Edit2';
  end;

  with TCheckBox.Create(WizardForm) do
  begin
    Parent := WizardForm;
    SetBounds(50, 70, 150, 15);
    OnClick:=@OnClick;
    Name:='CheckBox1';
    Checked:=GetIniBool(Name, 'State', false, ExpandConstant('{src}\') + INIFILE);
  end;

  with TCheckBox.Create(WizardForm) do
  begin
    Parent := WizardForm;
    SetBounds(150, 70, 150, 15);
    OnClick:=@OnClick;
    Name:='CheckBox2';
    Checked:=GetIniBool(Name, 'State', false, ExpandConstant('{src}\') + INIFILE);
  end;

end;


lupetto77 31-08-2017 16:19

Sorry for the response delay.

Thanks for the help, I will try to figure out how it works.


All times are GMT -7. The time now is 20:24.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
FileForums @ https://fileforums.com