Hi,
i try to return an TObjectList with an Service. But i don't wan't the List (and all the Objects in the List) to be freed automatically.
At Programmstart i create a List. I wan't to keep this, but also be able to get the List via a Service
The return to the Client works well!
But then the List and all Objects (and subobjects) within are freed server side
I tryed using the TXDataOperationContext.Current.GetManager to solve this problem, like the documentation said. But still the same problem occurs.
Is there a way to handle this problem? Can i disable the automatic Memory-Managment completly or (better) for a service-call?
Here the simplified sourcecode.
This is the Service-Part
type
[ServiceImplementation]
TTeamService = class(TInterfacedObject, ITeamService)
public
function List: TTeamList;
end;
implementation
function TTeamService.List: TTeamList;
var
Context: TObjectManager;
begin
Context := TXDataOperationContext.Current.GetManager;
Context.OwnsObjects := False;
Result := ServerContainer.Teams;
end;
and this is the ObjectList i want to return
unit clrTeam;
interface
uses
System.Generics.Collections;
type
TLeader = class(TObject)
end;
TTeam = class(TObject)
strict private
FLeader: TLeader;
public
constructor Create; reintroduce;
destructor Destroy; override;
end;
TTeamList = class(TObjectList<TTeam>)
end;
implementation
constructor TTeam.Create;
begin
inherited Create;
FLeader := TLeader.Create;
end;
destructor TTeam.Destroy;
begin
FLeader.Free;
inherited;
end;
end.
Creating the List and add one item
FTeams := TTeamList.Create;
FTeams.Add(TTeam.Create);