Hi List,
I cannot assign elements from a list to an interface type reference.
Given the following (simplified) class and interface definitions:
IBlah = Interface
procedure hello;
end;
TTestObject = class(TInterfacedObject, IBlah)
procedure hello;
end;
TSubObject = class(TTestObject)
procedure boeh;
end;
Assigning a variable of tyep TsubObject to an IBlah reference type works
perfectly:
var
iBlahRef: IBlah;
subObjRef: TSubObject;
begin
subObjRef:=TSubObject.create;
iBlahRef:=IBlah(testref3); //works fine
end;
When I first put the refs in a list, and then try to get them from the list, it
does not work
anymore:
var
iBlahRef: IBlah;
subObjRef: TSubObject;
begin
l:=TList.create;
l.add(TSubObject.create);
iBlahRef:=IBlah(l[0]); //does not work, null pointer exception
while, from the same list, this works:
testObjectRef:=TTestObject(l[0]); //works fine
As both TTestObject variables and IBlah variables should be assignable to the
elements
of the list, both should work, isn't it?
Then why can't I assign the elements from the list to an IBlah, where I can
assign them
to an TTestObject? Am I missing something, or is there some very silly error I
am
overlooking?
Is there any way in which I can assign list elements to interface typed
variables??
thanks, Rinke
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi