Determine where an existing Excel macro is used - excel-2010

Is there any way to determine where in an Excel 2010 workbook a macro is used? I inherited a workbook from a coworker and there are some macros with no comments for which I can't determine where they are used. I'd like to delete them if they are just trial or debug related code that was left behind.

Make a backup of the original file, delete the unwanted macros in the new file, then see if it still works....

Related

Can I stop C++Builder inserting USEFORM macros?

I have a C++Builder (XE6) project containing multiple Vcl forms. Only one of them is listed as auto-create on Project>Options>Forms, I create the rest using new as and when needed.
The problem is that every so often, C++Builder will insert a load of lines like:
USEFORM("TMainForm.cpp", mainForm);
into the file with my WinMain method. It will also occasionally shift around the order of these lines.
This leads to the version control history for that file being mostly full of garbage. So is there a way to prevent it inserting the USEFORM macro?
In a word, NO. You just have to live with it, and delete the macros if you don't want them.
If you are worried about version control issues, see suggestions in this topic:
IDE generated USEFORM macro calls changing their order.

Automate the insertion of breakpoints?

Is it possible to automate the insertion of breakpoints? For example, I need to insert a specific (the same) conditional breakpoint at the beginning and exit of every procedure inside a specific unit. To do this manually would be tedious and time-consuming, so I am looking for an automated way to do this.
No. There's no functionality in the IDE to do so.
Based on your comment to the original question, what you're actually trying to do is detect where a global ("public") variable is being changed. The way to do that is to set a Data Breakpoint, which is tripped when the variable is changed, and then view the callstack to see what code was executing last. (You can find this in the help file by searching on "Breakpoints, setting data breakpoints" in the help index for Delphi 2007, or "Breakpoint Properties, Data Breakpoint" in XE4's help (linked above).
Note that both ask for an address to watch, but work with #VariableName as well. (Using a stack (local) variable triggers a dialog that tells you that doing so can make your app unstable and asking you to confirm you want to do so.)
As #DavidHeffernan points out in a comment, a better solution is to make the public field a property with a setter, and then set a normal breakpoint inside that setter.
Breakpoints are stored in the similar named section of the projects DSK file. Set one breakpoint manually in the IDE to find out the correct settings. Then copy and adjust this breakpoint in the DSK file to your needs.
This doesn't solve the problem to find out the correct line numbers though.
Yes *)
A breakpoint can be inserted with assembler code (see How to simulate a Delphi breakpoint in code?):
asm int 3 end;
Automated insertion (and removal) of this code in the places where you need the breakpoint is a trivial task, as tools which perform source code instrumentation (e.g. profilers for Delphi and other languages) show.
I do not say that it is easy, but possible.
*) if you are a programmer ;-)

Removing Delphi IFDEf compiler directives automatically

I am currently working with 'inherited' code that has (scattered randomly throughout) a whole bunch of conditional compiler directives based on the version of Delphi, going back to Delphi 2 . From now on, all development will be with Delphi 2009 or future. Is there a tool in Delphi 2009 , or a plugin, that will automatically remove compiler conditional code segments based on a specified 'minimum' version?
I highly recommend the Delphi Inspiration Pascal Preprocessor (DIPP)
This can do a number of things with a source file in addition to removing conditional defines, including the "inlining" of include files and removing comments (all of course highly configurable and controllable by options supplied to the processor).
The conditional defines functionality is especially useful as you can either have all such conditionals simply removed or provide a set of DEFINE's that you wish to apply. DIPP will then emit a source file that reflects how it would appear to the compiler with those symbols DEFINED, but without the conditional directives themselves.
So in your case you would simply defined the symbols appropriate to your "baseline" Delphi version.
You should give JEDI PreProcessor (Pascal PreProcessor) in the JCL a try.
In the trunk in our SVN the source can be found in the dir jcl/devtools/jpp and in our latest release (2.1) zip-file the jpp.exe can be found in the dir devtools.
I don't know of such a tool but it should be relatively straight-forward to write it.
Loop through all files in the directory using FindFirst and FindNext
Use TStringList.LoadFromFile to read all pas files.
Loop through the strings and look for {$IfDef} directives. If the version specified in the conditional section is older than D2009 remove all text until the {$EndIf}.
Use TStringList.SaveToFile to write the modified file to disk.
My advice would be to ONLY change code you completely manage. If however you are also going to modify existing 3rd party code, then I suggest you go through each IFDEF defined for validation. Some vendors do not use the standard IFDEF VERxxx calls, but create their own which might be called something like VER70UP or such. The most common place for this would be in include files, so look for a {$I ???.INC} file near the beginning of each file, then analyze this for what is being used and how.
The other reason to analyze each $DEFINE/$UNDEF is the fact that a version specific one might turn on a new define that your previously not checking...one that ultimately leads into dead code.
Use GExperts, you can use both GrepSearch or GrepRegularExpressions to search in your code and then use the Replace tool in the GrepResults to remove whatever you need.
You can do a search and replace
operation on all of the matches in the
list or only the selected file/match.
When you choose one of those options,
a dialog appears prompting for the
string to use in place of the matched
text. Note that forms that are
currently open can not have their text
replaced, due to limitations in the
IDE. Please close all forms before
trying to replace text in them.

In Delphi ".pas" and ".dpr" files should not be removed?

Is there a rule of thumb that .pas, .dfm and .dpr files should not be removed?
While opening/working with concerned project files ,Unit1.pas,Form1,Unit1.dpr etc are automatically created by the IDE in the same project-folder.As they were not related to my proj,I inadvertently deleted them.Will that cause any issue?
Further should the same project be saved with a new name every time one saves it?
Like PfojDel.dpr
edit then save as PfojDel1.dpr
edit then save as PfojDel2.dpr etc
Kindly help
Thanks and Regards
Vas
Your first question's pretty straightforward. Any file that you need to compile into your project needs to be present on the disc. Anything else can go.
As for changing your project file name, that's a big hassle. Sounds like you're trying to keep a history of your changes. If so, I'd look into version control if I were you. TortoiseSVN makes it pretty easy to create a simple source code repository, either on your own hard drive or a networked system, that you can check changes into to keep a history.
See http://delphi.about.com/od/beginners/a/aa032800a.htm for an explanation on all most file extensions you come across when developing a Delphi application.
The dfm file contains the component information for the form (or data module). The dpr is the basic pascal program file. It is also the base of the project (normally contains the list of files in the project).
Deleting them is not a disaster, but you need some time to recreate them (specially if the form is big). But if you have the choice, do not delete them.
The dfm files are created because they contain the information you provide with the form designer (position of controls and the value of their published properties).
If you have renamed your project, you can delete the other files without problem. This is also true for units that are not used anymore.
You don't have to use a different name every time you save the project. If you want to keep track of changes, use source control. (Every wise programmer should use source control and backup the files frequently).
Under normal circumstances you shouldn't have any Unit1/Form1 files on your system. The first time you save/compile/run a project with a new file the IDE will prompt you for the filename and location.
If you have a file named Unit1/Form1 then it would indicate that you have a unit or form which hasn't been given a name, but it may still be used as part of your project. If it is used as part of your project then it is not safe to delete it. The only way to know if is used is to go through each of the uses clauses in your project, or to use an automated tool to do this for you.

"Rename control" in Delphi 7?

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.

Resources