views:

471

answers:

5

Following up on this question, I'm working on a large Delphi 7 codebase which was not written very nicely.

I'm looking at code like this, as a small example:

  if FMode=mdCredit then begin
    Panel8.Caption:='Credit';
    SpeedButton3.Enabled:=false;
    SpeedButton4.Enabled:=false;
    SpeedButton5.Enabled:=false;
    SpeedButton5.Enabled:=false;
    SpeedButton6.Visible:=False;
    SpeedButton10.Visible:=False;
  end;

Followed by another 6 very similar blocks. The whole thing is in this style. So I'm thinking that this would be much easier to read if the controls were named sensibly.

I could just use a global search and replace, but I'll run into problems when multiple forms use the same names, and also I'd have to be careful to change (eg) SpeedButton10 before SpeedButton1.

Is there some plugin which has the ability to perform a "smart" rename for me?

Edit:
Sorry, I should have mentioned this before: I tried both GExperts and Castalia's "Rename Component" feature, but they both seem to be intended for use when adding the component to the form initially.

They don't do a search+replace in the code, or rename existing events (SpeedButtonXClick() -> cmdCreditClick()).

Have I missed something?

A: 

The Rename Symbol refactoring in recent Delphi versions will work across units in a project. Since you say Delphi 7 I guess that's not going to help you, and in the past I've just used TextPad, a great editor that (like many others) will do powerful search/replace across files (with or without confirmation).

HTH

Edit: Craig's right - GExperts will do this, as will Castalia.

Argalatyr
A: 

I think GExperts has a search and replace like this.

Craig
Not as far as I can tell.
Blorgbeard
A: 

Don't know if it can work in your case, but you could try to load your project in a later version of Delphi that has the refactoring capability and use it to change the components names while taking care of all the dependencies. Then you just have to do a diff and see what has been changed.

François
+2  A: 

Not exactly a plug-in, but you can use one of the more recent versions of Delphi and the refactoring feature in there. Maybe you could use the free Turbo Edition . . .

You might try ModelMaker for Delphi 7. It has refactoring support that might work for you.

Jim McKeeth
ModelMaker worked for me.
Blorgbeard
A: 

Why not use Sync Edit? Its part of the IDE (at least in 2006+):

The Sync Edit feature lets you simultaneously edit indentical identifiers in selected code. For example, in a procedure that contains three occurrences of label1, you can edit just the first occurrence and all the other occurrences will change automatically. (copied from the BDS2006 Help)

You will have to rename your components first, but it takes the pain out of most of this. I prefer the GExperts wizard of renaming components as they are added to the form, but as you pointed out, it only works when the component is added to the form, and doesn't reach into the individual usages of the components in code. The reason for the renaming of the components first is that when you select the entire block of code to do the rename, it won't make the appropriate changes in the dfm file...just your locally selected code block.

To use the feature, select your entire implementation block, then press the button in the gutter that has two pencils "linked" by a line...then press tab until you get the first one you want to edit...when you change its name, it will change globally in the rest of your source file. Press ESC when your done.

skamradt
Why not Sync Edit? Because I'm using Delphi 7, not 2006+ :)
Blorgbeard