R: TZQuery;
S: TDataSource;
begin
R := TZQuery.Create(nil);
S := TDataSource.Create(nil);
R.Connection := FicheAccueil.ConnexionPQ; // ConnexionPG is dropped on "FicheAccueil" form
R.SQL.Text := 'SELECT nor_repertoire FROM s_ent.t_e_norme_nor WHERE nor_id=1;';
R.Open;
R.Active:=true;
S.DataSet:=R.???; // Here is my problem, I don't know what put in there.
S.Enabled:=true;
end;
When I drop ZQuery and TDataSource on that form and connect them by the Object Inspector, it works well.
Thanks for your help.
Michel.
Thanks jan for your advice.
All is working OK now.
Another question about the differences and benefits between creating ZQuery and DataSource by code or dropping these two components on the form?
Michel
Miflon wrote: ↑05.12.2019, 11:26
Another question about the differences and benefits between creating ZQuery and DataSource by code or dropping these two components on the form?
Hello,
errm . there is next to no difference - besides you needing to do a lot of work if you do things in code. Things that you put on the form at design time are managed by Lazarus for you. If you do this by hand, you need to do all the management...
It depends on the context, really. For datasets doing work through the applications lifetime, I'm always using design time. If I need a bit of information from the database (or inserting / editing a record in a specific table) I'm always creating it runtime.
As time passed I was drawn to be Class-y. Meaning, I write a class for everything, doing only one job, publishing only the necessary properties. While it has it's advantages like reusability...
...I'm creating ~85% of my queries in runtime
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
I also use short-living query objects for little tasks. I get it with DataModule.GetTempQuery, do what I need and forget about it. As the returned query is wrapped with interface, it is destroyed automatically
I have a general fear about interfaces and garbage collecting languages (like Java & C#). Even if I create a visual component during runtime, I always create it with .Create(nil) and destroy it by myself when it's not needed anymore. This way I can be sure that it is properly disposed at a time when it SHOULD be disposed.
Don't blame me - I have no trust in things which I cannot see
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
The difference between auto-managed types and GC is that with the former you always can tell when resources are freed and in the latter you can't. Auto-managed types could make code significantly shorter and cleaner.