How do you force the focus? lazarus / 9-Editor ---------------------------------------------------------------------- Bartlebee · 2013-11-22 16:52 Hi I'm new to Lazarus, and I need a little help. I'm trying to make it so when they leave DBEdit0, if it has an error, to be forced to stay on DBEdit1. How do I force them to stay on DBEdit0? Below is my code, and you can see my failed attempt. procedure TForm1.DBEdit0Exit(Sender: TObject); begin   If length(DBEdit0.text)> 5 then   begin     Label8.caption:='Error';     Label8.color:=clRed;     TControl.MouseMove(Shift:'ssLeft'; X:480, Y:24);   end   else   begin     Label8.caption:='';     Label8.color:=clDefault;   end; ---------------------------------------------------------------------- wp · 2013-11-22 17:01 Code: [Select]procedure TForm1.DBEdit0Exit(Sender: TObject); begin   If length(DBEdit0.text)> 5 then   begin     Label8.caption:='Error';     Label8.color:=clRed;     DBEdit0.SetFocus;      // <------ use SetFocus   end   else   begin     Label8.caption:='';     Label8.color:=clDefault;   end; ---------------------------------------------------------------------- exdatis · 2013-11-22 17:01 SetFocus ---------------------------------------------------------------------- exdatis · 2013-11-22 17:03 Sorry wp, the same time. Your answer is complete. ---------------------------------------------------------------------- Bartlebee · 2013-11-22 18:35 Thank you both! This was exactly what I was looking for. Seems to be working very smoothly, but it appears that the user can escape from correcting the data by clicking into another record of the DBGrid. Is there any way to stop that? ---------------------------------------------------------------------- wp · 2013-11-22 19:33 It seems that the dataset linked to the DBGrid is in edit mode since you are entering data. When you click another row of the grid the dataset posts the currently edited data. Therefore, you have to intercept the event BeforePost. I did not yet try in Lazarus, but in Delphi there is a silent exception "Abort" being raised to avoid posting the data. Something like this should work: Code: [Select]procedure TForm1.DatasetBeforePost(Sender: TObject); begin   If length(DBEdit0.text)> 5 then   begin     Label8.caption:='Error';     Label8.color:=clRed;     DBEdit0.SetFocus;        Abort;  // <--- this "aborts" the posting process   end; end; And the AfterPost event should do the "if true" part of your code, because it is reached only when the data are correct: Code: [Select]procedure TForm1.DatasetAfterPost(Sender: TObject); begin     Label8.caption:='';     Label8.color:=clDefault; end;