* * *

Author Topic: Best Way  (Read 1370 times)

JLWest

  • Full Member
  • ***
  • Posts: 192
Best Way
« on: February 10, 2018, 07:49:42 am »
What is the best way to check if data was entered into a  TDirectoryEdit?

I thought I saw a Form Subject on this but I can't find it.
JLWEST 
 FPC 3.0.4, Lazarus IDE v1.8.2 Windows 10 Pro
 Intel i7 770K CPU 4.2GHz 16 Gig Ram
GeForce GTX 1080 Graphics - 8 Gig 1.5 Terabyte SSD

dsiders

  • Jr. Member
  • **
  • Posts: 52
Re: Best Way
« Reply #1 on: February 10, 2018, 08:02:39 am »
What is the best way to check if data was entered into a  TDirectoryEdit?

I thought I saw a Form Subject on this but I can't find it.

I'm thinking the onEditingDone event handler. Supposedly you can access the value in the Text property at that point.

Lazarus 1.8.2 / FPC 3.0.4 / Windows 8.1 64-bit

JLWest

  • Full Member
  • ***
  • Posts: 192
Re: Best Way
« Reply #2 on: February 10, 2018, 08:43:22 am »
That's What I'm using but was wondering if there isn't a better way.
I'm having inconsistencies with editingDone.
JLWEST 
 FPC 3.0.4, Lazarus IDE v1.8.2 Windows 10 Pro
 Intel i7 770K CPU 4.2GHz 16 Gig Ram
GeForce GTX 1080 Graphics - 8 Gig 1.5 Terabyte SSD

Soner

  • Jr. Member
  • **
  • Posts: 60
Re: Best Way
« Reply #3 on: February 10, 2018, 01:33:45 pm »
I think TDirectoryEdit has bug or malfunction.
OnAcceptDirectory called if user selects from Dialog.
OnEditingDone called if user press [enter] in TEdit .

I would change this and OnAcceptDirectory should be called for both cases.
Pressing to [enter] meaning "I want it, I selected this."

Bart

  • Hero Member
  • *****
  • Posts: 3029
    • Bart en Mariska's Webstek
Re: Best Way
« Reply #4 on: February 10, 2018, 02:06:52 pm »
No, because it would fire then also if you leave the control.

Bart

Handoko

  • Hero Member
  • *****
  • Posts: 2443
  • My goal: build my own game engine using Lazarus
Re: Best Way
« Reply #5 on: February 10, 2018, 03:00:45 pm »
@JLWest

Can you explain on what cases you need it?

My guesses are:
1. After user provide/edit the TDirectoryEdit, you check its validity
2. You skip to save the config data, if the TDirectoryEdit hasn't changed

Instead of putting the code for the validation inside TDirectoryEdit's event, I think it will be better (and easier) to put the code inside the "OK" or "Save" button's event.

Bart

  • Hero Member
  • *****
  • Posts: 3029
    • Bart en Mariska's Webstek
Re: Best Way
« Reply #6 on: February 10, 2018, 03:37:11 pm »
I think TDirectoryEdit has bug or malfunction.
OnAcceptDirectory called if user selects from Dialog.
OnEditingDone called if user press [enter] in TEdit .

I would change this and OnAcceptDirectory should be called for both cases.
Pressing to [enter] meaning "I want it, I selected this."

This will also be inconsistent:
You cannot simply call OnAccept* in EditingDone since that will be triggered also when the user, from inside the edit, clicks the button.
Why then call OnAccept* only when user pressed enter (as an indicator the he is done editing), but not when user exits the control?

The OnAccept* event IMO should anly be used for validation if DirectInput = False, or ReadOnly = True.
In other cases the input should be validated when it is used later on in the code.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 785
Re: Best Way
« Reply #7 on: February 10, 2018, 03:41:54 pm »
That control has the Tedit derivative in it, so you can use the OnChange event and test the MODIFIED property
within the Onchange..

 Modified indicates the difference between user EDIT changes and directly changing the text via code which means
the dialog should change to the EDIT.text field should be setting this.
 
 a check I just did using 1.8.0 64 indicates the modified property gets set to true on any changes from
user EDITING or dialog box Setting of the Text property.

 Setting the Text property of the EDIT box from other sources does not trigger the Onchange if the text Is the
same and if the text is different it does trigger the Onchange but does not set the MODIFIED property.

 So basically, if Onchange does get called, testing for the Modified = True indicates that it was done with user EDIT or
 the dialog changed it, but does not set MODIFIED = true if external sources sets the property Text;

  So in short You could use the OnChange event to maintain correctness of the path given.

JLWest

  • Full Member
  • ***
  • Posts: 192
Re: Best Way
« Reply #8 on: February 10, 2018, 07:23:47 pm »
@JLWest

Can you explain on what cases you need it?

My guesses are:
1. After user provide/edit the TDirectoryEdit, you check its validity
2. You skip to save the config data, if the TDirectoryEdit hasn't changed

Instead of putting the code for the validation inside TDirectoryEdit's event, I think it will be better (and easier) to put the code inside the "OK" or "Save" button's event.

In my case I have two buttons on the config screen Update and a Quit.

So you advocate validating the data entered in the TEditDirectory on the Form Update button. I can see that would work.
JLWEST 
 FPC 3.0.4, Lazarus IDE v1.8.2 Windows 10 Pro
 Intel i7 770K CPU 4.2GHz 16 Gig Ram
GeForce GTX 1080 Graphics - 8 Gig 1.5 Terabyte SSD

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus