Locate in Delphi

2

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

I need to check if there is any situation other than conferido , I tried Locate direct with checked, but the way I did it will not work.

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

if not dmContratoEmpresarial.cdsContratoEmpresarialContratos.Locate('SITUACAO', 'CONFERIDO', []) then
    fMensagem.Adicionar('Os contratos não foram todos conferidos');
    
asked by anonymous 01.06.2016 / 16:29

1 answer

6

The Locate method places the cursor in the first record whose specified column is equal or partially equal ) to the specified value, returning false if you can not find a record under these conditions.

So this search method does not seem to fit your needs.

You can then use the Filter property, something like this:

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

Ready. Now the dataset contains only records that do not satisfy the condition, that is, "contracts that have not been checked".

You can count the records in dataset (property RowCount if it is a clientdataset , and the name of the component seems to be), showing the message that there are unconfirmed contracts if there is more than one record, or you can still display for the user the unconfirmed contracts (which are all records still present in dataset ).

To disable the filter, just set the Filtered property back to false :

cdsContratoEmpresarialContratos.Filtered := False;
    
01.06.2016 / 18:50