I didn't mean to confuse anyone. I posted just the relevant code to my question, but I'll add to it.
This is the working code:
procedure TForm1.btnPreviousClick(Sender: TObject);
var
i: Integer;
begin
btnVerify.Enabled:= False;
DMod1.ZQ_Main.Close;
DMod1.ZQ_Main.SQL.Text := 'SELECT question, a1, a2, a3, a4, the_answer ' +
'FROM mult_choice '+
'WHERE id = :id';
i:= previousVec.Size - previousTracker; // previousVec is a global vector, and previousTracker is a global integer
DMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i-1];
DMod1.ZQ_Main.Open;
lblQuestion.Caption:= DMod1.ZQ_Main.Fields[0].AsString;
rbtn_A1.Caption:= DMod1.ZQ_Main.Fields[1].AsString;
rbtn_A2.Caption:= DMod1.ZQ_Main.Fields[2].AsString;
rbtn_A3.Caption:= DMod1.ZQ_Main.Fields[3].AsString;
rbtn_A4.Caption:= DMod1.ZQ_Main.Fields[4].AsString;
lblTheAnswer.Caption:= DMod1.ZQ_Main.Fields[5].AsString;
if i = 1 THEN btnPrevious.Enabled:= False;
previousTracker:= previousTracker + 1;
end;
Please note lines 11 and 12.
Now, here's the code that fails. Note the changes in lines 11 and 12:
procedure TForm1.btnPreviousClick(Sender: TObject);
var
i: Integer;
begin
btnVerify.Enabled:= False;
DMod1.ZQ_Main.Close;
DMod1.ZQ_Main.SQL.Text := 'SELECT question, a1, a2, a3, a4, the_answer ' +
'FROM mult_choice '+
'WHERE id = :id';
i:= (previousVec.Size - previousTracker) - 1;
DMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i];
DMod1.ZQ_Main.Open;
lblQuestion.Caption:= DMod1.ZQ_Main.Fields[0].AsString;
rbtn_A1.Caption:= DMod1.ZQ_Main.Fields[1].AsString;
rbtn_A2.Caption:= DMod1.ZQ_Main.Fields[2].AsString;
rbtn_A3.Caption:= DMod1.ZQ_Main.Fields[3].AsString;
rbtn_A4.Caption:= DMod1.ZQ_Main.Fields[4].AsString;
lblTheAnswer.Caption:= DMod1.ZQ_Main.Fields[5].AsString;
if i = 1 THEN btnPrevious.Enabled:= False;
previousTracker:= previousTracker + 1;
end;
In the top block of code, I use
i:= previousVec.Size - previousTracker;
Then I use the value of i and subtract 1 from it:
DMod1.ZQ_Main.Params.ParamByName('id').AsInteger:= previousVec[i-1];
This works perfectly. No issues at all.
However, when I combine the math in the second block of code:
i:= (previousVec.Size - previousTracker) - 1;
it should provide me the same outcome as the code in the first block. But it fails. So I was thinking I cld get clarity on this here in the forum.