procedure TFormMain.FormCreate(Sender: TObject);
var
    MyIniFile :TIniFile;
    mySolutionIniFile :string;
begin
    mySolutionIniFile :=  ExtractFilePath(Application.ExeName) + 'NetConfig.ini';
    try
        MyIniFile := TIniFile.Create(mySolutionIniFile);
        cmbx_FormStyle.ItemIndex := MyIniFile.ReadInteger('系统配置','cmbx_FormStyle',1);
        cmbx_SolutionList.ItemIndex := cmbx_SolutionList.Properties.Items.IndexOf(MyIniFile.ReadString('系统配置','cmbx_SolutionList',''));
    finally
        MyIniFile.Free;
    end;
end;
为何我这样写会出现“[Warning] frmMain.pas(171): Variable 'MyIniFile' might not have been initialized”这样的警告呢?怎样才能消除这个警告啊?

解决方案 »

  1.   

    procedure TFormMain.FormCreate(Sender: TObject);
    var
        MyIniFile :TIniFile;
        mySolutionIniFile :string;
    begin
        mySolutionIniFile :=  ExtractFilePath(Application.ExeName) + 'NetConfig.ini';
        MyIniFile := TIniFile.Create(mySolutionIniFile);
        try
            
            cmbx_FormStyle.ItemIndex := MyIniFile.ReadInteger('系统配置','cmbx_FormStyle',1);
            cmbx_SolutionList.ItemIndex := cmbx_SolutionList.Properties.Items.IndexOf(MyIniFile.ReadString('系统配置','cmbx_SolutionList',''));
        finally
            MyIniFile.Free;
        end;
    end;
      

  2.   

    就象楼上,要把Tinifile.create()放在try的外面。
      

  3.   

    谢谢wudi_1982的回答,为何我不能结贴啊?点结贴没有任何反应哦!