Basic class with "private" variables.
Posted on 2006-06-28
I've created a class for use in an application and I'm having problems understanding the point of the word "private", as it seems to make no difference.
For example, here's a small class that shows my problem...
TTestClass = class
_Name : String;
procedure SetName(Value: String);
property Name : String read _Name write SetName;
procedure TTestClass.SetName(Value: String);
_Name := Value;
if I create an instance of that class, then I would not expect to be able to do the following...
oTestClass := TTestClass.Create;
oTestClass._Name := 'Bob';
...but I can.
Can someone PLEASE tell me what the point of the "private" keyword is, AND how do I make a truly private variable that is for internal use within the class only?
Thanks in advance,
PS. It's lots of points cos I need a quick answer.