I knew I could count on Graeme for an answer (and a plug ;) On 20/09/2011 14:42, Graeme Geldenhuys wrote: [snip] > > Maybe we should stop you right there, and teach you the "correct" > OOP way of doing database programming. :) No GUI unit should contain > code as listed above...
That was just an example. the 'hello world' of databases :P and only included cause I got an SIGSEGV in it... > Database connections, Query components, > embedded SQL, manual transaction handling etc. Yuck! Instead, use a > OPF (Object Persistent Framework) that hides all that ugliness and > let you only work with Business/Data Objects instead - the true OOP > way. Thing is - I may not need to know how the sewers work, that they need to be laid with some sort of descent ;) or that you should not use thin walled plastic pipes 15 meters underground ;) but it helps to know where the manhole covers are in case it rains, so your car won't get washed away when you build your garage over one... > > For a broad overview of tiOPF (a free OPF framework for Delphi and > Free Pascal, and that works with VCL, LCL and fpGUI), see the > following URL. > > http://tiopf.sourceforge.net/Doc/Concepts/index.shtml > Thanks. Will have a read. > > For example, changing your code above to something as shown below: > [snip code] Thing is, this is yet another abstraction layer... see my remark about sewers. My understanding of abstractions so far tries to embrace simple OOP and inheritance, I don't even understand Interfaces yet... > > NOTE: The above code is done manually to show you the details of how > it works. You can also use the "RAD" style of development, by > dropping a TtiModelMediator component on a form and hooking up the > properties via the Object Inspector. > Yeah that's cool, but yeah, the target when it's prime-time will be non-visual, at least in one end... > > Now, saving the list back to the database is as simple as... > > oList.Save; > > Transaction handling, rollback on error etc are all handled for you. > Never been happier, still -see my remark about sewers. (Or LWN article about abstraction trap) > OPF frameworks like tiOPF really make using databases easy - > including creating UI for your data. tiOPF also works with multiple > database (Firebird, MySQL, Oracle, MDB, etc) and multiple database > connection components (SqlDB, FBLib, dbExpress, Zeos, UIB, OIB etc). > So you are definitely NOT locked into some specific vendor or suite > of components. And as you have seen from the example above, you > application code doesn't need to change at all, even if you switch > from Firebird to PostgreSQL, or from SqlDB to UIB components. It's > all simply controlled by a single compiler define. > > > http://www.tiopf.com > > See also the Lazarus wiki page: > > http://wiki.lazarus.freepascal.org/tiOPF > > > tiOPF has been used in production environments for well over a > decade and has just under 2000 unit tests which run hourly to make > sure it stays rock solid. > Should have added (PLUG) into topic ;) > > Regards, - Graeme - > Thanks for this, many hours of reading, here I come. Lukasz -- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
