私は Spring4D フレームワークに非常に慣れていないので、助けを求めます。
私は次のクラスとインターフェースを持っています:
ICommand = interface
TCommand = class(TInterfacedObject, ICommand)
IVecadCommand = interface(ICommand)
TVecadCommand = class(TCommand, IVecadCommand)
TVecadCommandJPG = class(TVecadCommand, IVecadCommand)
TCommandDeckelJPG = class(TVecadCommandJPG, IVecadCommand)
次に、コンポーネントを登録します。
GlobalContainer.RegisterComponent<TCommandDeckelJPG>.Implements<IVecadCommand>('deckel_jpg');
次に、ServiceLocator を使用してオブジェクトを作成しようとします。
var
i: Integer;
com: ICommand;
begin
Result := nil;
com := ServiceLocator.GetService<ICommand>(actionName);
com.setSession(designSession);
Result := com;
end;
実行の結果、例外があります。
Invalid class typecast
例外を回避するために、次のようにします。
var
i: Integer;
com: IVecadCommand;
begin
Result := nil;
com := ServiceLocator.GetService<IVecadCommand>(actionName);
com.setSession(designSession);
Result := com;
end;
その後、すべてがOKです。
ポイントは、この場合、TCommand および継承されたクラスのリポジトリとして TContainer を使用する必要があることです。したがって、最初に ServiceLocator を使用する必要があります。
例外を回避し、TContainer で IVecadCommand ではなく ICommand を使用するにはどうすればよいですか?
ありがとう。喜んで追加の詳細を提供します。