如题,Label1.Font.Style可以直接赋值,比如:
Label1.Font.Style:=[fsBold];如果Include(Label1.Font.Style,fsBold);编译通不过,报:
[Pascal Error] E2064 Left side cannot be assigned to如果定义一个变量
var
 FS: TFontStyles;
然后
Include(FS,fsBold);这样又是可以的?这是怎么回事呢?

解决方案 »

  1.   

    var类型 就要求能够取指针传递过去,我看Label1.Font.Style的值是这样的: property Style: TFontStyles read GetStyle write SetStyle;procedure TFont.SetStyle(const Value: TFontStyles);
    var
      FontData: TFontData;
    begin
      GetData(FontData);
      FontData.Style := Value;
      SetData(FontData);
    end;procedure TFont.GetData(var FontData: TFontData);
    begin
      FontData := FResource^.Font;
      FontData.Handle := 0;
    end;function TFont.GetStyle: TFontStyles;
    begin
      Result := FResource^.Font.Style;
    end;
    请分析分析。
      

  2.   

    Delphi syntax:procedure Include(var S: set of T; I:T);DescriptionIn Delphi code, Include adds the element I to the set S. The expression Include(S,I) corresponds to S := S + [I] but the Include procedure generates more efficient code.S is a set type variable, and I is an expression of a type compatible with the base type of S. 不需要去看它的实现细节,这是它的语法已经规定了。要使用这个函数就必须符合它的语法,要不就自己重写一个.