VCL in DLL global scope


2003-11-15 12:12:01 AM
cppbuilder112
Hi there,
Just wanted to ask which is the best way to dynamically create a VCL
component in order to ensure that all methods
see the same instance of the VCL.
For example, assume that I wish to add a TTimer component in my DLL server.
What I usually do, which is not very nice but
seems to work so far, is to write in the *impl.cpp file
TTimer *timer1=new TTimer(NULL);
as a global statement (not inside a member function). This seems to work
fine for a RS232 component.
However, this does not work very well for database components (Interbase
specifically). When a new TIBTable for example is created, some of its
properties such as table name, transaction name, etc. must be defined.
Although these are defined once in a member function, when the same
component (e.g. table1) is called withing another function is like a new
instance and knows nothing of the assigned properties requiring that these
should be passed again.
The obvious workaround is to add the above instantiation statement in every
method call and assign all database, transaction and table properties each
time which of course isn't practical.
Half the problem is solved by declaring the component in the *impl.h file as
TTimer *timer1;
How should the component be instantiated in the *impl.cpp file in order to
ensure global visibility by all member functions and avoid memory leaks?
Finally, are there any particular thread settings that should be used when
using a timer component given that as I understand creates a thread of its
own?
thank you
Manos