V
V
Vladimir Kai2017-03-13 15:11:28
MySQL
Vladimir Kai, 2017-03-13 15:11:28

Why does the algorithm skip the entry in Query?

Good afternoon!
Here is the code for checking table records:

procedure TProdAdd.sBitBtn1Click(Sender: TObject);
begin
if OrderView.ZQueryBasket.Active = True then
OrderView.ZQueryBasket.Edit
else ShowMessage('Сообщение1');

if (Quantity.Text = '') or (Name.Text = '') then ShowMessage('Сообщение 2!')

else
begin
OrderView.ZQueryBasket.Post;  // Проверка, если записей 3, то пересчитываем всем колонку "Сумма скидки"
OrderView.ZQueryBasket.Last;
if OrderView.ZQueryBasket.RecordCount > 2 then
begin
   OrderView.ZQueryBasket.First;
  while not OrderView.ZQueryBasket.Eof do
  begin
   OrderView.ZQueryBasket.Edit;
   OrderView.ZQueryBasket.FieldByName('discount_price').Value := OrderView.ZQueryBasket.FieldByName('base_price').Value * 0.1;
   OrderView.ZQueryBasket.Post;
   OrderView.ZQueryBasket.Next;
  end;
end;

end;

end;

Imagine that initially there is 1 record or 2 in the dataset, and we add another record, then another.
As a result, when records > 2 are reached, a run through the entire data set occurs and each of the records overwrites the "Discount Amount" field.
But one of the records is not recalculated, the program skips it.
But, if you continue to fill the table with entries, then upon reaching 5 entries, the program puts down the amount of the discount for everyone, including the previously missed entry.
I hope you understand what I'm trying to convey :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2017-03-13
@tsklab

if (OrderView.ZQueryBasket.Active = True) and then
OrderView.ZQueryBasket.Edit
else ShowMessage('Message1');
if (Quantity.Text = '') or (Name.Text = '') then ShowMessage('Message 2!')
else
begin
OrderView.ZQueryBasket.Post; // Check if there are 3 records, then recalculate the "Discount Amount" column for all
OrderView.ZQueryBasket.Last;
if OrderView.ZQueryBasket.RecordCount > 2 then

if ( OrderView.ZQueryBasket.Active = True ) and ( OrderView.ZQueryBasket.RecordCount > 2 ) then

K
kalapanga, 2017-03-13
@kalapanga

And look during the execution of this procedure at RecordCount - does it correspond to your number of records?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question