源程序是这样的:
hehuiprocedure Tmainform.Button6Click(Sender: TObject);
var
s,newline,compcode:string;
compname,password:string;
f:textfile;
// tmplist:tstrings;
filelist:TStrings;
i,oldrecord,succ:integer;
begin
oldrecord:=0;
compcode:=edit8.Text;
password:=edit9.Text;
compname:=edit11.Text;
newline:=':'+compcode+':'+password+':'+compname;
filelist:=TStringList.Create;
filelist.LoadFromFile('C:\对照表.txt');
try
extractstrings([':'],[],pchar(filelist),filelist);
//edit7.Text:='trim(tmplist[1])';
for i:=0 to filelist.count - 1 do
begin
s:=filelist[i];
s:=copy(s,2,4);
s:=copy(s,1,3);
//showmessage(s);
if s=compcode then
begin
oldrecord:=1;
filelist[i]:=':'+compcode+':'+edit9.text+':'+edit11.Text;
filelist.SaveToFile('C:\对照表.txt');
end;
end;
finally
if oldrecord=0 then
begin
newline:=':'+edit8.Text+':'+edit9.Text+':'+edit11.Text;
filelist.Add(trim(newline));
filelist.SaveToFile('C:\对照表.txt');
end;
filelist.Free;
end;end; 对照表文本内容:
:123:123456:aaaaaaaaaa
:222:111111:bbbbbbbbbbbb
...现在问题是程序每次插入新行的时候总是在新行的下一行出现一个乱码,比如上文插入后变成了:
:123:123456:aaaaaaaaaa
:222:111111:bbbbbbbbbbbb
:444:444444:4444444
惿A
:333:444444:4444444
惿A怎么才能不出现‘惿A ’这一行啊,是我程序有问题吗??谢谢各位大人
hehuiprocedure Tmainform.Button6Click(Sender: TObject);
var
s,newline,compcode:string;
compname,password:string;
f:textfile;
// tmplist:tstrings;
filelist:TStrings;
i,oldrecord,succ:integer;
begin
oldrecord:=0;
compcode:=edit8.Text;
password:=edit9.Text;
compname:=edit11.Text;
newline:=':'+compcode+':'+password+':'+compname;
filelist:=TStringList.Create;
filelist.LoadFromFile('C:\对照表.txt');
try
extractstrings([':'],[],pchar(filelist),filelist);
//edit7.Text:='trim(tmplist[1])';
for i:=0 to filelist.count - 1 do
begin
s:=filelist[i];
s:=copy(s,2,4);
s:=copy(s,1,3);
//showmessage(s);
if s=compcode then
begin
oldrecord:=1;
filelist[i]:=':'+compcode+':'+edit9.text+':'+edit11.Text;
filelist.SaveToFile('C:\对照表.txt');
end;
end;
finally
if oldrecord=0 then
begin
newline:=':'+edit8.Text+':'+edit9.Text+':'+edit11.Text;
filelist.Add(trim(newline));
filelist.SaveToFile('C:\对照表.txt');
end;
filelist.Free;
end;end; 对照表文本内容:
:123:123456:aaaaaaaaaa
:222:111111:bbbbbbbbbbbb
...现在问题是程序每次插入新行的时候总是在新行的下一行出现一个乱码,比如上文插入后变成了:
:123:123456:aaaaaaaaaa
:222:111111:bbbbbbbbbbbb
:444:444444:4444444
惿A
:333:444444:4444444
惿A怎么才能不出现‘惿A ’这一行啊,是我程序有问题吗??谢谢各位大人
解决方案 »
- 在运行时怎么把一个窗体拖放到另一个窗体里?
- 关于Delphi用数组链表的问题!
- FastReport4forCodeGearRADStudioDelphiCBuilder2009.exe 安装出错,如何处理?
- 恭喜95贱人
- 求教高手:delphi 对msxml接受 中文乱码问题? 急!!!!!!!!!!
- combobox中插入线条是怎么实现的?
- 【调查】 大家都用DELPHI的那个版本?都做那方面开发呀?
- 请问一个MDI基本问题
- 想学delphi,环境是delphi6,要如何才能学会呢??有什么要准备??
- 关于Delphi的资源文件!
- 请问各位大虾:如何把cookie内容加入Tidhttp.post中?!
- delphi5在windowXP上为什么设断点不起作用?如何解决?
这句话有问题
filelist.Add(trim(newline));
filelist.SaveToFile('C:\对照表.txt');这段改为:
assignfile(f,'...');
append..
write..
closefile..
.
extractstrings([':'],[],pchar(filelist),filelist); 这句代码上
pchar(filelist)你这句的意识是不是想把filelist的内容转换成PChar
但是事实上不是,你 showmessage 一下就知到了
应该是pchar(filelist.text),
比如:123:123456:aaaaaaaaaa
:222:111111:bbbbbbbbbbbb
:444:444444:4444444当找到222时候,把:222:111111:bbbbbbbbbbbb这行替换掉。应该怎么做好点??
filelist.SaveToFile('C:\对照表.txt');时候能替换原来的文本文件,而不是添加到末尾?????
filelist.Add(trim(newline));
filelist.SaveToFile('C:\对照表.txt');
filelist.LoadFromFile('C:\对照表.txt');
try extractstrings([':'],[],pchar(filelist.text),filelist);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(我现在的问题是 这里的filelist.text内容是对照表里的文件内容的2倍,即内容被复制了一份。用shouwmessage(filelist.text)显示出来的内容:如本来应该是:
222:111111:bbbbbbbbbbbb
:444:444444:4444444
而现在变成了
:222:111111:bbbbbbbbbbbb
:444:444444:4444444
:222:111111:bbbbbbbbbbbb
:444:444444:4444444
这个是什么原因呢????)
for i:=0 to filelist.count - 1 do
begin
s:=filelist[i];
s:=copy(s,2,4);
s:=copy(s,1,3);
//showmessage(s);
if s=compcode t
templist,所以要手动清空procedure TForm1.Button1Click(Sender: TObject);
var
s,newline,compcode:string;
compname,password:string;
f:textfile;
// tmplist:tstrings;
filelist:TStrings;
templist:TStrings; //加一个临时的Strings------------------
i,oldrecord,succ:integer;
begin
oldrecord:=0;
compcode:=edit8.Text;
password:=edit9.Text;
compname:=edit11.Text;
newline:=':'+compcode+':'+password+':'+compname;
filelist:=TStringList.Create;
templist := TStringList.Create;
filelist.LoadFromFile('C:\对照表.txt');
try
for i := 0 to filelist.Count - 1 do begin
templist.clear();
extractstrings([':'],[':'],pchar(filelist[i]),templist);
s:=templist[0];
if s=compcode then
begin
oldrecord:=1;
filelist[i]:=':'+compcode+':'+edit9.text+':'+edit11.Text;
filelist.SaveToFile('C:\对照表.txt');
end;
end;
finally
if oldrecord=0 then
begin
// filelist.Clear;
newline:=':'+edit8.Text+':'+edit9.Text+':'+edit11.Text;
filelist.Add(trim(newline));
filelist.SaveToFile('C:\对照表.txt');
end;
filelist.Free;
templist.Free;
end;
end;