You are not logged in.
Pages: 1
Currently on Windows, I can access an instance of an interface like this
TMyInterface(aRestServer.Service<IStaff>).NewSetting := 10;
Since
function Service<T: IInterface>: T;
is only declared for Delphi2010 and up, how would I do this on Linux using fpc?
Would this be the same:?
var tmp: TMyInterface;
...
if aRestServer.Services.Info(TypeInfo(IStaff)).Get(tmp) then
TMyInterface(tmp).NewSetting := 10;
Last edited by squirrel (2019-06-14 13:32:21)
Offline
The "generics" stuff is just another way of putting it. But in fact, it is not the best option.
The best is to register the interface, then write:
initialization
TInterfaceFactory.RegisterInterfaces([ IStaff ]);
end.
var tmp: IStaff;
if aRestServer.Services.Resolve(IStaff,tmp) then
tmp.NewSetting := 10;
Warning: you are making confusion between interfaces (IStaff) and classes (TMyInterface). So your code won't work.
Offline
Pages: 1