I am very new in Spring4D framework and ask the help.
I have next classes and interfaces:
ICommand = interface
TCommand = class(TInterfacedObject, ICommand)
IVecadCommand = interface(ICommand)
TVecadCommand = class(TCommand, IVecadCommand)
TVecadCommandJPG = class(TVecadCommand, IVecadCommand)
TCommandDeckelJPG = class(TVecadCommandJPG, IVecadCommand)
then I register a component:
GlobalContainer.RegisterComponent<TCommandDeckelJPG>.Implements<IVecadCommand>('deckel_jpg');
then I try to create an object with the help of the ServiceLocator:
var
i: Integer;
com: ICommand;
begin
Result := nil;
com := ServiceLocator.GetService<ICommand>(actionName);
com.setSession(designSession);
Result := com;
end;
As a result of execution I have an exception:
Invalid class typecast
To avoid the exception I make so:
var
i: Integer;
com: IVecadCommand;
begin
Result := nil;
com := ServiceLocator.GetService<IVecadCommand>(actionName);
com.setSession(designSession);
Result := com;
end;
then everything is OK.
Point is I have to use it TContainer in this case as Repository for TCommand and inherited classes. So I must use ServiceLocator first way.
What should I do to avoid an exception and use ICommand but not IVecadCommand in TContainer?
Thanks. Will provide additional details with pleasure.