Initialization of class variables

forum.advanced.programming (1998-2005)
Tobias Krüeger

Initialization of class variables

Post by Tobias Krüeger » 04 Jan 2005, 17:37

 Posted by:  Tobias Krüeger 

Hi every body!
Is there a way to initialize Class Variables easily?
I would like to (ab)use Class variables as constants for a class without
polluting the global namespace.

E.g.
Class Variable:
Number: MONDAY = 0
Number: TUESDAY = 1
and so on

The only workaround is allocate an object and call an Init function,
which must be done from SAM_AppStartup.

Thomas Althammer posted several years ago that he has something in his
FAQ. Unfortunately it is no longer online.

Thanks for any ideas
Tobias

g.achrainer

Initialization of class variables

Post by g.achrainer » 04 Jan 2005, 23:20

 Posted by:  g.achrainer 

Hi,

there is nothing like a Constructor in TD, but if you are trying to create
"groups" of numeric constants, you may take a look at Enumerations (same
section as constants).

The mentioned FAQ are still for download at www.iceteagroup.com. I looked
for your Question and found the following:

How do I initialise class variables?
For setting values for class variables, you don't need an existing instance
of the class. So, you can just use the following code to initialise the
default color of screen element:
On SAM_AppStartup
Set cfScreenElement.c_mDefaultColor=COLOR_Grey

Hope this helps...

Regards,

gerhard.

Krister Henningsson

Initialization of class variables

Post by Krister Henningsson » 05 Jan 2005, 08:48

 Posted by:  Krister Henningsson 

Gerhard beat me to it ;-)

!!CB!! 525
Enum: Weekdays
Attributes
GUID: {E08E5E2C-CFE8-4654-A425-0F2CAFBCA2EA}
Help String:
Help Context: 0
Item: Sunday = 1
Item: Monday = 2
Item: Tuesday = 3
Item: Wednesday = 4
Item: Thursday = 5
Item: Freiday = 6
Item: Saturday = 7
--
--
Regards, Kriss

soon Former Gupta Developer :-/
FAQ-stuff
------------------------------------------------
OS: WindowsXP
GUPTA: TD3.1 PTF1(R)
Client 9i (9.2)
Db: Oracle 8.1.7
------------------------------------------------
"Sitting target
Sitting waiting
Anticipating
Nothing
Nothing

Life
Is full of surprises
It advertises
Nothing
Nothing

What am I trying to do
What am I trying to say
I'm not trying to tell you anything
You didn't know
When you woke up today

Sitting target
Sitting praying
God is saying
Nothing
Nothing

Always
Knows the prospects
Learnt to expect
Nothing
Nothing"
--Depeche Mode

Tobias Krüeger

Initialization of class variables

Post by Tobias Krüeger » 05 Jan 2005, 10:51

 Posted by:  Tobias Krüeger 

Hello Gerhard, hello Kriss,

thanks for your suggestions.

The enum is an alternative which had not considered.

But both ways are workarounds which do not solve my problem completely:

I think the enumerations is the most elegant solution but it does not
belong to the class itself. It resides in the global namespace.

The initialisation on AppStartup requires that something must be
executed before the class can be used.
If I write a class I would like to use it in my applications without the
need of initialisation. A class must care about those things itself.

Perhabs I am just dreaming again about more OO features in Gupta.

I think I will stick to the enumeration.

Tobias
(still open for new ideas)

Jürg Niederberger

Initialization of class variables

Post by Jürg Niederberger » 05 Jan 2005, 17:36

 Posted by:  Jürg Niederberger 

Hi
Maybe

Instance Variable
Boolean: bInitialized
and every function/message handler starts with
If not bInitialized
Call Initialize()

Initialize has to set bInitialized of course.

Jürg

Return to “advanced.programming”

Who is online

Users browsing this forum: [Ccbot] and 0 guests