#1 2016-08-23 18:49:29

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Safe way to verify that the child record has been instantiated

TTestChild = class(TSqlrecord)..

Ttest = class(TSqlrecord)
published
  ...
  Child : TTestChild read FChild write FChild;
end;

//Retrieve child if exists
if ATest.Child <> nil then
begin
   ATest.Child := TTestChild.Create(Database, ATest.Child);
   Log(ATest.Child.Name);
end;

But now, how i test if child is retrevied to avoid to retrieve again?

And ATest.Child assigned with this form is freed when ATest is freed?

Offline

#2 2016-08-24 13:55:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,667
Website

Re: Safe way to verify that the child record has been instantiated

It depends on how the TTest class instance is created.

See http://synopse.info/files/html/Synopse% … ml#TITL_70

If you use CreateJoined, it will create the instance for you.

But IMHO the safest approach is to define a TID published property, and use a public property with a getter to create a TTestChild local instance.

Offline

Board footer

Powered by FluxBB