try
AssignFile(plik, Utf8ToAnsi(SaveDialog.FileName));
Rewrite(plik);
Form1.QueryReports.First;
Count := Form1.QueryReports.FieldCount - 1;
pg.Max := Form1.QueryReports.RowsAffected;
pg.Position := 0;
Form1.Datasource1.Enabled := False;
Form1.Datasource1.DataSet := nil;
//nagłówek
for i := 0 to Count do
begin
if i = Count then
Writeln(plik, '"' + Form1.QueryReports.FieldDefs[i].DisplayName + '"')
else
Write(plik, '"' + Form1.QueryReports.FieldDefs[i].DisplayName + '"' + ',');
end;
//zawartość pliku
while not Form1.QueryReports.EOF do
begin
for i := 0 to Count do
begin
if i = Count then
begin
tmp_string:= '"' + StringReplace(Form1.QueryReports.Fields[i].AsString, '"', '^', [rfIgnoreCase, rfReplaceAll]) + '"';
tmp_string:= StringReplace(tmp_string, #13, ' ', [rfIgnoreCase, rfReplaceAll]);
tmp_string:= StringReplace(tmp_string, #10, ' ', [rfIgnoreCase, rfReplaceAll]);
Writeln(plik, tmp_string);
end
else
begin
tmp_string:= '"' + StringReplace(Form1.QueryReports.Fields[i].AsString, '"', '^', [rfIgnoreCase, rfReplaceAll]) + '"' + ',';
tmp_string:= StringReplace(tmp_string, #13, ' ', [rfIgnoreCase, rfReplaceAll]);
tmp_string:= StringReplace(tmp_string, #10, ' ', [rfIgnoreCase, rfReplaceAll]);
Write(plik, tmp_string);
end;
end;
Form1.QueryReports.Next;
pg.Position := pg.Position + 1;
end;
CloseFile(plik);
ShowMessage(Form1.GetLanText('Eksport zakończony!'));
pg.Position := 0;
Form1.Datasource1.DataSet := Form1.QueryReports;
except
on E: Exception do
Form1.Log('ERROR >> ' + E.Message + ' ' + IntToStr(E.HelpContext));
end;
Heap dump by heaptrc unit
1002361 memory blocks allocated : 886168757/890603048
944126 memory blocks freed : 452070306/456341968
58235 unfreed memory blocks : 434098451
True heap size : 448954368 (112 used in System startup)
True free heap : 10104368
Should be : 10966136
Call trace for block $087554F8 size 28
$004CABEA TFORMA_RAPORTY__MENUITEM14CLICK, line 200 of form_raporty.pas
$00601568 TMENUITEM__CLICK, line 83 of ./include/menuitem.inc
$00601B26 TMENUITEM__DOCLICKED, line 278 of ./include/menuitem.inc
$0040C0F6
$75877694
$75878BAA
$75878468
$75879C40
Call trace for block $087A07B8 size 14
$004CABBD
$00601568
$00601B26
$0040C0F6
$75877694
$75878BAA
$75878468
$75879C40
Call trace for block $4140A270 size 42764
[...]
Heap dump by heaptrc unit
1828722 memory blocks allocated : 1735404672/1743811016
1760487 memory blocks freed : 873666230/881869944
68235 unfreed memory blocks : 861738442
True heap size : 885948416 (112 used in System startup)
True free heap : 18618432
Should be : 19640192
[...]
Heap dump by heaptrc unit
2660904 memory blocks allocated : 2585303174/2597715304
2582669 memory blocks freed : 1295924723/1308094224
78235 unfreed memory blocks : 1289378451
True heap size : 1322942464 (112 used in System startup)
True free heap : 27132464
Should be : 28314232
[...]
Code: [Select]Heap dump by heaptrc unit
1002361 memory blocks allocated : 886168757/890603048
944126 memory blocks freed : 452070306/456341968
58235 unfreed memory blocks : 434098451
True heap size : 448954368 (112 used in System startup)
True free heap : 10104368
Should be : 10966136
Call trace for block $087554F8 size 28
$004CABEA TFORMA_RAPORTY__MENUITEM14CLICK, line 200 of form_raporty.pas
(..)
Sample lazarus app has been added with DDL. (Into reported bug)No problem. Simplified it to an FPC console program and see the problem in FPC 2.6.2 x86 and trunk x86 on Windows.
Thanks and sorry
The report is initially displayed in DBgrid. I have to turn off displaying before export, because it dramatically slowing process.Use enable/disablecontrontrols to set your display of.
begin
try
SQLQuery.disablecontrols;
......
finally
SQLQuery.enablecontrols;
end;
end;
Quote from: mithThe report is initially displayed in DBgrid. I have to turn off displaying before export, because it dramatically slowing process.Use enable/disablecontrontrols to set your display of.Code: [Select]begin
try
SQLQuery.disablecontrols;
......
finally
SQLQuery.enablecontrols;
end;
end;
I'm trying to export data to a *.csv file using a TSQLQuery (connected to a postgres database). Everything works fine for a small results. When the result is bigger (for example 80k rows, each with 6 fields of varchar 255 - which isn't of course huge amount of data), my program exhausts all possible memory (more than 1,5GB). I'm wondering what's wrong. D