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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ensuring closed queries/tables on create and destroy of datamodules.

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I want to be able to run a procedure both on the 'OnCreate' and 'OnDestroy' event of my various datamodules in my applications. At the moment on destroy of the application I have a procedure which checks the state of a dataset - if it is one of the edit modes then a 'Cancel' is performed - then the table/query has Active set to False to ensure that no data connections are open when we destroy the datamodule. This procedure has to be called for each of the table/query components in the datamodule in a list maintained by the developer. Is there a procedure that anyone uses that can be run to step through the query components (or table components) closing them - without me having to run a procedure for each and every data component listed by myself.
I sometimes have data components (query or tables) open in the design environment but want these to be closed when the application is started by the user - so need to run a similar procedure 'OnCreate' of the datamodule - such that all tables/querys are stepped through and have Active set to False to ensure no data is being accessed at start up.
Can anyone provide me with a solution or any pointers to get me started ??
Thanks in advance.
Steve
 
You will have to use some RTTI here

for I := 0 to DataModule1.ComponentCount - 1 do
begin
if (DataModule1.Components is TTable) or (DataModule1.Components is TQuery) then
//TData
//do what you want
//you will have to check the Active state of the component
//to increase the speed of the app if you have many
//components
end;
Welcome to the Pythian Games!
Long live Godess Athena!
dArktEmplAr of Delphi Oracle
 
Thanks dArktEmplAr - I'll put this to use at the weekend.
Steve
 
Steven, you can use an explicit TDatabase and point all your dataset Database property to there. Once you turn the TDatabase.Active to False in the Object Inspector and build your proj, you can be absolutely sure that no data access in yhour OnCreate event.
 
Antony7777 - thanks for the advice but that was the cause of my problem. I was sometimes leaving the TDatabase component Active at design-time (sometimes through listing fields against a TQuery component).
Thanks anyway.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top