您的位置:首页 > 编程语言 > Delphi

delphi7 ini创建,读写,条件字节值判断,删除,释放

2011-05-04 11:12 141 查看
//ini创建,读写,条件字节值判断
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,IniFiles;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
MyIniFile:TInifile;//定义ini
Filename:string;
v1:string;
v2:Integer;
v3:Boolean;
begin
Filename:=ExtractFilePath(Paramstr(0))+ 'program.ini'; //文件路径
if not fileexists(Filename)then //如果没有找到文件则会自动创建一个INI文件
begin
MyIniFile:=Tinifile.Create(FileName); //打开INI文件
//写入信息小名,变量,值,......................................................
myinifile.writestring('小节名', '关键字1','1111');
myinifile.writeinteger('小节名', '关键字2',11111);
myinifile.writebool('小节名', '关键字3',True);
end else //读取INI
begin
MyIniFile:=Tinifile.Create(FileName); //打开文件
v1:=myinifile.Readstring( '小节名', '关键字1','缺省值');
if v1='1111' then
begin
myinifile.writestring('小节名', '关键字1','初值改变了变000');
end else
v1:=myinifile.Readstring( '小节名', '关键字1','0');
v2:=myinifile.Readinteger( '小节名', '关键字2 ',0);
v3:=myinifile.Readbool( '小节名', '关键字3 ',false);
Edit1.Text:=v1+inttostr(v2)+booltostr(v3);
//删除关键字
//myinifile.DeleteKey( '小节名 ', '关键字 ');
//删除小节
//myinifile.EraseSection( '小节名 ');
//添加小节可以使用写入法来创建
// 在适当的位置用下面的语句释放myinifile:
//释放
myinifile.Destroy;
end;
end;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐