> Dear all
> Hi
[quoted text clipped - 46 lines]
> At the moment, I have to define a DBBroker object for each form and
> database operation and obviously, it is base practice.
How about using the singleton pattern?
(http://en.wikipedia.org/wiki/Singleton_pattern). With help of templates you can
transform a class into a singleton without touching their code (see
Alexandrescu's aproach in the loki library http://www.ddj.com/cpp/184401943)
> 2. As you know, If I have the following native C++ class:
> class C {
[quoted text clipped - 14 lines]
> SingleInvestorRegForm^ FillSexComboBox();
> };
> FillNationalityComboBox()->FillSexComboBox(); // or something like
> that
Yes, the sentence is correct.
--
Cholo Lennon
Bs.As.
ARG
Saeed Amrollahi - 16 Apr 2008 08:28 GMT
> > Dear all
> > Hi
[quoted text clipped - 84 lines]
>
> - Show quoted text -
Hi Cholo
Thank you. Your answer for second question was good. For the first
question:
my problem isn't single instance creation, Indeed I want to declare/
define a global ref object,
then using extern, I want to reuse such object in other translation
units:
// 1.h
public ref class DBBroker {
// ...
};
// main.cpp
// global definition
DBBroker^ DB = new DBBroker();
// 2.cpp
extern DBBroker^ DB;
// now use global DB
Thanks
- Saeed
SvenC - 16 Apr 2008 09:15 GMT
Hi Saeed,
> Thank you. Your answer for second question was good. For the first
> question:
[quoted text clipped - 14 lines]
> // 2.cpp
> extern DBBroker^ DB;
Define a static public ref class with a static public method which
returns your singleton.
--
SvenC
adebaene@club-internet.fr - 16 Apr 2008 09:27 GMT
> my problem isn't single instance creation, Indeed I want to declare/
> define a global ref object,
> then using extern, I want to reuse such object in other translation
> units:
You can't declare global variable in .NET. The singleton is the right
solution (you should also use it in native C++, it is anyway a better
pattern, that a global "extern" object).
You could also make the DBBRoker class static : if you declare only
one instance of this class, there is no real reason to have it
instanciable...
Arnaud
Ben Voigt [C++ MVP] - 16 Apr 2008 16:53 GMT
> my problem isn't single instance creation, Indeed I want to declare/
> define a global ref object,
[quoted text clipped - 13 lines]
> extern DBBroker^ DB;
> // now use global DB
This is correct, except ref class instances live on the managed heap, so use
gcnew instead of new.
> Thanks
> - Saeed