你用这个。。这个我已经加成功了。 var tt:Tstringlist; index:integer; begin tt:=Tstringlist.create; tt.loadfromfile('c:\a.ini'); index:=tt.indexof('[小节名]'); if index<>1 then tt.insert(index+1,'我的字符串'); tt.SaveToFile('c:\a.ini'); end;
用TStingList来可以实现的阿! tt:Tstring; index:integer; tt;=Tstringlist.create; tt.loadfromfile('c:\a.ini'); index:=tt.indexof('小节名'); if index<>1 then tt.insert(index+1,'我的字符串'); 为什么没有插入也》?》??你上面定义的tt是Tsting 下面却是tt:=TStringList.Create; 应该是tt:TStringList; 再: tt:=TStringList.Create; tt.LoadFromFile(FileName); 然后就可以用tt.Add或者tt.Append加入字符串了!
为什么一定要用TStrings呢?我试过TIniFile,极其方便。为什么不用TIniFile? procedure TForm1.Button1Click(Sender: TObject); var Ini:TIniFile; begin Ini:=TIniFile.Create('Ini.ini'); Ini.WriteString('bb','dd','tt'); Ini.Free; end; 这样的操作的结果,如果ini.ini存在,则加入 [bb] dd=tt 如果不存在,则创建ini.ini让后写入同样内容
var
filename:string;
begin
filename:=ExtractFilePath(paramstr(0))+'myini.ini';
myinifile:=TInifile.Create(filename);
edit1.Text:= myinifile.readstring('程序参数','用户名称','缺省的用户名称');
edit2.text:= inttostr(myinifile.readinteger('程序参数','已运行时间',0));
checkbox1.Checked:= myinifile.readbool('程序参数','是否正式用户',False);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
myinifile.writestring('程序参数','用户名称',edit1.Text);
myinifile.writeinteger('程序参数','已运行时间',strtoint(edit2.text));
myinifile.writebool('程序参数','是否正式用户',checkbox1.Checked);
myinifile.Destroy;
end;
也就是 ‘我的字符串 ’没有插入
我的小节下面也!
savetofile 不是另存文件吗?
他的writestring会在我的小节下 写入一个‘=’
而我只要写入一个字符串 而不要哪个‘=’
所以要用Tstring 和Tstringlist
请各位指点
可以 在加分
var
tt:Tstringlist;
index:integer;
begin
tt:=Tstringlist.create;
tt.loadfromfile('c:\a.ini');
index:=tt.indexof('[小节名]');
if index<>1 then
tt.insert(index+1,'我的字符串');
tt.SaveToFile('c:\a.ini');
end;
tt:Tstring;
index:integer;
tt;=Tstringlist.create;
tt.loadfromfile('c:\a.ini');
index:=tt.indexof('小节名');
if index<>1 then
tt.insert(index+1,'我的字符串');
为什么没有插入也》?》??你上面定义的tt是Tsting
下面却是tt:=TStringList.Create;
应该是tt:TStringList;
再:
tt:=TStringList.Create;
tt.LoadFromFile(FileName);
然后就可以用tt.Add或者tt.Append加入字符串了!
procedure TForm1.Button1Click(Sender: TObject);
var Ini:TIniFile;
begin
Ini:=TIniFile.Create('Ini.ini');
Ini.WriteString('bb','dd','tt');
Ini.Free;
end;
这样的操作的结果,如果ini.ini存在,则加入
[bb]
dd=tt
如果不存在,则创建ini.ini让后写入同样内容
我不许要那个可恶的‘=’
所以用TstringList d的