[Lazarus] Attn José: TWindowsMask oddity?

Bart bartjunk64 at gmail.com
Mon Nov 1 15:31:04 CET 2021


On Mon, Nov 1, 2021 at 12:22 PM José Mejuto via lazarus
<lazarus at lists.lazarus-ide.org> wrote:

> The target in *Windows classes is to mimic the old fashion CMD masks,
> and CMD masks does not have ranges or sets.

OK, this is by design.
Since that is however not backwards compatible (the old mask
implementation supported sets out of the box by default on all
platforms, I changed "our" implementation.

A note: IIRC (do not have the source at hand here) you escape [ ] and
\, with or withoud mocEscapeChar enabled.
if mocEscapeChar is not enabled, escaping these in the mask is
probably not what you want.

> LCL's TMask raises syntax errors (or others, I can not recall) at
> creation time and in my code the syntax check is at Compile time so I
> call compile to raise an exception if needed.

Yes, the old mask did so, whci, to be hones, is a PITA.
Normally you do
SomeVar := TSomeClass.Create(...);
try
  SomeVar.SomeThing;
finally
  SomeVar.Free
end;

If you know you can let the constructor fail, just by giving it an
"invalid" parameter, you hve to rewrite you code to:

SomeVar := TSomeClass.Create(...);
if Assigned(SomeVar) then
begin
  try
    SomeVar.SomeThing;
  finally
    SomeVar.Free
  end;
end;

So, I changed it (and documented it as a change that breaks backwards
compatibility).

> Compile should not be called again unless the mask is changed
> via the property.

I think, that does not happen.
The Mask property IIRC does not have a setter.

I introduced a setter for the mask property, it sets fMaskIsCompiled to False

Also, if compile fails and the user/prgrammer is stupid enough to call
Matches again, Matches will simply return False (no exception), whic
(even if the programmer is stupid) is a bad thing IMO.
I fixed that by setting fMaskIsCompiled to False as first line in
Compile and only set it to True if Compile does not raise an exception
(so it finishes).

Something else.
When you reset the mask, you should also reset the internal
representation of the mask and it's associated length value, otherwise
you get an access violation when you set mask via the property and
then call Matches.

Again, thanks for helping me out.

-- 
Bart


More information about the lazarus mailing list