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

bpl unit initialization section

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi all,

I have a bpl in which I share an instance of a class (or unit) that implements section initialization and finalization.

In the initialization section, the class (inherited from TApplication) creates itself.

Here's a skeleton of my class:
-----------------------------------------------------------
type
TclsAppIntf = class(TApplication)
// private and public declarations...
end;
var oApp: TclsAppIntf;

implementation
//code of the class...
initialization
oApp := TclsAppIntf.Create(Application);
finalization
// No need to free the object descending from TApplication
//oApp.Free;
-----------------------------------------------------------

If the initialization section is there (that is, calling the constructor of the class), RAD Studio 2007 raises access violation within a IDE modal form (like the AboutBox form) when switching back to the task. Anyway, the point is, RAD Studio doesn't like it (while BDS 2006 does).

So, I need to create an instance of my class within my bpl. In fact, I was using initialization
section as the entry point of my bpl (each vcl uses the same shared class instance)

Is there another entry point in a bpl from where I could instantiate my object?
That is, only one place to call the constructor of TclsAppIntf?

Thanks a lot for help,

RC
 
Could you create entry points in your code? I'm thinking that the unit wouldn't automatically create the object. Instead your code would invoke a function to create the object and return a variable reference to the object. If the object has already been created by another process then you return the variable reference to the existing object.

That being said you're heading into territory above my programming ability... :)

In this way if something goes wrong with the creation of your object then you can trap the exception.

e.g.:

//creates instance as required
MyoApp := TheUnit.GetoAppInstance;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top