Topic: Returning from a sub form

Hi All,
I have a button on a form (frmMain) and it is next to one of my memo fields.  This button calls another form (frmMemo) where I can View/Edit the information in the memo field. This works fine (thanks to help from folks on the forum smile  )  However when I close frmMemo it goes back to the first field on the frmMain form.  I'd like to go back to the field I was in when I called frmMemo.
-
Any thoughts will be appreciated.
Thanks, Frank

2 (edited by derek 2020-12-15 15:22:38)

Re: Returning from a sub form

Hi Frank,
You could try it like this (see attached).
Not sure if there's any easier way.
Derek.

Post's attachments

Attachment icon active field.zip 336.13 kb, 219 downloads since 2020-12-15 

3 (edited by papafrankc 2020-12-16 05:37:25)

Re: Returning from a sub form

Derek,

Your solution does the job smile 
Going back to the field that I came from is a lot better than having the user have to look around on the form to see which field is active.
-
I've already included it in one of my forms with no problems.
-
Thanks.
Frank

4 (edited by derek 2020-12-15 20:45:46)

Re: Returning from a sub form

It might be a bit of overkill but you can also highlight the focussed cell with colour so when you return from your memo form, not only is the cursor still on the same field but the color highlighting is still switched on..
It depends on the nature of the form, number of fields on it etc etc, but it can be effective when it's not always obvious where the cursor is flashing.
Other options might be to change the mouse pointer (crhandpoint, for example) which can be done without any script.
Derek.

Post's attachments

Attachment icon active field2.zip 336.84 kb, 256 downloads since 2020-12-15 

5 (edited by CDB 2020-12-20 06:59:11)

Re: Returning from a sub form

Hello Papafrank and Derek,


Derek I hope you don't mind, but I'd like to offer a minor difference to your code, which in its' present state no longer keeps the edit box on return from form 2, so of course doesn't quite do what Papafrank wants, but could be useful for someone else.

1. Click on the Form1 adn enable the property 'Key Preview'

2. Double Click on the Form1 event OnKeyPress  and add below code to the script

procedure Form1_OnKeyPress (Sender: TObject; var Key: Char);

begin
    if Key = #13 then
    begin     
        twincontrol(form1.findcomponent(vwherefrom)).setfocus;
      Key :=#0;
    end;

end;

3. Amend the Form1_EditXX_OnEnter code to:


Procedure Form1_Edit1_OnEnter (Sender: TObject);
begin
  vwherefrom := Form1.Edit2.Name; //'edit1';
  resetcolors;
  form1.edit1.Color := $00C0DCC1;
end;

Do that to all the 'OnEnter' code and then you also not only have the edit boxes change colour when you click in them  but you can now move from edit box to edit box just by pressing the Enter key.


The advantage to changing vwherefrom := 'EditXX' to vWhereFrom := Form1.EditXX.Name   is that if you change the EditBox name at anytime you won't have to change the script. It also allows for some cut and paste into other programs.


Note that each edit box vWhereFrom := Form1.EditXX.Name 'points to the next edit box , not the current one


I tried to see if there was a way to have 'intelligent code' which would recognise which edit box had been entered and automatically move to the next edit box but I couldn't get

if form1.Controls[i] is TEdit   

or

if form1.components[i] is TEdit

to work.

On a clear disk you can seek forever