procedure TCDCdb.ScanImagesDirectory(ImagePath: string; ProgressCat: Tlabel; ProgressBar: TProgressBar); var c, f: tsearchrec; i, j, n, p: integer; catdir, objn, fname, cmd: string; dummyfile: boolean; ra, de, w, h, r: double; ms : QWord; //NEW begin try if DirectoryExists(ImagePath) then begin try if DB.Active then begin ProgressCat.Caption := ''; ProgressBar.position := 0; ms :=GetTickCount64; //NEW j := findfirst(slash(ImagePath) + '*', faDirectory, c); while j = 0 do begin if ((c.attr and faDirectory) <> 0) and (c.Name <> '.') and (c.Name <> '..') then begin catdir := slash(ImagePath) + c.Name; ProgressCat.Caption := c.Name; ProgressBar.position := 0; Application.ProcessMessages; DB.UnLockTables; DB.starttransaction; cmd := 'delete from cdc_fits where catalogname="' + uppercase(c.Name) + '"'; DB.query(cmd); DB.commit; i := findfirst(slash(catdir) + '*.*', 0, f); n := 1; while i = 0 do begin Inc(n); i := findnext(f); end; ProgressBar.min := 0; ProgressBar.max := n; if (ProgressBar.Max > 250) then ProgressBar.Step := ProgressBar.Max div 250 else ProgressBar.Step := 1; i := findfirst(slash(catdir) + '*.*', 0, f); n := 0; db.StartTransaction; // USE THIS while i = 0 do begin if f.Name = 'README.TXT' then begin i := findnext(f); continue; end; Inc(n); if (n mod ProgressBar.step) = 0 then begin ProgressBar.stepit; Application.ProcessMessages; end; // NEW statement if GetTickCount64-ms > 1000 then begin Application.ProcessMessages; ms := GetTickCount64 end; dummyfile := uppercase((extractfileext(f.Name))) = '.NIL'; if dummyfile then begin ra := 99 + random(999999999999999); de := 99 + random(999999999999999); w := 0; h := 0; r := 0; fname := slash(catdir) + f.Name; end else begin // this is much faster than cdcwcs_getinfo FFits.FileName := slash(catdir) + f.Name; ra := FFits.Center_RA; de := FFits.Center_DE; w := FFits.Img_Width; h := FFits.img_Height; r := FFits.Rotation; fname := FFits.FileName; end; if FFits.header.valid or dummyfile then begin objn := extractfilename(f.Name); p := pos(extractfileext(objn), objn); objn := copy(objn, 1, p - 1); objn := uppercase(stringreplace(objn, blank, '', [rfReplaceAll])); cmd := 'INSERT INTO cdc_fits (filename,catalogname,objectname,ra,de,width,height,rotation) VALUES (' + '"' + stringreplace(fname, '\', '\\', [rfReplaceAll]) + '"' + ',"' + uppercase(c.Name) + '"' + ',"' + uppercase(objn) + '"' + ',"' + formatfloat(f5, ra) + '"' + ',"' + formatfloat(f5, de) + '"' + ',"' + formatfloat(f5, w) + '"' + ',"' + formatfloat(f5, h) + '"' + ',"' + formatfloat(f5, r) + '"' + ')'; // Separator is SQL command is only needed // if send group of commands at once DB.Execute(cmd); // CORRECT WAY, Query method was the problem //writetrace(Format(rsDBInsertFail, [f.Name, DB.ErrorMessage])); end else writetrace(Format(rsInvalidFITSF, [f.Name])); i := findnext(f); end; DB.commit; findclose(f); end; j := findnext(c); end; DB.flush('tables'); end; finally findclose(c); end; end else begin ProgressCat.Caption := 'Directory not found!'; end; except end; end;