Board index » delphi » Problem with Form Inheritance and DB Aware Components...

Problem with Form Inheritance and DB Aware Components...

Hi,

Not sure if this is the correct form - but here goes.

I have an interesting Problem in regards to Form Inheritance...  I was
wondering if any of you might know the answer to the following situation...

I have a DataAware Maintenance Form that I use (built up from a application
framework of inherited forms).  However, I have an interesting situation in
regards to DataSource - DataSet relations in the inherited forms.

The base form that I am using has a DBGrid and a DbNavigator on it - with
the Data Source property left blank.  It also has a panel on the right hand
side for putting DB Fields on in the decendant form.

So - I inherit from the Ancestor and create a new decendant.  On this new
form I add the DB Fields to the panel - and connect the DBGrid, DB Navigator
and DB Fields to the DataSource on an associated DataModule.  I create the
DataModule at Run Time - in the decendant forms CreateForm method.  So
really I create both decendant form and associated datamodule at design
time - then change project options so that neither is created automatically
in the project source.  When I create the form - it automatically creates
the Datamodule!  (Sets the datamodule name to blank - so that I reference a
new copy of the data with each instance of the form)

The problem is when I close the project and reopen it.  I get the DBEngine
error "Unknown Database: Alias xxx".   I click OK - and then the project
finishes opening - but the DataSource property of the DBNavigator and DBGrid
are set to blank!!!  However, all the DB Fields still have their DataSource
property set correctly.  Only the objects that were in the ancestor form
have it set to blank.  I have even tried moving the Datasource to the form.
If I put it on the decendant - everything works fine.  If I put it on the
Ancestor then it leaves the Datasource property set correctly on all the
other DB aware fields/grids/etc - but then the DataSet property on the
Datasource gets set to blank.

All in all - I realize there must be either a logical explaination for
this - or it is a bug.  The problem is I don't know which.  Any thoughts on
this??  I am hoping to stay away from setting this stuff in code - but I may
have to move to that as a last result.

Any thoughts on this would be appreciated.

Bradley

 

Re:Problem with Form Inheritance and DB Aware Components...


Hi Bradley --

Try putting the code that creates the datamodule before the "inherited
Create(AOwner);" statement of your form's constructor.

Just curious tho...but why waste the resources to create a new datamodule
for each instance of the form?  Why not just put the datasource on the form
itself?  That way you can connect everything in the ancestor form and put
the specifics in the descendant form...

--jd

Re:Problem with Form Inheritance and DB Aware Components...


Hello,

The code to call the create of the datamodule is in the ancestor.  It
references a abstract method from it's FormCreate method that is implemented
in the decendant form.  However, the problem I am encountering is at Design
time - not run time - so I am not sure your idea will work - but I will try
just about anything at this point....

In terms of wasting resources - I have a requirement where each instance of
the form needs to have it's own view of the data.  So - I need a new
instance of the data module each time.  I have tried puting the DataSource
on the Form - but then the DataSet property of the Datasource gets blanked
every time I open the form.  All in all very frustrating!!!

I appreciate your comments.

Bradley

Re:Problem with Form Inheritance and DB Aware Components...


It just gets more and more bizarre....

I tried you idea of move the creation of the datasource before the
inherited - and it did not work.  Thanks for the suggestion though...

I also noticed that when I reopen the project.... the error message about
unknown alias only appears if the DataBase is connected.  If it is not
connected then I don't get the message.  Also - the datasouce property is
not cleared when I bring up the form at design time.  However, when I run
the form - it does have the DBGrid connected - so I close the form - and low
and behold - the datasource property is cleared.....

The more I deal with this - the more I wonder if it is not a suttle bug in
the form inheritance part of Delphi.    Or it could just be me screwing up
again <g>

Bradley

Re:Problem with Form Inheritance and DB Aware Components...


Quote
G. Bradley MacDonald wrote in message <7ajtcg$fi...@forums.borland.com>...

>The base form that I am using has a DBGrid and a DbNavigator on it - with
>the Data Source property left blank.  It also has a panel on the right hand
>side for putting DB Fields on in the decendant form.

Sounds virtually identical to my current project, a common maintenance-type
form (itself inherited from a more basic form) that contains a datasource
with a dbgrid linked to it, but the dataset property left blank. Descendant
forms tie their db controls to the datasource, get access to a business
object and link the datasource to an appropriate dataset. All created only
at runtime. However, I haven't encountered the problem of any properties
being blanked out or "alias" problems as you describe - and I have 3 other
guys all creating descendant forms for this project!).

This is definitely weird and so I can only suggest a stab in the dark. With
Delphi closed, in the project directory, delete any unnecessary files -
.dof, .dsm, .dsk, then reopen the project and see if the problems still
persist (you'll have to reset your blanked properties once still).

--
Wayne Niddery - WinWright Consulting
Delphi, C++Builder, JBuilder, InterDev --
http://home.ican.net/~wniddery/RADBooks.html
...remove chaff when replying...
"You know you've landed gear-up when it takes full power to taxi"

Re:Problem with Form Inheritance and DB Aware Components...


As a clarification to the post I just made, what I mean by 'I delete all the
tables I was using,' I meant I deleted the table _files_, and the directory,
and the alias.

Semper Fi,

Chris

G. Bradley MacDonald <Bradley_MacDon...@bc.sympatico.ca> wrote in message
news:7ajtcg$fiq15@forums.borland.com...

Quote
>Hi,

>Not sure if this is the correct form - but here goes.

>I have an interesting Problem in regards to Form Inheritance...  I was
>wondering if any of you might know the answer to the following situation...

>I have a DataAware Maintenance Form that I use (built up from a application
>framework of inherited forms).  However, I have an interesting situation in
>regards to DataSource - DataSet relations in the inherited forms.

>The base form that I am using has a DBGrid and a DbNavigator on it - with
>the Data Source property left blank.  It also has a panel on the right hand
>side for putting DB Fields on in the decendant form.

>So - I inherit from the Ancestor and create a new decendant.  On this new
>form I add the DB Fields to the panel - and connect the DBGrid, DB
Navigator
>and DB Fields to the DataSource on an associated DataModule.  I create the
>DataModule at Run Time - in the decendant forms CreateForm method.  So
>really I create both decendant form and associated datamodule at design
>time - then change project options so that neither is created automatically
>in the project source.  When I create the form - it automatically creates
>the Datamodule!  (Sets the datamodule name to blank - so that I reference a
>new copy of the data with each instance of the form)

>The problem is when I close the project and reopen it.  I get the DBEngine
>error "Unknown Database: Alias xxx".   I click OK - and then the project
>finishes opening - but the DataSource property of the DBNavigator and
DBGrid
>are set to blank!!!  However, all the DB Fields still have their DataSource
>property set correctly.  Only the objects that were in the ancestor form
>have it set to blank.  I have even tried moving the Datasource to the form.
>If I put it on the decendant - everything works fine.  If I put it on the
>Ancestor then it leaves the Datasource property set correctly on all the
>other DB aware fields/grids/etc - but then the DataSet property on the
>Datasource gets set to blank.

>All in all - I realize there must be either a logical explaination for
>this - or it is a bug.  The problem is I don't know which.  Any thoughts on
>this??  I am hoping to stay away from setting this stuff in code - but I
may
>have to move to that as a last result.

>Any thoughts on this would be appreciated.

>Bradley

Re:Problem with Form Inheritance and DB Aware Components...


I was having problems like this.  I deleted everything I could think of and
recreated them, even the project files and forms, one by one, to no avail.
Finally, a stab in the dark, I deleted the tables I was using and recreated
_them_.  Viola, all _my problems went away, don't have any idea how, though!

Semper Fidelis,

Chris

G. Bradley MacDonald <Bradley_MacDon...@bc.sympatico.ca> wrote in message
news:7ajtcg$fiq15@forums.borland.com...

Quote
>Hi,

>Not sure if this is the correct form - but here goes.

>I have an interesting Problem in regards to Form Inheritance...  I was
>wondering if any of you might know the answer to the following situation...

>I have a DataAware Maintenance Form that I use (built up from a application
>framework of inherited forms).  However, I have an interesting situation in
>regards to DataSource - DataSet relations in the inherited forms.

>The base form that I am using has a DBGrid and a DbNavigator on it - with
>the Data Source property left blank.  It also has a panel on the right hand
>side for putting DB Fields on in the decendant form.

>So - I inherit from the Ancestor and create a new decendant.  On this new
>form I add the DB Fields to the panel - and connect the DBGrid, DB
Navigator
>and DB Fields to the DataSource on an associated DataModule.  I create the
>DataModule at Run Time - in the decendant forms CreateForm method.  So
>really I create both decendant form and associated datamodule at design
>time - then change project options so that neither is created automatically
>in the project source.  When I create the form - it automatically creates
>the Datamodule!  (Sets the datamodule name to blank - so that I reference a
>new copy of the data with each instance of the form)

>The problem is when I close the project and reopen it.  I get the DBEngine
>error "Unknown Database: Alias xxx".   I click OK - and then the project
>finishes opening - but the DataSource property of the DBNavigator and
DBGrid
>are set to blank!!!  However, all the DB Fields still have their DataSource
>property set correctly.  Only the objects that were in the ancestor form
>have it set to blank.  I have even tried moving the Datasource to the form.
>If I put it on the decendant - everything works fine.  If I put it on the
>Ancestor then it leaves the Datasource property set correctly on all the
>other DB aware fields/grids/etc - but then the DataSet property on the
>Datasource gets set to blank.

>All in all - I realize there must be either a logical explaination for
>this - or it is a bug.  The problem is I don't know which.  Any thoughts on
>this??  I am hoping to stay away from setting this stuff in code - but I
may
>have to move to that as a last result.

>Any thoughts on this would be appreciated.

>Bradley

Re:Problem with Form Inheritance and DB Aware Components...


Quote
> The problem is when I close the project and reopen it.  I get the DBEngine
> error "Unknown Database: Alias xxx".   I click OK - and then the project
> finishes opening - but the DataSource property of the DBNavigator and DBGrid
> are set to blank!!!  However, all the DB Fields still have their DataSource

  We had a similar problem in Delphi 3/4.  To fix it, we placed our
TDatabase in a maintenance unit and created it in the initialization
section (it isn't on a form).  Then the database object was always loaded
and ready before any forms were created at design time.

Good luck,
Erik

Re:Problem with Form Inheritance and DB Aware Components...


Update

I am still having the problem (after D4 Update 3).  Some additional
information...

1.  When I reopen the Project - the datasource's dataset property looks as
if it is still set - but if I run the program - the grid (based on the
datasource) is blank - and when I return to the IDE - the dataset property
is now blank
2.  As above in 1 - when I reopen the project - the dataset property is
still appears to be set - but if I view the form as text - then switch
back - the property is now blank.

The project is made up as follows...

1.  Data Modules
    a)  Main TDataModule - contains the TDatabase Component
            - created auto by the project source
    b)  Customer TDataModule - contains TQuery, TUpdateSQL
            - created at run time by the FormCreate method of the Customer
Form

2.  Forms
    a)  Main form - Created auto by the project source
            - This form is not data aware - and serves only as a type of
tool bar for the entire application.
    b)  Customer Form - created at run time via a Create statement.
            - Creates the Datamodule Customer.  It is the DataSet property
of the Datasource on this form that I am having trouble with during the
reopening of a project.......

Any thoughts??

Bradley MacDonald

Other Threads