Can I write this? Or how to do it?
Can I write this? Or how to do it?
I have a database reader which uses generics and declared like this: IDatabaseReader
Now, based on a parameter I can call the reader for different.
var
readerCustomer: IDatabaseReader;
readerAddress: IDatabaseReader;
begin
readerCustomer:=TDatabaseReader.Create;
readerAddress:=TDatabaseReader.Create;
end;
Instead of declaring the readers I tried to do something along these lines:
var
reader: IDatabaseReader;
readObject: TObject;
begin
if param=Customers then
readObject:=@TCustomers; <---????
reader:=TDatabaseReader<@readObject>.Create; <---????
end;
Would something like this be possible? Or, perhaps, with RTTI?
Thanks
I have a database reader which uses generics and declared like this: IDatabaseReader
Now, based on a parameter I can call the reader for different
var
readerCustomer: IDatabaseReader
readerAddress: IDatabaseReader
begin
readerCustomer:=TDatabaseReader
readerAddress:=TDatabaseReader
end;
Instead of declaring the readers I tried to do something along these lines:
var
reader: IDatabaseReader
readObject: TObject;
begin
if param=Customers then
readObject:=@TCustomers; <---????
reader:=TDatabaseReader<@readObject>.Create; <---????
end;
Would something like this be possible? Or, perhaps, with RTTI?
Thanks
Uwe Raabe That's what I have now.
ReplyDeleteGeneric class is mapped to real class in compile time, not in runtime. You can use Spring and DI container to resolve required object in runtime.
ReplyDeleteJacek Laskowski Indeed they are mapped in compile time. I just thought to ask in case something like that is possible. I don't see how DI containers will solve my case which is to avoid typing in all the variables depending on the type of . Same thing...
ReplyDelete