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?
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.
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.
I think GExperts has a search and replace like this.
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.
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.
Related
Just upgraded from Delphi XE to Tokyo, and was hoping for some updated IDE features.
One nice to have feature would be automatically providing options to add a unit to the uses clause. For example, if you reference something in code that isn't in a uses, it would be nice if the IDE prompted you to add the related unit(s).
For example, keeping it simple, in IntelliJ, you might declare a Button, but not yet have added the associated Library to the Import clause.
When this happens, the offending line is highlighted (just like in Delphi), but the IDE will let you add the necessary library with an Alt-Enter. If there are multiple libraries (it knows about it) it will prompt you for the one you want.
Anything like this for Delphi?
Delphi 2007 and later versions support this for most types that it knows about (in the search or library path). (It may have been available in D2005/2006; I don't have them installed anywhere now to check. I know it was not in Delphi 7.)
Put in the type, and use the Refactor menu (Refactor->Find Unit) or press Ctrl+Shift+A.
Here's an example:
It's not 100% effective, but it's a vast improvement over the old way.
(And yes, I know about TArray<string>, before someone chimes in. I just grabbed a quick type that I knew wouldn't be in the default VCL form uses clause for an example.)
I have in a old project, standard menus on my forms. The menu items are populated by TActions that I have made using the TActionManager.
I am updating this old project and would now like to change the appearance of my menu to XP Style as set by the TActionManager, so it can match the TToolBars on my forms which have changed to dsGradient.
Is there a non lazy way of making this transformation?
Otherwise it means I have to manually go through my forms, remove the TMainMenus, drop a TActionMainMenuBar on the form and then begin creating the TActionBars to populate the menus again, which I will be honest with you right now I don't feel like spending so much time doing this.
So if there is a way to automate the conversion somehow I would be interested to know, then I don't have to spend so much time manually changing them.
Equally, if the above can be done without manually making the changes, I would be interested to see if it is possible to reverse convert, eg TActionBar menu to TMainMenu?
If I must do it manually then so be it, but if there is a quicker better option then I really would like to know.
I strongly suggest you to study the following converter utilities by ChoosPill :
TB2KImpTb97
TB2KImport
They are distributed in source code and support the import of all relevant items and properties from stock VCL components TMainMenu, TPopupMenu, TMenuItem and TToolBar to Jordan Russel's famous Toolbar97/Toolbar2000 components respectfully.
You can also consider to take a glimpse at TBXLib converter source code .
You can also consider delving into TdxBarConverter's source code if you are a DevExpress registred user.
They can serve as a good starting point for you.
Some people are saying that I must update the controls in Win3.1 palette (especially TFilterComboBox) with modern ones. But does Delphi provide such new controls?
I need to create a GUI (somehow similar to Windows Explorer, consisting in a DirectoryListBox, FileListBox and a FilterComboBox) where I allow the user to easily explore for files of a specific type. Since the interface is centered around this Explorer, a TOpenDialog will be like hitting the customer with a hammer in the middle of his head. I need an 'easy to use' solution.
Unfortunately Shell Controls are not stable enough to be used as replacement.
The Shell Controls that come as a demo with Delphi only have to be installed, and you'll have some nice shell controls. There is, IMO, no big need to get 3rd party components for that.
Look for ShellCtls (or similar, can't check right now) in your demos folder. That Demos folder can be accessed from the Windows Start menu for your version of Delphi.
Update
They are not in a Demos folder, it is called Samples now. They can be found in Samples\Delphi\VCL\ShellControls. Install vclshlctrls.dproj first and then dclshlctrls.dproj.
In our application we use tpShellShock which works rather well. You may need to tweak it a little for Unicode Delphi, but if I recall correctly that was pretty simple to do.
Here's what it looks like:
In Delphi 2010 a new Find bar has been added beneath the source editor.
Though I sounds like a good idea I find it prettry anoying when F3 should be pressed multiple times for finding next matches. It works from time to time for me.
How I can switch it off and use the old search fnctionality?
It is not possible to switch back to the old modal behavior. That code is gone. If you’d like to see all the results in a list, you can use “Find in Files” and choose either “open files” or “files in project” to keep the number of files being searched to a minimum
Depending on how reliant you are on the latest versions of the VCL components, you may be able to run a slightly older version of the IDE as your editor, and use command-line compilation to compile your code using Delphi 2010. I have in the past mixed and matched IDEs in this way, but admittedly this is more difficult if your software is component-heavy, so to speak.
Edit: Moved my comment.
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?
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.
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.
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.