Subject Re: [IBO] Re: TEditEnh component selstart and sellength
Author Geoff Worboys

> Thanks for answering. I tryd both options but without success.
> With the second option I got the right selstart but when I try
> to set it dont work.

I did not realise that you wanted to also set SelStart/SelLength.
From your first posting I thought you only wanted to read the values.
Setting the selection is going to be problematic because the mask
processing is forced to do a lot of management in this area.

I guess my first question is; What is it you are trying to achieve?
From your code it appears that you may be trying to limit input to a
set of permitted values. If that is the case, have you considered
using a combobox instead?

In particular you could try TComboBoxEnh available from the
EnhComponents - download from the IBO registered users site.
TComboBoxEnh is derived from TCustomEditEnh and so supports masks and
its incremental searching works better than the standard API combo
(IMHO :-).

The other possibility that I see is that you are trying to work around
the character definition limitation in the masks. I have a new
version of EditEnh (to be released when IBO4 becomes available) that
has the ability to define your own mask input characters. If your
problem is not urgent then this may be a solution.

And finally. If you really need to proceed with the code that you are
using, then you will need to make another change to the CustomEditEnh
source. Find the declarations for

procedure SyncPositionToCaret;
procedure SyncCaretToPosition;

in the protected section of the TCustomEditEnh class (in
CustomEditEnh.pas). Move these two declarations into the public
section of the class and rebuild. Then in your code where you set the
selection add a call to SyncPositionToCaret. eg...

> TEdit(Sender).SelStart := OldSelStart;
> TEdit(Sender).SelLength := Length(newvalue) - OldSelStart;

This will try to force the mask buffer to resynchronise with the new
caret position. This is not necessarily reliable, since the mask
processing must have the selection performed in a particular manner
according to the mask type, so it is still possible that the selection
may not end up where you want it.

Do let me know what you end up doing as I will probably NOT make the
Sync* procedures public unless it is the only way you can achieve what
you need. Actually this reminds me, you could derive your own class
from TCustomEditEnh that will do the processing you require more
directly and prevent the need to change the main release directly.

Geoff Worboys
Telesis Computing