How to create a new TSQLQuery in a DataModule at runtime lazarus / 63-Database ---------------------------------------------------------------------- JanRoza · 2017-10-23 14:29 Has anyone any experience with creating TSQLQueries at runtime in an existing DataModule? A simple example would be of great help. Thanks! ---------------------------------------------------------------------- taazz · 2017-10-23 14:35 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 uses db, sqldb, ..... ; Function QueryDB(Const aDB :TCustomConnection; aCommand :String; Const aTransaction :TSQLTransaction) :TSQLQuery;begin  Result := TSQLQuery.Create(nil);//<- set it to either self or the component that will free it when finished its job  Result.DataBase := aDB;  if Assigned(aTransaction) then Result.Transaction := aTransaction;  Result.SQL.Text := aCommand;  Result.Open;end; Make sure that you pass it only select statements no delete, update or metadata. ---------------------------------------------------------------------- JanRoza · 2017-10-23 15:24 Thanks Taazz! I'll play with this and see how far it will get me. The idea I'm playing with is to create a Windows database program like the old but famous DOS program PC-File where a user can define its own table structures (which I store in a table definitions table). So when the program starts only the dbconnection and the table containing the user-table definitions are opened in the OnCreate of the dataModule. After that I need to make a routine that creates the other SQLqueries in the DataModule from the data that is read from the definitions table. A nice puzzle, that will keep me from doing bad things.