Hi,
I am trying to use a TAdvMaskEdit component with a OnValidateError event,
However I do not understand how / when this event is raised.
When I look at the component source code, this event is raised from the ValidateError procedure. This procedure is overrides from TCustomMaskEdit and doesn't call it's inherited counterpart. All the ValidateError does is call the OnValidateError event if it's assigned.
Nowhere in the TAdvMaskEdit is the ValidateError procedure called. The only place I see the ValidateErrror procedure called in inside the ValidateEdit of TCustomMaskEdit.
The problem I see is that the ValidateEdit procedure is also overiden in TAdvMaskEdit and doesn't call inherited. All the overrided version does is call the OnValidateEdit event if it's assigned.
At first glance, I would think that an inherited call is missing from the ValidateEdit in TAdvMaskEdit
If this is working as intended, can you please provide a small demo explaining how to use a TAdvMaskEdit with a OnValidateError event?
Thanks
ValidateError is a virtual function in the standard VCL TMaskEdit base class and is called from this base class. In our component TAdvMaskEdit, we override this virtual method to trigger an event from it. This ValidateError method in the base class VCL TMaskEdit is called when a value is entered that doesn't match the specified mask.
Hi,
I understand and this is exactly what I need but it doesn't seem to work.
The event is never fired.
Please try it.
However if I change the following:
procedure TAdvCustomMaskEdit.ValidateEdit;
begin
if Assigned(OnValidateEdit) then
FOnValidateEdit(Self)
end;
to
procedure TAdvCustomMaskEdit.ValidateEdit;
begin
inherited;
if Assigned(OnValidateEdit) then
FOnValidateEdit(Self)
end;
Then it works (at least the event will fire as expected). I really think that the inherited call is needed here.
Is this something that can be fixed?
Thanks
We'll fix it this way.
Hi,
in your fix, can you please do
procedure TAdvCustomMaskEdit.ValidateEdit;
begin
if Assigned(OnValidateEdit) then
FOnValidateEdit(Self);
inherited;
end;
instead of
procedure TAdvCustomMaskEdit.ValidateEdit;
begin
inherited;
if Assigned(OnValidateEdit) then
FOnValidateEdit(Self)
end;
By having the inherited call after the OnValidateEdit event, the OnValidateEdit event can be used to auto-correct (if possible) the input and avoid errors launching the OnValidateError event.
Thanks!
Ok, that makes sense and we've adapted it accordingly.