views:

126

answers:

2

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)
  .MyMethod;
end;
A: 

That's a bug and already reported to QC.

Ulrich Gerhardt
This bug prevents using codeformater at all.
Stebi
Not only that bug :-)
Jeroen Pluimers
+1  A: 

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;
moz