Is it advisable to keep a zTable always open?

2

I'm developing a product registration system and cash front.

My main Form is the Orders screen and from there I open the other registration screens (Units of Measure, Products, Forms of Payment, Customers, etc.)

For each of these screens I have a zTable in a DataModule. And on the OnShow / OnClose of each form, I open / close zTables.

As the main screen I need these open zTables, my question is: Is it advisable to open them in the main form and keep them open for as long as my application is running?

    
asked by anonymous 08.08.2014 / 02:18

1 answer

1

This has to be seen on 2 sides

1. How often do these tables change?

If they are not updated frequently, it's worth keeping them open, but you should be careful that the information is not outdated.

2. What is the size of these tables?

If they have a lot of data, if they are open they can take up too much memory, and depending on the device they are running, it can be crippling.

As for where to keep them open:

An interesting idea is to create a Singleton object as a generic data cache for your application, not necessarily in the main form, to avoid very complex dependencies.

Also implement a LazyLoad concept, just load this data into memory after the first request.

TDadosCache = class
private
  FUnidadesMedida: TZTable
published
  property UnidadesMedida: TZTable read GetUnidadesMedida;
end;

function TDadosCache.GetUnidadesMedida: TZTable;
begin
  if not FUnidadesMedida.Active then
    FUnidadesMedida.Open;

  Result := FUnidadesMedida;
end;
    
08.08.2014 / 13:29