If you add a class, think of it like a window you cannot see.
You can add properties of the usual kinds
You can create a constructor method that initialises them
You can add methods to add on the data, or return their values.
But we have no idea what you mean by âget out of itâ
Well, I wonât get into the power of subclassing, since youâve said this isnât about subclassing.
I too am confused by âhow did you get out of it?â I will take a stab, though. If what you mean is âhow does one get rid of it when done?â, itâs simple. When you create an instance of the class in a method, it will be removed from memory when it goes out of scope.
I typed my french text @ translate google and copy / paste the translation.
OK, I will rephrase it:
I searched in the LR / Documentation explanations on how to do a Class (Insert Menu -â> Class). I mean a step by step example that do something.
I searched on the internet, but there, they are talking to people who knows about Class.
I wasted hours yesterday to achieve a goal, using many different design until I realize it does not works, change the design, and so on⊠until at night, I found a simple solution (old school).
BTW: I fully understand the advantages of Class, what is unclear is how to build one that do somethingâŠ
Here is a simple one: the âSavings Jarâ class.
It represents an empty jar where you save coins.
Insert a Class
Name it âSavingsâ
Give it a private property âValueâ as double
Give it a public method âSaveâ which takes a double parameter
Give it a public method âSpendâ which take a double parameter, and returns a double
Maybe one called âEmptyâ which returns a double
And one called TotalSaved which returns a double.
You should not be able to access the Value directly, which is why it is private
The Save method âŠ
Save(v as double)
if v >0 then Value = Value + v //cannot 'save' a negative
The Spend method
Spend(v as double) as double
dim ret as double
if v<= value then //cant spend more than you have
ret = v
Value = value - v
else
ret= value
value = 0
end if
return ret //confirm how much was removed
The Empty method
Empty() as double
dim ret as double
ret= value
value = 0
return ret //confirm how much was removed
The TotalSaved method
TotalSaved() as double
dim ret as double
ret= value
value = 0
return ret //confirm how much was removed
Now, you can have several jars âŠ
dim myJar as new Savings
dim yourJar as new Savings
call myJar.save(25.3)
call YourJar.save(10)
dim GetSomeMoney as double
GetSomeMoney = MyJar.spend(30)
// we dont own 30, so GetSomeMoney will be 25.3
I have used the same technique to create a class to replace an onscreen canvas
At one time I had a canvas on top of another canvas.
They both painted, but the result was horrible.
So I created a class which had the size properties of a canvas, but no actual graphics backing.
It still had a paint method, taking g as graphics
In the main canvasâ paint event, I drew the main canvas, then performed the drawing that the other canvas would have done, but at the location of the pseudo canvas, by calling the paint method and passing along âgâ
If youâre making an âabstract objectâ kind of class rather than a subclass, just leave the âSuperâ field blank in the Inspector for your new class. Then add methods, properties, etc to the class in the IDE as you would normally. Here is my class âItemâ: