[Lazarus] [Long and partially OT] Database (OOP) programming: beginners manual?

Joost van der Sluis joost at cnoc.nl
Tue Sep 20 17:11:07 CEST 2011


On Tue, 2011-09-20 at 15:42 +0200, Graeme Geldenhuys wrote:
> On 20/09/2011 14:53, Lukasz Sokol wrote:
> > procedure TForm1.Button1Click(Sender: TObject);
> > begin
> >   if Label1.Caption = 'ODBC Disconnected' then
> >     if OpenDialog1.Execute then
> >       begin
> > 
> >         ODBCConnection1.Params.Add('DBQ='+OpenDialog1.FileName);
> >        // ODBCConnection1.Open;
> >         SQLQuery1.SQL.Clear;
> >         SQLQuery1.SQL.Add('SELECT * FROM MyTable');
> >         SQLQuery1.Open;  // SIGSEGV when calling a second time
> >         exit;
> >       end;
> > ...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... 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.

I don't think that you can help anyone on this list with answers to
questions which aren't posed:

Q: "How do I solve this problem in method 'A'"?
A: "Well, use method 'B', it's better."

First of all it is not the answer to the question. And secondly in this
case it does not solve the problem, because the underlying
database-problem will also occur when this is all rewritten to use a
proper OPF.

I know that you do not want to advertise tiOPF alone, but also want to
teach people something. But this time the answer is completely
unrelated. And if you really couldn't it could have been much shorter.
Like: 'Hmm... I can not help you with your problem, but maybe you could
take a look at a better design of your code and split your GUI-code from
the actual work. Google for ....'

Joost

-- 
My Lazarus blog: http://www.lazarussupport.com/lazarus/weblog





More information about the Lazarus mailing list