Page 1 of 1

How to inherit from 7.12's rpreview class?

Posted: Wed Jan 02, 2008 2:49 am
by hua
I have a customized version of rpreview, which has a few additional buttons.

Seeing that rpreview in 7.12 is now a class, I attempt to inherit from it and place my changes in this new class. So I create a new class TPreview2, copy over method ::BuildButtonBar() and started to add in the additional buttons.

What stump me during this attempt is l2007 is declared as a static var in TPreview not as a class data. What's the correct way for me to proceed? Simply create a static l2007 var in TPreview2 or modify TPreview and change the var to a class data?

What's actually the rule of thumb when inheriting classes that make use of static vars? TPrinter is another class that comes to mind.

TIA

Posted: Wed Jan 02, 2008 12:19 pm
by Antonio Linares
Hua,

> What's the correct way for me to proceed?

Yes, you can declare it as a CLASSDATA and modify the source code to access ::l2007

There is nothing wrong in using static vars. The problem comes when a class is inherited, as in your case. Then, you are right, a CLASSDATA is the way to go

Posted: Wed Jan 02, 2008 12:41 pm
by StefanHaupt
Antonio,

what is the difference between CLASSDATA and DATA ?
When I have to use CLASSDATA ?

Posted: Wed Jan 02, 2008 1:00 pm
by Antonio Linares
Stefan,

A DATA belongs to an object. A CLASSDATA belongs to a Class.

For example:Imagine that you want to create a class TCar, and you want to know how many cars have been produced. Then you need a CLASSDATA nCars that will be a "shared" value from all Cars objects.

So everytime that a car is created, you do oCar:nCars++ and nCars is the same CLASSDATA shared from all Cars objects.

There are multiple cars, and just one nCars value.

Posted: Thu Jan 03, 2008 5:36 am
by hua
Thanks for the reply Antonio

Posted: Thu Jan 03, 2008 12:54 pm
by StefanHaupt
Antonio,

Ok, I see.

Many thanks for the explanation