Inno Setup - 如何读取和写入ini文件?

时间:2014-10-28 09:15:41

标签: inno-setup

我对Inno Setup很新,现在尝试从.ini文件中读取值。我需要读取Checked状态的值。 (该行中的第一个真/假)。

      AddCheckBox('Global', '', 0, True, True, True, True, TStringList.Create);
      AddCheckBox('Option 1', '', 1, False, True, False, True, TStringList.Create);
      AddCheckBox('Option 2', '', 1, True, True, False, True, TStringList.Create); 

安装后存储新值。

有人可以给我看一段代码或示例,该怎么做?

这是完整的代码:

[Setup]
AppName=My Program
AppVerName=My Program version 1.5
DefaultDirName={pf}\My Program

[Files]
Source: ReadMe1.rtf; Flags: dontcopy
Source: ReadMe2.rtf; Flags: dontcopy
Source: ReadMe3.rtf; Flags: dontcopy

Source: Image1.bmp; Flags: dontcopy
Source: Image2.bmp; Flags: dontcopy
Source: Image3.bmp; Flags: dontcopy

Source: Files\*; DestDir: {app}\add; Flags: ignoreversion recursesubdirs createallsubdirs; Check: CheckedBox(2)

[Code]
var
  Page: TWizardPage;
  ListBox: TNewCheckListBox;
  Memo: TRichEditViewer;
  CheckLabel: TLabel;
  MouseY: integer;
  BitmapImage: TBitmapImage;
  InfoBmp: array of TBitmap;

function CheckedBox(ItemNumber: integer): Boolean;
begin                                    
  Result:= ListBox.Checked[ItemNumber];  
end;

procedure CheckOnClick (Sender: TObject); 
begin
  if MouseY < ListBox.Items.Count then
    begin 
      ListBox.Checked[MouseY]:= Not(ListBox.Checked[MouseY]);
    end;
end;

procedure CheckMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin                                       
  MouseY:= Y/ScaleY(16);
  if MouseY < ListBox.Items.Count then
    begin  
      Memo.RTFText:= TStrings(ListBox.ItemObject[MouseY]).Text;
      BitmapImage.Bitmap:= InfoBmp[MouseY];
    end;
end;

procedure InitializeWizard();
var
  i: integer;
begin
  ExtractTemporaryFile('ReadMe1.rtf'); ˙
  ExtractTemporaryFile('ReadMe2.rtf');
  ExtractTemporaryFile('ReadMe3.rtf');
  ExtractTemporaryFile('Image1.bmp');  
  ExtractTemporaryFile('Image2.bmp');
  ExtractTemporaryFile('Image3.bmp');

  Page:=CreateCustomPage(wpWelcome, 'Title', 'Description')

  ListBox:= TNewCheckListBox.Create(Page); 
  with ListBox do
    begin
      Left   := 15
      Top    := 0
      Width  := 200
      Height := 149
      Parent := Page.Surface
      AddCheckBox('Global', '', 0, True, True, True, True, TStringList.Create);
      AddCheckBox('Option 1', '', 1, False, True, False, True, TStringList.Create);
      AddCheckBox('Option 2', '', 1, True, True, False, True, TStringList.Create);

      TStrings(ItemObject[0]).LoadFromFile(ExpandConstant('{tmp}\ReadMe1.rtf'));
      TStrings(ItemObject[1]).LoadFromFile(ExpandConstant('{tmp}\ReadMe2.rtf'));
      TStrings(ItemObject[2]).LoadFromFile(ExpandConstant('{tmp}\ReadMe3.rtf'));
    end;

  Memo:= TRichEditViewer.Create(Page); 
  with Memo do
    begin
      Left        := ListBox.Left + ListBox.Width + 8;
      Top         := ListBox.Top;
      Width       := ListBox.Width;
      Height      := ListBox.Height;
      Color       := clBtnFace;
      Enabled     := False;
      BorderStyle := bsNone;
      Parent      := Page.Surface;
    end;

  CheckLabel:= TLabel.Create(Page);  
  with CheckLabel do
    begin
      Width       :=ListBox.Width;
      Height      :=ListBox.Height;
      Autosize    :=False;
      Transparent :=True;
      OnMouseMove :=@CheckMouseMove;
      OnClick     :=@CheckOnClick;
      Parent      :=ListBox;
      Cursor      := 1;
    end;

  BitmapImage := TBitmapImage.Create(Page);
  with BitmapImage do                       
    begin                                   
      AutoSize := True;
      Left        := ListBox.Left;
      Top         := ListBox.Top + ListBox.Height + 8;
      Width       := ListBox.Width;
      Height      := 32;
      Parent := Page.Surface;
    end;

  for i:=0 to ListBox.Items.Count - 1 do  
    begin                                
      SetArrayLength(InfoBmp, i+1);
      InfoBmp[i]:= TBitmap.Create;
    end;

  InfoBmp[0].LoadFromFile(ExpandConstant('{tmp}\Image1.bmp'));
  InfoBmp[1].LoadFromFile(ExpandConstant('{tmp}\Image2.bmp'));
  InfoBmp[2].LoadFromFile(ExpandConstant('{tmp}\Image3.bmp'));
end; 

0 个答案:

没有答案
相关问题