Binded TwwEdit not posting unless change focus

Comments

6 comments

  • Michael Verhagen

    I had a major problem with this with TNumberBox and TComboEdit so I think that the problem is NOT in FirePower.

    If you use a TNavigator to Post your record, this does not switch focus away from the edit components because TNavigator cannot receive focus and I found that the one (edit component) that is in focus will not have its changed data posted.

    I have found that focus works much differently in FMX compared to VCL so it is not reliable to try to change focus in places such as dataset AfterScroll or edit component AfterExit.

    I read of others having a similar problem and even using a SLEEP somewhere in the process and that seemed to allow sufficient time for the edited data in the focused control to be seen by the Post.

    But the work-around that I use in my FMX/FireDAC/SQLite apps is to overlay the Post button in the TNavigator with my own TButton, and to have an image on that button that looks like the nav's Post button.  This button receives focus and because focus is moved away from the edit control, its contents is always seen by the Post.

    You could test this approach by just putting a TButton with OnClick of dataset.Post and see if it works for you without any additional changes.

    Others spoke of also switching focus back to the focused control in its OnChange and I'll check my apps later to see if I also do that, but I'm not sure it's necessary while using my work-around.

    0
    Comment actions Permalink
  • Roy Woll

    Besides what Michael said, if you are using your own button and canfocus is true, then it should update the tfield contents and be able to save the changes.  I believe you could also set focus to the form before calling post.

    0
    Comment actions Permalink
  • Michael Verhagen

    The problem is finding how and where to change focus at all when you're in edit/insert mode and focus is on an edit component that has had a change of value, in an FMX app.  Not sure if it's also dependent on FireDAC because I don't think I'd build an FMX app using some other database connection.

    Have you found an event that works reliably for moving focus away from the edit component?  I haven't.

    In VCL this was easy and I also discovered years ago that it was a good idea to move focus away from a datagrid in BeforeInsert and BeforeDelete because, when using ADO/dbGo and MS Access, you'd sometimes get nonsense failures reporting messages like "record cannot be found for updating" and some kind of message about "Bookmarks".  If simply moving focus in a BeforeEvent handler made the symptom disappear, the error had to have been bogus.

    0
    Comment actions Permalink
  • Michael Verhagen

    Oh, and aside from setting CanFocus to True on your TButton, if you have an image over it, you need to make sure that Image.HitTest = False so the click goes through it to the button underneath it.

    To make it easier to reach the Button.OnClick event handler code in the IDE, I also make the image small in the IDE and then set Image.Align=alClient at the time of app start-up.

     

    0
    Comment actions Permalink
  • Felix Castillo

    I changed the wwImage to a TButton and now it works, but I expected another solution, I then read the form.setfocus before the Post, I will try it later, I hope it works, because I prefer the picture than the button.

     

    Thank you very much!

    0
    Comment actions Permalink
  • Michael Verhagen

    You can have your image (picture) on top of the TButton and have best of both, as long as you have Image.HitTest set to False, because the button will then receive focus when you click on the image, so you don't need to set focus to the form.

    But if you wish to not use a TButton, then moving focus away from the focused control that contains changed data must be accomplished in another way.

    I did not try moving focus to the form in my BeforePost, but I did try moving it to things like a TEdit that the user does not see, and this did not work reliably in my tests.

    Even if setting focus to the form is not needed to cause data in the focused control to be posted, it is still a good idea to ensure that focus does not remain on an edit control when the dataset is no longer in Insert or Edit mode.

    Accomplishing proper Post behavior is critical, but it does not address other behavior in FMX that is different from VCL, so it would be a good idea to include things in your testing of the UI that also reveal if you have other work to do regarding use of TAB (assuming the app uses a keyboard) and the TabOrder of the controls and what happens when you TAB past the last edit control (and keep tabbing many times to see if focus comes back around to unexpected edit controls).  If those things cause problems for you as they did for me, please post a new question about it.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk