Locate in the Delphi

Asked

Viewed 865 times

2

I have a DataSet that returns multiple rows and in one of the columns I have the Situação of the record that may be: open, closed, in conference, conferred, finalized...

I need to check if there’s a situation that isn’t conferido, tried the Locate direct with the check, but the way I did it won’t work.

Another possibility would be to make a Locate for each of the situations to apply the restriction, but would like something better than to do several IFs.

if not dmContratoEmpresarial.cdsContratoEmpresarialContratos.Locate('SITUACAO', 'CONFERIDO', []) then
    fMensagem.Adicionar('Os contratos não foram todos conferidos');
  • Why do you use a query and make a select? Selects all records of those contracts that have different check status. If you return any, you know that you have unselected contracts. In addition, select is much faster than Locate.

1 answer

6


The method Locate position the cursor on the first record whose specified column is equal or (partially equal) to the specified value, returning false if you do not find registration under these conditions.

So this search method seems not to be suitable for your need.

You can then use the property Filter, sort of like this:

cdsContratoEmpresarialContratos.Filter := 'SITUACAO <> ''CONFERIDO'''`;
cdsContratoEmpresarialContratos.Filtered := True;

Ready. Now the dataset contains only records that do not satisfy the condition, i.e., "contracts that have not been conferred".

You can count the records on dataset (property RowCount if it is a clientdataset, and by the name of the component looks like it is), showing the message that there are no conferred contracts if there is more than one record, or may still show for the user the contracts not conferred (which are all reigistros still present in the dataset).

To disable the filter, simply set the property Filtered again to false:

cdsContratoEmpresarialContratos.Filtered := False;

Browser other questions tagged

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