Subject Re: [IBO] TEditEnh component selstart and sellength
Author Geoff Worboys
> I made a small program with the TEditEnh component becouse of
> the mask property but I have find out some strange thing.
> I use the OnChange event to trap the changes in the component but
> when I want to access the SelStart and SelLength propertys I
> always get 0 as a result when I apply the mask to the control.

The reason why SelStart is 0 is that the input processing is actually
done in a separate mask buffer and then the new text assigned to the
control buffer. So every time you see a change event when a mask is
defined, it is the entire text being replaced (so the API thinks the
caret is at the start).

You have two options...

1. Use the OnKeyUp event - at this point all the synchronisation
should be complete and everything where it should be.

OR

2. Update CustomEditEnh.pas as follows and rebuild IBO.

procedure TCustomEditEnh.CMTextChanged(var Message: TMessage);
begin
if IsMasked then begin
if FInternalUpd = 0 then begin
if FModifyFlag then begin // If a genuine modification to
the text
Modified := true; // tell everyone it is modified
SyncCaretToPosition; // <<< INSERT THIS LINE
end
else begin // otherwise pretend we've only just entered...
Mask.SaveMaskTextTo( FSavedText );
Mask.InitMaskInput( false );
SyncCaretToPosition;
if AutoSelect and not (csLButtonDown in ControlState) then
begin
SelectAll;
SyncSelection( VK_END, false );
end;
end;
if DoTextChange then
inherited;
end;
end
else begin
if DoTextChange then
inherited;
FSavedText := Text;
end;
end;


If you can afford the time I would appreciate it if you could try
option 2 and tell me how it goes. I do not want to release this fix
until I am sure it does not disrupt anything else (the mask
synchronisation can get very touchy :-)


HTH

Geoff Worboys
Telesis Computing