Board index » delphi » D1 Newbie: Little Question on DB Form

D1 Newbie: Little Question on DB Form

1. Where is the best place to open Database files?
   On Create or On Show Event!? Why?

   procedure TBookForm.FormCreate(Sender: TObject);
   begin
     BookTable.Open;
     PaxTable.Open;
   end;

2. If one of the above database can't open in any reason, how to I
write the exception to show the error and close the form afterward.

3. Where is the best place and when (before Post or on field Exit) for
field vaildation?

4. It should be most grateful if someone can post a sample program
which show how to open a Database, record locking, edit and validate
fields, posting and closing it. Sure it need to detect all kind of
exception(s).

Regards,
Chris

 

Re:D1 Newbie: Little Question on DB Form


Quote
Chris Lee wrote:

> 1. Where is the best place to open Database files?
>    On Create or On Show Event!? Why?

>    procedure TBookForm.FormCreate(Sender: TObject);
>    begin
>      BookTable.Open;
>      PaxTable.Open;
>    end;

Depends on what you want to do. If you want to keep the tables open, even if the user never sees
the form, use OnCreate.

Quote
> 2. If one of the above database can't open in any reason, how to I
> write the exception to show the error and close the form afterward.<WARNING: Not tested, but it should give you an idea...>

try
  Table1.Open;
  Table2.Open;
except
  on e : EDBEngineError {I think???} do
    ShowMessage('Cannot open data table');
    {You can do other things in here to protect your code.}
end;{try}

Quote

> 3. Where is the best place and when (before Post or on field Exit) for
> field vaildation?

Your call, try both and see what works best. I prefer OnBeforePost.

Quote
> 4. It should be most grateful if someone can post a sample program
> which show how to open a Database, record locking, edit and validate
> fields, posting and closing it. Sure it need to detect all kind of
> exception(s).

If you are using a Database component, use the Connected property.
Record Locking with Paradox tables is automatic.
Edit is optionally automatic. Set AutoEdit to True.
Validate OnBeforePost.

Chris, these issues are the BIGGIES when creating a database apps. Everyone here is dealing with
them. I know there are as many different ways of performing thee tasks as there are programmers.
If after reading this response you think it is too vague, e-mail me. I'll put together some code
fragments and try to get you up to speed.

Good luck.

Matthew

--

==================================================================
Matthew McDermott
McDermott Enterprises
matt...@valleynet.com
My Web Page: http://www.valleynet.com/~matthew
------------------------------------------------------------------
Director of Information Services & Adjunct Professor - Mathematics
The American College of Prehospital Medicine: http://www.acpm.edu/
==================================================================

Other Threads