求助.memo1.Lines.Count我得到的数据怎么少1位
delphi吧
全部回复
仅看楼主
level 3
提取文本文件中的数据到dbf表中,另一窗体一段完全相同的代码没问题 可在form7提取的数据始终少1代码如下
begin
form7.checkbox1.Checked:=true;
Label1.Visible:=true;
form1.ADOQuery1.Close;
form7.ADOTable2.Close;
ADOTable2.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+form1.FileListBox1.Directory+';Extended Properties=dBase 5.0;Persist Security Info=False';
ADOTable2.TableName:='01.dbf';
//ADOQuery1.Close;
//ADOQuery1.SQL.Clear;
ss1:=TStringList.Create;
ss1.Delimiter:='$';
ss1.DelimitedText :=form1.memo1.Lines[0];
if ss1.Count < 4 then showmessage('文件错误,请检查是否为数据文件')
else
begin
form7.Button1.Visible:=false;
form7.ADOTable2.open;
form1.DataSource1.AutoEdit:= False;
j:=form1.memo1.Lines.Count;
label1.Caption:=inttostr(form1.memo1.Lines.Count); //这里得到的是数目是对的
for i:=0 to form1.memo1.Lines.Count do // 这里取得的数目就少1
begin
s:=form1.memo1.Lines[i];
s:= StringReplace(s,' ','',[rfReplaceAll]); //清除信息中的空格
if s<>'' then
begin
ss1.DelimitedText :=s;
ProgressBar1.Position:=(i*100) div (j);
Label1.Caption:='已处理信息'+' '+inttostr(i)+' '+'条,请稍候!';
Application.ProcessMessages;
if ADOTable2.Locate('no',ss1[0],[]) then //查找相同项目
begin
with ADOTable2 do
begin
edit;
2016年07月21日 13点07分 1
level 3
[不高兴]求高人 实在没看出来哪里错了
2016年07月21日 13点07分 2
level 6
count应该减一
2016年07月21日 13点07分 3
原本代码就是减1的,然后把减1去掉也是不行 j:=form1.memo1.Lines.Count-1; //Count-1; label1.Caption:=inttostr(form1.memo1.Lines.Count); for i:=0 to form1.memo1.Lines.Count-1 do // Count-1 代码是这样也并没有效果,得到的数目依然少1 伤心
2016年07月21日 13点07分
level 11
count是行数,9行可以用1-9遍历,也可以用0-8遍历。
如果看不懂就自己慢慢琢磨
2016年07月22日 01点07分 4
level 7
你要习惯编程世界里许多种计数都是从0开始而非1。
2016年08月19日 00点08分 5
level 8
j的count不用-1,i的要
2016年09月02日 14点09分 6
level 1
for i:=0 to form1.memo1.Lines.Count - 1 do
begin
end
2016年09月12日 08点09分 8
1