[Lazarus] New TMaskList [forked from: TMask revisited]

Bart bartjunk64 at gmail.com
Wed Oct 27 13:30:56 CEST 2021


On Tue, Oct 26, 2021 at 10:44 PM Bart <bartjunk64 at gmail.com> wrote:

> I'll have a go at it then

To simplify matters I decided to remove the CreateWindows and
CreateNative constructors for TMaskList.
The CreateWindows skipped the population of fMasksWindows, but that is
a small price to pay IMO.
I can't have this as a constructor in TMaskListWindows, but I would
inherit it, so I got rid of it.
So, for the moment TMaskList always internally creates and populates 2 lists.

I tried to use a factory pattern, , so that I would not have to
replicate the Matches method for TMaskListWindows.
I factored out populating the respective objeclists (fMasks and
fWindowsMasks) and made that a virtual method so I could override that
in TMaskListWindows.

That has it's drawbacks however: in TMaskListWindows I have to iterate
through fMasks in order to set some privae variables/fields of the
created TMaskWindows instances, and then have to call the Compile
method.
(Duplicating some actions in the TMaskWindows constructor, so that
possibly needs updating when TMaskWindows constructor gets changed).

The problem turned out to be the fact that:
FMaskClass.Create(S[i], CaseSensitive, aOpcodesAllowed)
does not call the TMaskUtf8Windows constructor, when FMaskClass
definitely _is_ TMaskWindows (it calls TMaskUTF8 constructor
directly).

This probably is because the signature of te constructor has a long
list of default parameters.
Unfortunately you can't override that constructor in TMaskUtf8Windows:
you'll get a  "Error: Can't determine which overloaded function to
call".

So, I untangeld all constructors for TMaskUtf8:
    constructor Create(const aMask: String);  (1)
    constructor Create(const aMask: String; aCaseSensitive: Boolean);  (2)
    constructor Create(const aMask: String; aCaseSensitive: Boolean;
aOpcodesAllowed: TMaskOpCodes); virtual; overload; (3)

Then in TMaskUtf8Windows I override the last one (3) to call the
constructor with "quirks" parameter.

It may look a bit messy, but AFAICS all possible constructor calls still work.
(I had to add "overload" to constructor (3), otherwise constructors
(1) and (2) were not visible in TMaskWindowsUTF8, something about
constructors which I did not know).




-- 
Bart


More information about the lazarus mailing list