I applied the lastest revision, and I tested it again with a new debug information reporter, typing "12345":
user@ubuntu:~/maskedit$ ./project1
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = True Current Text = ________
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = ________
TCustomMaskEdit.TextChanged: Disallowing the change
TCustomMaskdit.KeyPress: Key = 1
TCustomMaskEdit.InsertChar: Ch = 1 CanInsertChar = True
TCustomMaskedit.InsertChar: calling SeInheritedText(1_______)
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = True Current Text = 1_______
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = 1______
TCustomMaskEdit.TextChanged: Disallowing the change
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = True Current Text = 1_______
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = 1_______
TCustomMaskEdit.TextChanged: Disallowing the change
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = 1_______
TCustomMaskEdit.TextChanged: Disallowing the change
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = 1_______
TCustomMaskEdit.TextChanged: Disallowing the change
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = 1_______
TCustomMaskEdit.TextChanged: Disallowing the change
TCustomMaskEdit.TextChanged: IsMasked = True FChangeAllowed = False Current Text = 1_______
TCustomMaskEdit.TextChanged: Disallowing the change
user@ubuntu:~/maskedit$
This sucks.
In this piece of info, I can only see one KeyPress (namely '1').
There seems to be an (endless?) number of TextChanged, when there should be only one.
In theory:
- you press '1'
- KeyPress calls InsertChar
- InsertChar determines the Key can be inserted
- InsertChar then calculates the new text
- Mind you: up until now, the text in the control has not changed!
- InsertChar calls SetInheritedText with the appropriate new text content
- SetInheritedText sets FChangeAllowed to True and sets the text in the control
- Only now the text in the control gets changed
- The widgetset (GTK2 in this case) detects this and fires a signal
- The signal is caught by the app (LM_TEXTCHANGED I believe) and TextChanged will be executed
- In TextChanged FChangeAllowed = True
- Inherited TextChanged is called (the one from TCustomEdit)
- This calls Change, but does not alter the text (in our case)
- This calls the OnChange handler (if one is assigned)
- TextChanged is done now
- Return to SetInheritedText, which sets FChangeAllowed back to False
So there should be only one call to TextChanged after each keypress, but in your case there are multiple.
So something else must be somehow changing the contents of the control?
The whole purpose of the FChangeAllowed business is that, for example, in GTK2 you can select text in the control and then drag it to another position.
This will trigger a TextChanged, and FChangeAllowed will be False (and so it must be) in this case.
What I also do not understand is the following: in the beginning the control looks like '__________' , this is achieved via the same mechanism (see TCustomMaskEdit.Clear) and it seems to work OK on your machine.
Can you do me a favour and use my testsuite (see attachment in my previous message). Don't change any properties in OI, just build an run.
On startup the MaskEdit (topmost edit) is not masked (so it acts as a TEdit).
Now press the "Apply Mask" button.
This will set the EditMask to whatever is in the second Edit control (just leave the default 'cccccc' as it is)
Since setting a new EditMask also clears the MaskEdit control it's text should now read '______'
Does it do that?
Now press the "Set Text" button.
It will try to set MaskEdit.Text to whatever is in the third Edit control (just leave the default 'ABCDEF' as it is)
The text in the MaskEdit should now be 'ABCDEF'
Does it do that?
At this point, if there is any text in the MaskEdit, select one (or more) character(s) and press Delete.
The selected chars should be replaced with '_'
Does is do that?
And one final question:
In your own program can you create an OnChange handler for the MaskEdit.
In it just do
Debugln('OnChange');
(Debugln is in LCLProc unit, so you need to include that in your uses clause)
Then run these 2 scenario's
1
- EditMask = '' (empty mask)
- run
- type '1' in the control (just once)
- close the program
2
- EditMask = 'cccccc'
- run
- type '1' in the control (just once)
- close the program
How many OnChanges do you see in each of the 2 scenario's?
Bart