Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid losing DataSource

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I have seen this problem a number of times but never determined the 'why' behind it - and ideally would like to prevent it happening again.
I make use of forms and datamodules, whereby a form will have a standard TDBGrid pointed to a TDataSource on an associated DataModule. On occasions if I open the form, then the datamodule, then close the DataModule (insider the IDE) the TDBGrid suddenly (sometimes) loses the DataSource property. Even if I then close all the files - the form and datamodule timestamps remain undchanged but the grid has now lost it's link.
Why would this happen ?
How can I prevent from tripping over this in the future ?
Usually I have the habit of opening the appropriate DataModule before opening the form - but sometimes I forget.
This isn't an issue I see every time I open the form / datamodule out of sequence but have seen it on occasion.
Anyone got any suggestions ?
Thanks in advance
Steve
 
I've had this problem. I assign the Datasource in the OnCreate method or Constructor of the form, at runtime.

lou
 
Hi Steve !
I've had this problem too sometimes. Last week again. I am not sure but I think the reason is a change in the installed packages or components :
The week before last week the datamodule was edited by one of my collegues. That guy had installed a new package or component that I did not have. He saved a new version of the datamodule (WITH all the correct datasource assignments) on our network drive. When I opened the datamodule last week the datasource assignments were gone.
So, I closed my Delphi project and we restored the original datamodule file from a backup copy. Then I installed the same new package that my collegue used when he saved the datamodule file. After this I could open the datamodule without any problem.
We did not try to proof that the change in the packages caused the problem, but we will go on watching Delphi's behavior when we install the next new component or package.
Bye,
Thomas
 
One workaround would be to put the datasource on the form, not in the data module. (It could still point to a table in the data module.) Of course, this would defeat half the point of having the data module in the first place.
-- Doug Burbidge mailto:doug@ultrazone.com
 
It looks like that when the datasource is on a DataModule, if the datamodule is closed during design time, any alteration on the query or table will break the connection. The way I detect is to put a statusbar with the datasource.state on it. The modes are not connected, edit, browse etc. When I run the program not connected indicates a broken link.
If you are using several queries and datamodules, puting the datasource on the form is not practical, especially when reports are involved. S. van Els
SAvanEls@cq-link.sr
 
Thanks for the pointers with this.
I need to keep the TDataSource components inside the TDataModule as they are global and could be used from a number of places.
When I lost the link from TDBGrid to TDataSource (in the TDataModule I closed) I had not made any change(s) to the components in the TDataModule (I can be certain of this as Delphi did not prompt me to save changes on closing the TDataModule).
Svanels : When you say you use a StatusBar to indicate the DataSource.State in it - how do you mean ? And how are you doing this ?
Thanks again.
Steve
 
My database input forms have the normal data aware controls like grids, navigator etc. + a statusbar or the statusbar of the main form.

I use the dbnavigator to examine the state of the datasource TDataSetState = (dsInactive, dsBrowse, dsEdit, dsInsert, dsSetKey, dsCalcFields, dsFilter, dsNewValue, dsOldValue, dsCurValue, dsBlockRead, dsInternalCalc, dsOpening);

Procedure TMyForm.SetStatusbar
begin
if dbnavigator1.DataSource.State <> nil then
begin
case dbnavigator1.DataSource.State of
dsEdit: StatBar.Panels[1].Text :='Edit';
dsBrowse : StatBar.Panels[1].Text :='Browse';
dsInactive : StatBar.Panels[1].Text :='Inactive';
dsInsert: StatBar.Panels[1].Text :='Insert';
end; { case }
end { if }else
sbStatBar.Panels[1].Text :='Data not Assigned' ;
end;

Declare SetStatusbar in the private section as virtual so you can modify it to fits your need in descendant forms.

Call SetStatusbar in OnFormCreate and OnStateChange of the datasource.

The indication &quot;Data not Assigned&quot; means a broken link,

Regards


S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top