You are not logged in.
Pages: 1
Hi, ab
Help me please
How correctly to convert IInterface type to store in ORM database?
unit Unit1;
interface
type
ISomeInterface = interface
['{0A799B7B-3BBB-4159-B59F-BD3B03AA654F}']
function GetProvider: RawUTF8;
end;
TSQLProviders = class(TSQLRecord)
private
FIntf: ISomeInterface; {What type of interface variable?}
published
property Intf: ISomeInterface read FIntf write FIntf;
end;
TSomeObject = class
protected
FIntf: ISomeInterface;
FRest: TSQLRest;
public
constructor Create;
end;
implementation
constructor TSomeObject.Create;
var
Rec: TSQLProviders;
Provider: RawUTF8;
begin
FRest := TSQLRestServerFullMemory.CreateWithOwnModel([TSQLProviders]);
FRest.CreateMissingTables;
TSQLProviders.AutoFree(Rec);
Intf := TSomeProvider.Create;
Rec.Intf := Intf; {how to convert interface variable to store in database?}
FRest.Add(Rec,'',True);
Provider := Rec.Intf.GetProvider; {how to call the interface method from database?}
end;
end.
Offline
Did the IInterface type variable is not a pointer?
Offline
Thanks
That's how it works
...
TSQLProviders = class(TSQLRecord)
private
FIntf: UIntPtr; {What type of interface variable?}
published
property Intf: UIntPtr read FIntf write FIntf;
end;
....
Intf := TSomeProvider.Create;
Rec.Intf := UIntPtr(Intf); {how to convert interface variable to store in database?}
FRest.Add(Rec,True);
....
Provider := ISomeInterface(Rec.Intf).GetProvider; {how to call the interface method from database?}
Offline
You can't persist an interface pointer.
It is depending on the execution context.
If you restart the application for instance, the pointer value will be incorrect for sure.
So I don't see the point of saving a pointer into a database.
We can save classes, because we don't save their pointer, but their attributes/fields values.
What you could do is save an integer ID which may be able to create an interface instance from the database.
But this is something else.
Offline
Thanks, ab
You can't persist an interface pointer.
It is depending on the execution context.
This is just what I need.
I need to save an interface pointer within the execution context into the FullInMemory database
Offline
Thanks, ab.
I understood it.
I have to use InterfaceArrayAdd and InterfaceArrayDelete each time I add or delete the interface into the database
Offline
Pages: 1