Try-Except catching exception but still throwing the AV error delphi

  

I have this submethod inside a method in my Delphi FMX code, but it is still throwing an exception on the combobox part. I am forcing the error by letting the combobox index to be -1, but since I’ve put try before the if why is it still throwing the error for me instead of just the message showing that the field has incorrect value? Do I need to put the try inside each block to prevent that error throw?

procedure TForm1.setFields;
var
i: integer;
begin
for i := 0 to ComponentCount – 1 do
begin
try
if (Components[i] is TEdit) then
begin
FDQuDB.FieldByName((Components[i] as TEdit).Name).Value :=
(Components[i] as TEdit).Text;
end
else if (Components[i] is TComboBox) then
begin
FDQuDB.FieldByName((Components[i] as TComboBox).Name).Value :=
(Components[i] as TComboBox).Selected.Index;
end
else if (Components[i] is TListBox) then
begin
(Components[i] as TListBox).Items.Delimiter := ‘|’;
FDQuDB.FieldByName((Components[i] as TListBox).Name).Value :=
(Components[i] as TListBox).Items.DelimitedText;
end;
except
on E: Exception do
begin
ShowMessage(‘Invalid value for “‘ + Components[i].Name + ‘!’);
abort;
end;
end;
end;
end;

Comments are closed.