baeckerg 6 Posted July 18, 2019 Hi, in a program I have a central FireDAC connection to my database in a datamodule. I intend to have all record related activities (CRUD) in a class that holds the record. My questions are: 1) is there any penalty if I pass the connection (as var parameter?) to the constructor of the class? 2) is this the best way to separate the data from the UI? many thanks in advance Gernot Share this post Link to post
PeterBelow 238 Posted July 18, 2019 1 hour ago, baeckerg said: Hi, in a program I have a central FireDAC connection to my database in a datamodule. I intend to have all record related activities (CRUD) in a class that holds the record. My questions are: 1) is there any penalty if I pass the connection (as var parameter?) to the constructor of the class? 2) is this the best way to separate the data from the UI? many thanks in advance Gernot For 1: If you like to set up the connection at design-time in a datamodule the approach is OK, and you do not need to pass the connection object as a Var parameter. Objects are reference types, so you pass a reference to the connection object, and that can even be done as const, since you can work with the object's properties or pass the reference on this way as well. Just do not free the connection object in the "record class", it belongs to the datamodule and will be freed by it when the datamodule is destroyed. For 2: "Best" is hard to define in this context. For a complete separation of the UI from the data it works with you need a bit more than just keeping connection and query/table objects out of the forms/frames and business logic code out of event handlers there. But writing a model-view-presenter framework or a full-blown object-relational mapper (ORM) framework from scratch is a lot of work. For smaller projects it may not pay to go to these length, especially if you only aim for one platform with a desktop client. Share this post Link to post
baeckerg 6 Posted July 18, 2019 Thanks for the feedback and the valuable input Free will be part of the datamodule when it is destroyed 🙂 Share this post Link to post
David Schwartz 426 Posted July 20, 2019 TMS has Aurelius that can generate ORM classes for you. Share this post Link to post