I have the following procedure in Delphi 6:
procedure TfrmUserCRUD.ShowErrorWithFocus(Message: string; FocusedField: TWinControl); begin try raise Exception.Create(Message); except on E : Exception do begin ShowMessage(E.Message); FocusedField.SetFocus; Abort; end; end; end; This is how I'm calling the function:
procedure TfrmUserCRUD.ValidateFields(); begin if not(chkListProducts.Checked) and (chkUsesProductValue.Checked) then ShowErrorWithFocus('You need to use the product list if you wanna use the product value.', chkListProducts); if (chkUsesProductValue.Checked) and (edtProductValue.KeyValue = nil) then ShowErrorWithFocus('The field "value of product" needs to be filled', edtProductValue); end; The objective of this procedure is to receive an error message and one of the fields from the form (CheckBox, Grid, Edit, etc) and whenever the function is called, it's supposed to show the message on screen with the error, then focus the field that it received like the system was highlighting it, like in those pictures:
I've been trying to use different methods so it could focus on the field, but if I use raise, the program loses the field variable, if I use Abort, the program doesn't do anything. I've also tried different ways of focusing the TField, like using Perform() and event updates, but it didn't worked as intended.
Any ideas of what I could do to resolve this problem?


ShowErrorWithFocusmethod? You may need to edit the question with minimal reproducible example Theabortprocedure in the exception handler is useless. See the documentation on what Abort does docwiki.embarcadero.com/Libraries/en/System.SysUtils.Abort