views:

218

answers:

3

I need to switch every control of a particular type on a form to a different type while maintaining the name and the code associated with each control.

For example, let's say I need to switch a dozen or more TEdit fields to TSpinEdits. How can I do that in Delphi 2007 with minimal effort?

+13  A: 

Use the GExperts Replace Components expert. It's free, and is the only tool I've seen that does what you're asking, including mapping properties from the old component to the new one.

Craig Stuntz
Very nice. I have used this and @Jozz below's technique. I would hope that under the surface, it's not so much mapping properties as doing its own search-replace for TComponentNameA and replacing it with TComponentNameB in both the DFM and the PAS files.
Warren P
+8  A: 

If you don't feel like using any external tools, you could always try switching to view the form as text, then search and replace TEdit to TSpinEdit. When you switch back and save the form, the IDE should tell you that the declarations in the .pas file are incorrect and offer to correct them automatically. Property mappings shouldn't be a problem unless there are properties that are named differently that you want to map from one class to the other. Properties that don't exist on the new class will be deleted. This is how it works in Delphi 7 anyway...

If you're not happy with the results, you might try GExperts as recommended by Craig, which are a great addition to the IDE for many reasons.

Jozz
"Properties that don't exist on the new class will be deleted." When/if you subsequently open the form in the IDE (after the rename), that is. If you don't do this, you will get an error at run time.
Craig Stuntz
A: 

I use the CNTools component replacer (couldn't find the one in GExperts), it's got a good Component Selector feature too so you can select multiple controls based one some simple queries.

Peter Turner