Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Delphi's equivalent to "+=" for adding elements to a set?

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?

like image 262
Jessica Brown Avatar asked Jul 21 '12 18:07

Jessica Brown


1 Answers

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;
like image 178
gordy Avatar answered Oct 17 '22 09:10

gordy