回 帖 发 新 帖 刷新版面

主题:delphi读ini文件的问题,请教高手们

在用delphi读ini文件的时候,怎么样才可以让ini文件中的小节名读入到listbox组件中,并且在edit中显示其关键字后的内容.在这里先谢谢了

回复列表 (共2个回复)

沙发

unit ConfigIni;

interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, ADODB, StdCtrls, Buttons, ExtCtrls;

procedure WriteConfigStr(Section:string;Ident:string;WriteValue:string);
procedure WriteConfigInt(Section:string;Ident:string;WriteValue:integer);
function  ReadConfigStr(Section:string;Ident:string;Default:string):string;
function  ReadConfigInt(Section:string;Ident:string;Default:integer):integer;
procedure WriteConfigBins(Section:string;Ident:string;WriteValue:string);
procedure ReadConfigSections(Sections:TStrings);
procedure ReadConfigSection(Section:string;Keys:TStrings);
procedure ReadConfigSectionF(FileName:string;Section:string;Keys:TStrings);
procedure ReadConfigSectionValue(Section:string;Keys:TStrings;Values:TStrings);
procedure DeleteConfigKey(Section:string;Keys:String);

procedure WriteConfigStrF(FileName:string;Section:string;Ident:string;WriteValue:string);
procedure WriteConfigIntF(FileName:string;Section:string;Ident:string;WriteValue:integer);
function  ReadConfigStrF(FileName:string;Section:string;Ident:string;Default:string):string;
function  ReadConfigIntF(FileName:string;Section:string;Ident:string;Default:integer):integer;

implementation
uses
  IniFiles;

procedure WriteConfigBins(Section:string;Ident:string;WriteValue:string);
var
  stHexs:string;
  Config:TIniFile;
begin
  setlength(stHexs,2*length(WriteValue));
  //Bins_To_Hexs(pchar(WriteValue),pchar(stHexs),length(WriteValue));
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    Config.writestring(Section,Ident,stHexs);
    Config.free;
  except
    showmessage('应用配置文件出错!');
  end;

end;
procedure WriteConfigStr(Section:string;Ident:string;WriteValue:string);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    Config.writestring(Section,Ident,WriteValue);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
  end;
end;

procedure WriteConfigInt(Section:string;Ident:string;WriteValue:integer);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    Config.writeinteger(Section,Ident,WriteValue);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
  end;
end;
function  ReadConfigStr(Section:string;Ident:string;Default:string):string;
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    result := Config.readstring(Section,Ident,Default);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
    result := Default;
  end;
end;

function  ReadConfigInt(Section:string;Ident:string;Default:integer):integer;
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    result := Config.readinteger(Section,Ident,Default);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
    result := Default;
  end;
end;

procedure ReadConfigSections(Sections:TStrings);
var

板凳

Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    Config.ReadSections(Sections);
    Config.free;
  except
  end;
end;
procedure ReadConfigSection(Section:string;Keys:TStrings);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    //showmessage(ExtractFilePath(Application.EXEName));
    Config.ReadSection(Section,Keys);
    Config.free;
  except
  end;
end;

procedure ReadConfigSectionF(FileName:string;Section:string;Keys:TStrings);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(FileName);
    Config.ReadSection(Section,Keys);
    Config.free;
  except
  end;
end;

procedure ReadConfigSectionValue(Section:string;Keys:TStrings;Values:TStrings);
var
  i:integer;
begin
  for i:=0 to Keys.Count-1 do
  begin
    Values.Add(ReadConfigStr(Section,Keys.Strings[i],'0'));
  end;
end;

procedure WriteConfigStrF(FileName:string;Section:string;Ident:string;WriteValue:string);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(FileName);
    Config.writestring(Section,Ident,WriteValue);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
  end;
end;


procedure WriteConfigIntF(FileName:string;Section:string;Ident:string;WriteValue:integer);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(FileName);
    Config.writeinteger(Section,Ident,WriteValue);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
  end;
end;
function  ReadConfigStrF(FileName:string;Section:string;Ident:string;Default:string):string;
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(FileName);
    result := Config.readstring(Section,Ident,Default);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
    result := Default;
  end;
end;

function  ReadConfigIntF(FileName:string;Section:string;Ident:string;Default:integer):integer;
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(FileName);
    result := Config.readinteger(Section,Ident,Default);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
    result := Default;
  end;
end;

procedure DeleteConfigKey(Section:string;Keys:String);
var
  Config:TIniFile;
begin
  try
    Config := TIniFile.create(ExtractFilePath(Application.EXEName) + 'Config.ini');
    Config.DeleteKey(Section,Keys);
    Config.free;
  except
    //showmessage('应用配置文件出错!');
  end;
end;
end.

我来回复

您尚未登录,请登录后再回复。点此登录或注册