Is it advisable to keep a zTable always open?

Asked

Viewed 78 times

2

I am developing a product registration system and cash front.

My main form is the Order screen and from it I open the other registration screens (Unit of Measure, Products, Payment Methods, Customers, among others)

For each of these screens I have a zTable in a Data Módule. And in the Onshow/Onclose of each form, I open/close the zTables.

As in the main screen I need these open zTables, my question is the following: It is advisable to open them in the main form and keep them open all the time my application is running?

1 answer

1


This has to be seen from 2 sides

1. How often these tables are amended?

If they are not updated frequently, it is worth keeping them open, but you should take care that the information is not outdated

2. How large are these tables?

If they have a lot of data, if they stay open they can take up a lot of memory, and depending on the device they’re running, it can be impeding.

As to where to keep them open:

An interesting idea is to create a project Singleton like caching generic data for your application, not necessarily in the main form, to avoid too complex dependencies.

In addition implement a Lazyload concept, only upload this data to 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;
  • 1

    I think I get @Caputo. So instead of me using ztUnidadesMedida.Open I would use GetUnidadesMedida of the object DadosCache, correct? And to set that mine FUnidadesMedida is my zTable ztUnidadesMedida, I do this in the object constructor, correct?

  • That’s right @Thiagothaison, so you keep all the cache in one place, and if someone works in finance, for example, you might not need all this data open. The Get method would be encapsulated in the Property, then you would use Cache.UnidadesMedida

Browser other questions tagged

You are not signed in. Login or sign up in order to post.