|
Technical answers from the trenches |
|
TDataModule Instability Problems
| ||||
Posted: 28 March 2001 |
||||
  |
Applies to Delphi 2 and later |
|||
  |
Audience: Everyone |
|||
Question: I'm creating a data module dynamically. My system becomes unstable at the end of the process. It locks up, hangs, or otherwise gets weird. What's going on and how do I fix it? Answer: See if you're doing something like this: with tDataModule1.create( self ) do
try
doSomething();
finally
release;
end;
If so, your problem stems from the fact that tDataModule doesn't have a release method. This code calls the release method of the form that runs it. The solution is to call your data module's free method instead. For example: with tDataModule1.create( self ) do
try
doSomething();
finally
free;
end;
This illustrates two dangers:
When in doubt, be specific. For example, the following code would have triggered a syntax error in the Delphi IDE: var
dmoData : tDataModule1;
begin
dmoData := tDataModule1.create( self );
try
doSomething();
finally
dmoData.release;
end;
end;
While this might seem like more work, it would have prevented the problem in the first place. Consider it an investment in quality. :-) For information on why you should use release for forms, please see the online Help. Keep in mind, however, that you free objects and release forms. |
|||
|
||||||||
|
Copyright © 2000-2004, techtricks.com; All Rights Reserved. Acknowledgements, Disclaimers, Terms and Conditions. |
||||||||
|
Article last updated on 31 May 2003
|
||
|
|
||
|
[- End -]
|