QC43219: Renaming components using refactoring can break code

QC43219: Renaming components using refactoring can break code

Post by Arthur Hoo » Tue, 27 Mar 2007 16:26:46


When you re-name a component (such as Button1) using refactoring, the
refactorer also re-names the event handlers.

For example, if you rename "Button1" to "Startbutton", the event handler
"Button1click" becomes "Startbuttonclick" automatically. The problem: if
your code calls "Button1click" directly, this call is not taken into
account in the refactoring process and your code will be broken.


NOTICE: If you check "view references before refactoring" the renaming
of event handlers is NOT shown !!!!!!!

-------------------------------------------------------


Steps to reproduce:

- Create a new VCL application

- On the form, drop a tlabel, a tbutton and a ttimer

- Implement the following event handler for button1.onclick:


procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.caption:='Test';
end;


- Implement the following event handler for timer1.ontimer:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Button1click(Nil);
end;


Now re-name button1 to "Startbutton" using refactoring. The refactored
code for the
event handlers now looks like this:

procedure TForm1.StartButtonClick(Sender: TObject);
begin
Label1.caption:='Test';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Button1click(Nil);
end;


Your code will no longer compile correctly.







--
Arthur Hoornweg

(In order to reply per e-mail, please just remove the ".net"
from my e-mail address. Leave the rest of the address intact
including the "antispam" part. I had to take this measure to
counteract unsollicited mail.)