Forum > General

How to add operators to an existing record that can't be edited?

(1/3) > >>

jamie:
In this case:
   Windows.LogFont.

 using FpgMap<LogFont, TFONT> for example.

 It requires that logFont has <> operators.

 I can create a local TLogFont with a logfont in it, however, that creates a mess because now I need an identifier for that logfont because the language does not support anonymous records inside another, nor does RECORDS support inheritance, which would also solve this issue.

I tried implementing operators in the unit for this record, but the compiler won't have it, it wants to see a CLASS for this to work.

I looked around and did not find a TLogFont record ready made with operators.

Thaddy:
The easiest solution is to write a type helper for logfont.
Slightly more involved is a unit with the TLogfont copied and the operators implemented on your copy.

PascalDragon:

--- Quote from: Thaddy on August 24, 2024, 05:13:35 pm ---The easiest solution is to write a type helper for logfont.
--- End quote ---

That won't help either, cause at specialization time the compiler only sees the involved types themselves (in this case LogFont and TFont) as well as the units at the time the generic itself had been declared.

Thaddy:
I tested my second suggestion and that works. In fact it works on any windows structure, provided unit order is obeyed.

jamie:
I solved the problem for now.

I create a TCLogFont and a member lf:LOGFONT, the rest has the operators in it.


P.S.

 Helpers do not support operators from what I can see and also, operators in the unit interface work but are not seen when specializing the generic.

 So they must live in a record.

Navigation

[0] Message Index

[#] Next page

Go to full version