开发者

Delphi 2010 Code Formatter: "(MyVar as TMyType).MyMethod" is split in two lines

开发者 https://www.devze.com 2022-12-30 00:46 出处:网络
How to prevent the code formatter from doing this? It seems that it moves casts with \"as\" always a line up. Is this a bug, or is there any setting in the formatter?

How to prevent the code formatter from doing this? It seems that it moves casts with "as" always a line up. Is this a bug, or is there any setting in the formatter?

// Before formatting:
procedure TMyFrame.WidthEditChange(Sender: TObject);
begin
  (Properties as TMyProperties).Width := (Sender as TJvSpinEdit).AsInteger;
end;


// After formatting:
procedure TMyFrame.WidthEditChange(Sender: TObject);
begin (Properties as TMyProperties) // <----- I want this untouched
  .Width := (Sender as TJvSpinEdit).AsInteger;
end;

It gets weird:

// Before formatting:
procedure TMyFrame.WidthEditChange(Sender: TObject);
begin
  (Properties as TMyProperties).Width := (Sender as TJvSpinEdit).AsInteger;
  (Properties as TMyProperties).MyMethod;
end;

// After formatting:
procedure TMyFrame.WidthEditChange(Sender: TObject);
begin (Properties as TMyProperties)
  .Width := (Sender as TJvSpinEdit).AsInteger; (Properties as TMyProperties)
 开发者_如何学Go .MyMethod;
end;


one work-around is a comment on the end of the line:

   if Assigned(aDBControl) then //
   (aDBControl as TcxDBLookupComboBox)
      .Properties.ListSource := aDataSource;

It's not ideal, the indent on the next line is wrong, but it's better than waiting to see if update 2 fixes it.

edit: a hard cast wrapping the safe cast works slightly better.

   if Assigned(aDBControl) then
  TcxDBLookupComboBox(aDBControl as TcxDBLookupComboBox)
    .Properties.ListSource := aDataSource;


That's a bug and already reported to QC.

0

精彩评论

暂无评论...
验证码 换一张
取 消