кол-во строк мне нужно для prograssbar`a code:
| Код | procedure TLogToDBForm.Button1Click(Sender: TObject); var SL:TStringList; Qry:TQuery; FI:TextFile; Buff:String; i, t:integer; begin t:=GetTickCount; Memo1.Lines.LoadFromFile(ExtractFilePath(Application.ExeName)+'Log.txt'); PB.Position:=0; PB.Max:=Memo1.Lines.Count-1; Memo1.Clear; AssignFile(FI,'Log.txt'); Reset(FI); if FileExists('Log.db') then DeleteFile('Log.db'); try Qry:=TQuery.Create(nil); Qry.SQL.Text:='create table Log (FullName varchar(255), '+ 'FPath varchar(255), FName varchar(50), FType varchar(8), FSize float)'; Qry.ExecSQL; while not Eof(FI) do begin try SL:=TStringList.Create; Readln(FI,Buff);
lInfo.Caption:=inttostr(PB.Position+1)+', '+inttostr(length(Buff)); if strtoint(lLength.Caption)<length(Buff) then lLength.Caption:=inttostr(length(Buff));
ExtractStrings([eSeparator.Text[1]], [' '], PChar(Buff), SL); if SL.Count=5 then begin with Qry.SQL do begin Clear; Add('insert into Log values ('); Add(''''+SL.Strings[0]+''','); Add(''''+SL.Strings[1]+''','); Add(''''+SL.Strings[2]+''','); Add(''''+SL.Strings[3]+''','); Add(SL.Strings[4]+')'); end; try Qry.ExecSQL; except on E:Exception do begin mErrors.Lines.Add('++++++++++++++++++++++++++++++++++++++++++++++'); mErrors.Lines.Add('SQL Error:'); mErrors.Lines.Add(E.Message); mErrors.Lines.Add('SQL:'); mErrors.Lines.Add(Qry.SQL.Text); lErorrs.Caption:=inttostr(strtoint(lErorrs.Caption)+1); end; end; end else begin with mErrors.Lines do begin Add('----------------------------------------------'); Add('SL.Count='+inttostr(SL.Count)+' Line='+inttostr(PB.Position+1)); for i:=0 to SL.Count-1 do Add('SL.Strings['+inttostr(i)+']: '+SL.Strings[i]); lErorrs.Caption:=inttostr(strtoint(lErorrs.Caption)+1); end; end; PB.Position:=PB.Position+1; finally SL.Free; end; Memo1.Lines.Add('----------------------------------------------'); Memo1.Lines.Add(Buff); lTime.Caption:=inttostr(GetTickCount-t); Application.ProcessMessages; end; finally Qry.Free; end; end;
|
зы: создаю stringlist в цикле из-за того, что не работает SL.Clear... странно оО =( Знаю, что будет быстрее работать, если создать параметры. |