How to make this OO?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-04-09T15:19:45Z
Indexed on
2010/04/09
15:23 UTC
Read the original article
Hit count: 358
Hello,
Sorry for the poor title,I'm new to OOP so I don't know what is the term for what I need to do.
I have, say, 10 different Objects that inherit one Object.They have different amount and type of class members,but all of them have one property in common - Visible.
type
TObj1=class(TObject)
private
a:integer;
...(More members)
Visible:Boolean;
end;
TObj2=class(TObject)
private
b:String;
...(More members)
Visible:Boolean;
end;
...(Other 8 objects)
For each of them I have a variable.
var Obj1:TObj1;
Obj2:TObj2;
Obj3:TObj3;
....(Other 7 objects)
Rule 1: Only one object can be initialized at a time(others have to be freed) to be visible.
For this rule I have a global variable
var CurrentVisibleObj:TObject; //Because they all inherit TObject
Finally there is a procedure that changes visibility.
procedure ChangeObjVisibility(newObj:TObject);
begin
CurrentVisibleObj.Free; //Free the old object
CurrentVisibleObj:=newObj; //assign the new object
CurrentVisibleObj:= ??? //Create new object
CurrentVisibleObj.Visible:=true; //Set visibility to new object
end;
There is my problem,I don't know how to initialize it,because the derived class is unknown.
How do I do this?
I simplified the explanation,in the project there are TFrames each having different controls and I have to set visible/not visible the same way(By leaving only one frame initialized).
Sorry again for the title,I'm very new to OOP.
© Stack Overflow or respective owner