Board index » delphi » Accessing database data from a stand-alone unit

Accessing database data from a stand-alone unit

On 17 Oct 1996 02:41:18 GMT, Rodney Gicker <rgic...@worldnet.att.net>
you smacked the keyboard repeatedly to write:

[Snip]

Quote
>var
>  bInitialized: boolean;
>  tblMsg:       TTable;

>implementation

>function MsgCreate(AOwner: TComponent): boolean;
>begin
>  try
>    try
>      bInitialized := False;
>      tblMsg.Create(AOwner);

        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Change to:

        tblMsg := TTable.Create(AOwner);

Quote
>      tblMsg.DatabaseName := 'db';

This should be the path where "Message.db" is found.  The name of the
property is somewhat missleading.

Quote
>      tblMsg.TableType := ttParadox;
>      tblMsg.TableName := 'Message.db';
>      tblMsg.Open;
>      bInitialized := True;
>    except
>      on EGPFault do
>         ShowMessage('EGPFault error in QMsg.MsgCreate');
>      on EAbort do
>         ShowMessage('EAbort error in QMsg.MsgCreate');
>      on EBreakpoint do
>         ShowMessage('EBreakpoint error in QMsg.MsgCreate');
>      on EConvertError do
>         ShowMessage('EConvertError error in QMsg.MsgCreate');
>    end;

>Thanks!
>Rod Gicker
>rgic...@worldnet.att.net

Brien King
bk...@primenet.com
 

Re:Accessing database data from a stand-alone unit


To anyone who can help:

I'm an experience VB programmer who is trying to learn Delphi on my own.  
I'm currently trying to create a stand-alone unit (i.e. one that is not
connected to a form) that access data from a Paradox table.

I have added a database component to a form in my project and reference
it from the code in my stand-alone unit.

The problem I have is that each time I try to run the program I get an
EGPFault error!  I've tried a number of things, including explicitly
calling the .create property for the TTable variable I've created, but I
continue to get the same error.

If I drop a table, source, and dbgrid component on a form and use the same
database and table everything works fine.

I'm sure this is a very basic error, but I'm completely lost.  If anyone
can offer any help I'd really appreciate it.

The code I'm using is shown below:

var
  bInitialized: boolean;
  tblMsg:       TTable;

implementation

function MsgCreate(AOwner: TComponent): boolean;
begin
  try
    try
      bInitialized := False;
      tblMsg.Create(AOwner);
      tblMsg.DatabaseName := 'db';
      tblMsg.TableType := ttParadox;
      tblMsg.TableName := 'Message.db';
      tblMsg.Open;
      bInitialized := True;
    except
      on EGPFault do
         ShowMessage('EGPFault error in QMsg.MsgCreate');
      on EAbort do
         ShowMessage('EAbort error in QMsg.MsgCreate');
      on EBreakpoint do
         ShowMessage('EBreakpoint error in QMsg.MsgCreate');
      on EConvertError do
         ShowMessage('EConvertError error in QMsg.MsgCreate');
    end;

Thanks!
Rod Gicker
rgic...@worldnet.att.net

Re:Accessing database data from a stand-alone unit


In article <5446ce$...@mtinsc01-mgt.ops.worldnet.att.net> Rodney Gicker <rgic...@worldnet.att.net> writes:

Quote
>From: Rodney Gicker <rgic...@worldnet.att.net>
>Subject: Accessing database data from a stand-alone unit
>Date: 17 Oct 1996 02:41:18 GMT
>To anyone who can help:
>I'm an experience VB programmer who is trying to learn Delphi on my own.  
>I'm currently trying to create a stand-alone unit (i.e. one that is not
>connected to a form) that access data from a Paradox table.
>I have added a database component to a form in my project and reference
>it from the code in my stand-alone unit.
>The problem I have is that each time I try to run the program I get an
>EGPFault error!  I've tried a number of things, including explicitly
>calling the .create property for the TTable variable I've created, but I
>continue to get the same error.
>If I drop a table, source, and dbgrid component on a form and use the same
>database and table everything works fine.
>I'm sure this is a very basic error, but I'm completely lost.  If anyone
>can offer any help I'd really appreciate it.
>The code I'm using is shown below:
>var
>  bInitialized: boolean;
>  tblMsg:       TTable;
>implementation
>function MsgCreate(AOwner: TComponent): boolean;
>begin
>  try
>    try
>      bInitialized := False;
>      tblMsg.Create(AOwner);

 this should be
         tblmsg := ttable.create(AOWNER)

- Show quoted text -

Quote
>      tblMsg.DatabaseName := 'db';
>      tblMsg.TableType := ttParadox;
>      tblMsg.TableName := 'Message.db';
>      tblMsg.Open;
>      bInitialized := True;
>    except
>      on EGPFault do
>         ShowMessage('EGPFault error in QMsg.MsgCreate');
>      on EAbort do
>         ShowMessage('EAbort error in QMsg.MsgCreate');
>      on EBreakpoint do
>         ShowMessage('EBreakpoint error in QMsg.MsgCreate');
>      on EConvertError do
>         ShowMessage('EConvertError error in QMsg.MsgCreate');
>    end;
>Thanks!
>Rod Gicker
>rgic...@worldnet.att.net

pleasure

Boris Ingram, Cyborg Software
boris...@iafrica.com
100076.3...@compuserve.com
http://www.pcb.co.za/users/borising/cyborg.htm

Re:Accessing database data from a stand-alone unit


try this:

Function MsgCreate: boolean;
begin
MsgCreate:= False;
try
  bInitialized := False;
  tblMsg:= nil;
  tblMsg.Create(nil);  {because there is no owner, you must destroy it
later}
  tblMsg.DatabaseName := 'db';
  tblMsg.TableType := ttParadox;
  tblMsg.TableName := 'Message'; {it may be wiser to use a name that is not
a keyword!}
  tblMsg.Open;
  bInitialized := True;
except
  if tblMsg<>nil then tblMsg.destroy;
  {raise;} {activate this to display the error message}
  end;
MsgCreate:= bInitialized;
end;

HTH,

--
Paul Motyer
pa...@linuxserver.pccity.com.au
SoftStuff, Croydon, Vic,  Australia, 3136.

Rodney Gicker <rgic...@worldnet.att.net> wrote in article
<5446ce$...@mtinsc01-mgt.ops.worldnet.att.net>...

Quote
> To anyone who can help:

> I'm an experience VB programmer who is trying to learn Delphi on my own.
> I'm currently trying to create a stand-alone unit (i.e. one that is not
> connected to a form) that access data from a Paradox table.

> I have added a database component to a form in my project and reference
> it from the code in my stand-alone unit.

> The problem I have is that each time I try to run the program I get an
> EGPFault error!  I've tried a number of things, including explicitly
> calling the .create property for the TTable variable I've created, but I
> continue to get the same error.

> If I drop a table, source, and dbgrid component on a form and use the
same
> database and table everything works fine.

> I'm sure this is a very basic error, but I'm completely lost.  If anyone
> can offer any help I'd really appreciate it.

> The code I'm using is shown below:

> var
>   bInitialized: boolean;
>   tblMsg:       TTable;

> implementation

> function MsgCreate(AOwner: TComponent): boolean;
> begin
>   try
>     try
>       bInitialized := False;
>       tblMsg.Create(AOwner);
>       tblMsg.DatabaseName := 'db';
>       tblMsg.TableType := ttParadox;
>       tblMsg.TableName := 'Message.db';
>       tblMsg.Open;
>       bInitialized := True;
>     except
>       on EGPFault do
>          ShowMessage('EGPFault error in QMsg.MsgCreate');
>       on EAbort do
>          ShowMessage('EAbort error in QMsg.MsgCreate');
>       on EBreakpoint do
>          ShowMessage('EBreakpoint error in QMsg.MsgCreate');
>       on EConvertError do
>          ShowMessage('EConvertError error in QMsg.MsgCreate');
>     end;

> Thanks!
> Rod Gicker
> rgic...@worldnet.att.net

Other Threads