[fpc-pascal] Generics in Objective Pascal?
Zoë Peterson
zoe at scootersoftware.com
Mon Nov 2 21:30:27 CET 2020
On 11/2/20 1:01 PM, Ryan Joseph via fpc-pascal wrote:
> What are you trying to do exactly? There are categories in ObjC but those don't allow fields (they're like helpers in Object Pascal). If you need to share data between a bunch of different NSView subclasses then all you can do is make a common subclass or make the shared data a class of its own and pass that into all your subclasses. Nothing ObjC related about that however but I'm not sure what you're trying to do.
I have an NSView subclass with a bunch of fields and methods, and I
wanted to be able to optionally swap that out with a parallel version
derived from NSVisualEffectView without duplicating all of the code. I
was hoping that adding generics to objcclass would be relatively trivial
and just hadn't been asked for, but I know how assuming that usually goes.
More specifically, under LCL/Cocoa, TCustomControl's Handle uses a
TCocoaManualScrollView(NSView) (in
lcl/interfaces/cocoa/cocoascrollers.pas) that has a bunch of code to
interact with the LCL objects. When running recent versions of macOS in
dark mode, custom controls like TTreeView actually use a
behind-the-window blur rather than a plain clWindow FillRect. Since a
lot of the TCocoaManualScrollView interaction is just general NSView
messages or LCL protocol/category extensions, I figured I could keep the
changes fairly small if I was able to just swap in a
TCocoaManualScrollView<NSVisualEffectView>, which would avoid
introducing another view in the hierarchy, keep the code cleaner, and
be easier to disable if MACOS_MINIMUM_DEPLOYMENT_TARGET < 10.10.
I should be able to make it work with composition and re-parenting
things when necessary, but there will be a lot more management code, so
I thought I'd ask.
--
Zoë Peterson
Scooter Software
More information about the fpc-pascal
mailing list