SQLQuery/DBGrid Export to Excel lazarus / 31-LCL ---------------------------------------------------------------------- sfdoony · 2025-08-11 17:07 Hi Gurus, I tried to dump the content in DBGrid or SQLQuery to excel. After searched on the forum I found in some posts there mentioned     if SaveDialog1.Execute then     with CSVExporter1.Create(nil) do begin        //Dataset:= BufDataSet1;        Dataset:= SQLQueryWords.DataBase.DataSets[0];        FileName:= SaveDialog1.FileName;        Execute;        Free;     end; However, when coming to "with CSVExporter1.Create(nil) do begin", here is one fatal error: Access violation reading from address $000... Could you please kindly advise? Thank you. ---------------------------------------------------------------------- wp · 2025-08-11 17:56 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i with TCSVExporter.Create(nil) do begin   ... ---------------------------------------------------------------------- CharlyTango · 2025-08-12 09:41 Your variable names look like you have put at least a TSaveDialog component and a TCSVExporter component on your form. That results in Lazarus creating two variables for you: SaveDialog1 and CSVExporter1. If my assumption is right then this code could work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  if SaveDialog1.Execute then    with CSVExporter1 do begin       Dataset:= SQLQueryWords.DataBase.DataSets[0];       FileName:= SaveDialog1.FileName;       Execute;       Free;    end; Lazarus will create and destroy the TCSVExporter component for you. Otherwise the suggestion of wp will work. my next assumption is that you saw the code at https://wiki.freepascal.org/lazdbexport but in your case https://wiki.freepascal.org/TCSVExporter could be better.