procedure TForm2.SpeedButton1Click(Sender: TObject);
var tmplist:TStringList;
tmpstream:TFileStream;
begin
tmplist:=TStringList.Create ;
if OpenDialog1.Execute then
begin
tmpstream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
tmpstream.Position:=0;
tmplist.LoadFromStream(tmpstream);//这里是读取
showmessage(inttostr(tmplist.Count ));
end;
tmplist.Free ;
tmpstream.Free ;end;
//tmplist.SaveFromStream(tmpstream);//
var tmplist:TStringList;
tmpstream:TFileStream;
begin
tmplist:=TStringList.Create ;
if OpenDialog1.Execute then
begin
tmpstream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
tmpstream.Position:=0;
tmplist.LoadFromStream(tmpstream);//这里是读取
showmessage(inttostr(tmplist.Count ));
end;
tmplist.Free ;
tmpstream.Free ;end;
//tmplist.SaveFromStream(tmpstream);//
解决方案 »
- 为在取键(F12)key 值时,会报错,其它的键都正常取值。
- 在colorgrid中,如何自定义基本颜色!
- 在线等候!
- service 程序怎么结束?
- 菜单分割问题?
- ADOQuery1.Delete该怎样用,我为什么删除不了数据,反而出现了错误!
- 如何制作象WINDOW98那样的开始菜单,也就是在左过有一竖条的(图片或文字)
- delphi中怎么判断memo滚动条滑到底部了?
- 谁试过用midas传递大量的文本数据,高分求教
- 请教在delphi里把数字(69)转换成字母的函数是什么
- 如何知道,端口上是否插上了软件狗?
- 在<<Delphi深度历险>>(陈宽达著)一书中40页处,"自制图形组件的基类"和"自制窗口组件的基类"是什么意思?
procedure TForm1.Button1Click(Sender: TObject);
var
f : TIniFile;
i : integer;
stSection : TStringList ;
begin
f := TiniFile.create('ini文件名');
stSection := TStringList.Create ;
f.ReadSection('小节的名字',stSection);
for i := 0 to stSection.Count -1 do//删除
f.DeleteKey('小节的名字',stSection[i]); for i := 0 to ListBox1.Count -1 do//写入
f.WriteString('小节的名字',intToStr(i+1),ListBox1.Items[i]);
stSection.Free;
end;
需要引用inifiles单元。
for i := 0 to count-1 do
begin
inifile.WriteString('ABC','a'+ IntToStr(I+1),values[i]);
end;如果不知道count
inifile := TINIFile.Create('inifile.ini');
for i := 0 to length(values)-1 do
begin
inifile.WriteString('ABC','a'+ IntToStr(I+1),values[i]);
end;
//其中values是你要保存的数据数组
myCIniFile = class
public
FileName: string;
constructor Create(sFileName: string);
destructor Free;
procedure DeleteKey(sSection,sKey:string);
procedure EraseSection(sSection:string);
function ReadBool(sSection,sKey:string; bDefault:Boolean): Boolean;
function ReadInteger(sSection,sKey:string; iDefault:LongInt): LongInt;
function ReadString(sSection,sKey:string; sDefault:string): string;
procedure WriteBool(sSection,sKey:string; bValue:Boolean);
procedure WriteInteger(sSection,sKey:string; iValue:LongInt);
procedure WriteString(sSection,sKey:string; sValue:string);
end;implementationuses Windows, SysUtils;constructor myCIniFile.Create(sFileName: string);
begin
FileName:= sFileName
end;destructor myCIniFile.Free;
begin
end;procedure myCIniFile.DeleteKey;
begin
WritePrivateProfileString(PChar(sSection), PChar(sKey), nil, PChar(FileName))
end;procedure myCIniFile.EraseSection(sSection:string);
begin
WritePrivateProfileString(PChar(sSection), nil, nil, PChar(FileName))
end;function myCIniFile.ReadBool(sSection,sKey:string; bDefault:Boolean): Boolean;
begin
Result:= bDefault;
Result:= GetPrivateProfileInt(PChar(sSection), PChar(sKey), Ord(bDefault), PChar(FileName))<>0;
end;function myCIniFile.ReadInteger(sSection,sKey:string; iDefault:LongInt): LongInt;
begin
Result:= iDefault;
Result:= GetPrivateProfileInt(PChar(sSection), PChar(sKey), iDefault, PChar(FileName))
end;function myCIniFile.ReadString(sSection,sKey:string; sDefault:string): string;
var
Buffer: array[0..2047] of Char;
begin
Result:= sDefault;
SetString(Result, Buffer, GetPrivateProfileString(PChar(sSection), PChar(sKey), PChar(sDefault), Buffer, SizeOf(Buffer), PChar(FileName)))
end;procedure myCIniFile.WriteBool(sSection,sKey:string; bValue:Boolean);
begin
if bValue then
WritePrivateProfileString(PChar(sSection), PChar(sKey), 'True', PChar(FileName))
else
WritePrivateProfileString(PChar(sSection), PChar(sKey), 'False', PChar(FileName))
end;procedure myCIniFile.WriteInteger(sSection,sKey:string; iValue:LongInt);
begin
WritePrivateProfileString(PChar(sSection), PChar(sKey), PChar(IntToStr(iValue)), PChar(FileName))
end;procedure myCIniFile.WriteString(sSection,sKey:string; sValue:string);
begin
WritePrivateProfileString(PChar(sSection), PChar(sKey), PChar(sValue), PChar(FileName))
end;procedure myCIniFile.Free;
begin
end;end.