D1 Newbie: Little Question on DB Form

D1 Newbie: Little Question on DB Form

Post by Chris L » Sun, 12 May 1996 04:00:00



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

 
 
 

D1 Newbie: Little Question on DB Form

Post by Matthew McDermot » Thu, 16 May 1996 04:00:00



> 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

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/
==================================================================

 
 
 

1. DB-LIB question ( newbie question )

Hi:

Could somebody tell  me what is wrong with the following code ?
When I run it, all I get is my prompt back. The table has the entry
'niranjan', 'T&F' in it.

I compile the program as
cc -I/sybase/include -L/sybase/lib example.c -lsybdb

The version is sybase 10.1

Also how does one get back a single row as a string. I need  to
delete trailing blanks from each field ? Any suggestion ?

i.e

while ( there are rows ) {
        fetch a row
        remove trailing blanks

peace,

-- Niranjan

#include<sybfront.h>
#include<sybdb.h>
#include<syberror.h>
#include "sybdbex.h"

main()
{
        DBPROCESS *dbproc;
        LOGINREC *login;
        RETCODE return_code;

        login = dblogin();
        DBSETLUSER(login,USER);
        DBSETLPWD(login,PASSWORD);
        DBSETLAPP(login,"a.out");

        dbproc = dbopen(login, NULL );
        if(dbproc == NULL)
                exit(ERREXIT);  

        dbcmd(dbproc, "use tempdb");
        dbcmd(dbproc, "select * from emp");
        if(dbsqlexec(dbproc) == FAIL)
        {
                dbexit();
                exit(ERREXIT);
        }

        while(dbresults(dbproc) != NO_MORE_RESULTS)
                dbprrow(dbproc);

        dbexit();
        exit(STDEXIT);

2. Saving and retrieving Ole-Automation objects from Dao and MFC using CLongBinary class

3. ReportSmith and Form Reports (D1)

4. Informix Query takes 10 times longer than Orrible

5. The same table in two forms in D1

6. Unix database to Windows database

7. D1: using TTables across forms ?

8. msaccess

9. D1-Tfield not in grid but on form-Possible

10. Writing File New, Save, Open code for D1 Database form

11. Passing data between forms - a newbie question

12. Newbie questions about Win 5.0 forms (sort of long)

13. Newbie question re Forms 6.0