Topic: setfocus not working!

Hi,
I just have a simple DB, All i want to save data to database and set focus to a textbox after hitting enter.
saving works fine, but set focus not working!
how can I make it to work?
I just attached the project.

and I have another problem, Cannot have empty value for relations and must select notnull in database to prevent of error but sometimes I need to leave the field empty sad

Many Many Thanks

Post's attachments

Attachment icon Buchhaltung.zip 339.92 kb, 176 downloads since 2023-03-15 

Re: setfocus not working!

Your code does not work because the form property BuchhaltungsManager.KeyPreview = False.
But it will be right to add setting the focus to the event BuchhaltungsManager.Save.OnAfterClick:

procedure BuchhaltungsManager_Save_OnAfterClick (Sender: TObject);
begin
  BuchhaltungsManager.Grund.SetFocus;
end;

When you press the Enter key, the Save button will automatically click because it has the Default property set to True.

Визуальное программирование: блог и телеграм-канал.

Re: setfocus not working!

Hello Sonixax, Konstantin,
You need to be careful when saving a record using the 'enter' key but staying on the same form (Buchhaltungsmanager);  it is very easy to accidently create duplicate records. 
I would suggest that at least you make Buchhaltungs.grund mandatory in your data schema and clear this at the same time as re-setting focus.

procedure BuchhaltungsManager_Save_OnAfterClick (Sender: TObject);
begin
  BuchhaltungsManager.Grund.SetFocus;
  BuchhaltungsManager.Grund.clear;
end;

You also mention a problem with a relationship - I'm guessing that you are referring to foreign currency?  What problem does this cause if you set it to optional?
Derek.