cronodragon
01-08-2007, 03:25 PM
I have something like this:
type
myClass = class(TObject)
...
procedure DoSomething(var Obj:TObject);
begin
...
end;
var
myObj: myClass;
Now I want to call the procedure like this:
DoSomething(myObj);
But I get a type error. I don't see why since myClass is a decendant of TObject. So I have to explicitly typecast the parameter inelegantly:
DoSomething(TObject(myObj));
I think the compiler is trying to save me from using a parameter which is not of the right type, but by doing that it is forcing me to use a solution which is unsafe, since I could typecast a variable which is not a class by mistake. Of course I could use the "as" operator, but I think it's too slow. Is there a way to tell the compiler not to be so strict with classes?
Regards! :D
type
myClass = class(TObject)
...
procedure DoSomething(var Obj:TObject);
begin
...
end;
var
myObj: myClass;
Now I want to call the procedure like this:
DoSomething(myObj);
But I get a type error. I don't see why since myClass is a decendant of TObject. So I have to explicitly typecast the parameter inelegantly:
DoSomething(TObject(myObj));
I think the compiler is trying to save me from using a parameter which is not of the right type, but by doing that it is forcing me to use a solution which is unsafe, since I could typecast a variable which is not a class by mistake. Of course I could use the "as" operator, but I think it's too slow. Is there a way to tell the compiler not to be so strict with classes?
Regards! :D