Wrong behaviour/Bug in delphi2010 "extract method"

Im facing this issue when i try to extract a methode in the if statement. i couldnt find any reported bug on it.

procedure TForm1.BitBtn3Click(Sender: TObject);
var
  x: integer;
  b: boolean;
begin
  if true then
    x := 8    //********************** i try to extract this line
  else
    x := 6;

  showmessage(inttostr(x));
end;

the result i get is:

procedure TForm1.BitBtn3Click(Sender: TObject);
var
  x: integer;
  b: boolean;
begin
  if true then
    newMethode
  else
    x := 6;

  showmessage(inttostr(x));
end;

and the new Methode is:

procedure TForm1.newMethode;
var
  x: Integer;
begin
  x := 8;
end;

Can anybody check how is the behaviour on Delphi XE? anybody knows if it was reported?


This is a bug in the "Extract Method" refactoring.

As an alternative, you might want to use the "Extract Method" refactoring from ModelMaker Code Explorer refactoring tool. At EUR 99, it is a relatively cheap tool that works from Delphi 5 onward, and the recent 9.0.5 updates have vastly improved their Extract Method refactoring so much that I haven't used the Delphi built-in one for quite a while.

Two great benefits:

  • it launches the method-editor dialog where you can change and reorder parameters, which are then reflected in the extracted and calling code
  • it leaves the original code in a (* *) comment just in case something fails, or you need to reference it
  • In addition, it places bookmarks (numbered 7, 8 and 9) in the code for easy navigation between the extracted code and the call site.

    Highly recommended.


    您可以在Oracle博客条目中找到有关提取方法的答案

    链接地址: http://www.djcxy.com/p/53914.html

    上一篇: 需要一些TinyMCE jQuery的帮助

    下一篇: 错误行为/ delphi2010中的错误“提取方法”