What is possible use of RetainObject

We are migrating to XE13 and the newest RemObjects/DataAbstract 4 Delphi SDK and notice RetainObject is not available anymore (it is now private)

So we have to modify our code.

In one instance it is used for a return value of a RO function

function TRobotService2.GetLoggedUsers():TUserInfoArray;
begin
Result := BorrowLoggedInUsers();
RetainObject(Result);
end;

I guess this was valid use and ensured that RO did not cleanup the instance in the server process. Is this correct?

We should probably simply clone the (borrowed) object.

The second instance we use it, it is on an item of a RO array.

newuser := fUsers.Add;

RetainObject(newuser);

with fUsers : TUserInfoArray;

&TUserInfoArray = class(TROArray)

The fUsers is the instance that the BorrowLoggedInUsers returns.

Does this make any sense?

In the old version, if you retained TUserInfoArray did you also have to retain the TUserInfo items?

I assume our Clone() will make this RetainObject also obsolete, correct?

Hi,

you can still use RetainObject. just cast to IROObjectRetainer:

function TRobotService2.GetLoggedUsers():TUserInfoArray;
begin
  Result := BorrowLoggedInUsers();
  (self as IROObjectRetainer).RetainObject(Result);
end;

yes


our code destroys only var and out parameters that aren’t retained, so usage of RetainObject with newuser isn’t needed.

destructor TROObjectDisposer.Destroy;
var
  i: Integer;
  l_retainer: IROObjectRetainer;
begin
  if Supports(fService, IROObjectRetainer, l_retainer) then begin
    // Only destroyes the var and out params the service is not retaining
    for i := Count - 1 downto 0 do
      if not l_retainer.IsRetained(Items[i]) then
        FreeOrDisposeOf(Items[i]);
    l_retainer := nil;
  end
  else begin
    for i := 0 to Count - 1 do
      FreeOrDisposeOf(Items[i]);
  end;

  fService := nil;
  inherited;
end;

Logged as bugs://D19702.

bugs://D19702 was closed as fixed.

Hi,

I’ve moved methods of IROObjectRetainer to public section again.

Sorry for inconvenience