导入:
procedure RegulateStr(aString:String;Sepchar:String;Isfirst:boolean);
//aString 为取出的字符串,Sepchar为分隔符.
var
Num:Integer;
MyStr,qryStr:String;
begin
Num:=0;
//i:=length(aString);
while length(astring)<>0 do begin
mystr:=copy(astring,1,pos(sepchar,astring)-1);//截取子符串
delete(astring,1,pos(sepchar,astring)); //删除子符串
if mystr=''then mystr:='1.00'; //防止空字符
if Isfirst then begin//如果是第一条,则特殊处理。
Form1.Query1.fields[Num].DisplayLabel:=mystr;
end else
begin
Form1.Query1.Fields[Num].AsString:=mystr;
end;
Num:=Num+1;
end;
end;
procedure TForm1.N7Click(Sender: TObject);
var
filestr:Textfile;
recoStr:string;
begin
OpenDialog1.Filter:='ASCII Files(*.TXT)|*.txt';
if OpenDialog1.Execute then
begin
Screen.Cursor:=crHourGlass;
assignfile(filestr,opendialog1.filename);
Reset(filestr);
Readln(filestr,recostr);//读出一行字符串。
RegulateStr(recostr,'|',true);
while not eof(filestr) do
begin
Query1.Insert;
Readln(filestr,recostr);
RegulateStr(recostr,'|',false);//循环取出所有子符串。
Query1.Next;
//读下一行。
end;
end;
Screen.Cursor:=crdefault;
Application.MessageBox('操作在没有警告的情况下正常结束!','完成',mb_ok+mb_iconinformation);
closefile(filestr);
end;
end.