In other languages like C++, there are operators to do a plus-equals or or-equals type of operation to add additional styles/flags. Is there an equivalent in Delphi?
Right now I have some code like:
label1.Font.Style := label1.Font.Style + [fsBold];
label2.Font.Style := label2.Font.Style + [fsBold];
But I would love, if it is possible, to get that simplified a bit to something more concise without duplicating the label name on both sides of the assignment operator, something along the lines of: label1.Font.Style += [fsBold];
or label1.Font.Style := self + [fsBold];
Can this be done? Or not so much?
Include is what you're looking for. Unfortunately you run into the problem that Label.Font.Style is a property and must be assigned to and not passed by var. You can do this however:
var
fontStyle: TFontStyles;
begin
fontStyle := Label1.Font.Style;
Include(fontStyle, fsBold);
Label1.Font.Style := fontStyle;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With