我听过很多程序员,特别是Delphi程序员嘲笑使用'with'.
我认为它使程序运行得更快(只有一个对父对象的引用),并且如果使用得当,它更容易阅读代码(少于十几行代码并且没有嵌套).
这是一个例子:
procedure TBitmap32.FillRectS(const ARect: TRect; Value: TColor32);
begin
with ARect do FillRectS(Left, Top, Right, Bottom, Value);
end;
Run Code Online (Sandbox Code Playgroud)
我喜欢用with
.我怎么了?