Author Topic: Change function/variable name in code files  (Read 300 times)

Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 20
Change function/variable name in code files
« on: July 14, 2018, 03:53:21 AM »
How do you guys handle changing a function name or a variable name?  For example if I have a type that's called TTextBox that has a function TCreateTextBox and I want to rename that function to TCreateChildTextBox, I have no idea where I'm calling it in the code to rename it everywhere and even worse, there are other types having a function with the same name, so a basic replace all does not work. Is there a simple procedure or just try to build and fix the resulting errors?

I am using blide, maybe it has a shortcut to handle that?

Offline Scaremonger

  • Jr. Member
  • **
  • Posts: 68
    • ITSpeedway - Ramblings of a geek!
Re: Change function/variable name in code files
« Reply #1 on: July 14, 2018, 01:30:07 PM »
Hi,
I would usually open the offending file and anything I know that is using it in Notepad++ and use a simple search to locate potential matches. I would only press replace when I know that it is the correct one and not calls to the other type.

Notepad++ has a regex search option too, which might help to identify the correct ones to replace.

Or maybe you could rename your function/method and replace the old name with a dummy function containing a simple "debugstop": Run your code and every time it stops, follow it back to the call and update your code. Once you've got all the calls, you can remove the dummy function. An alternative to this might be to put an "assert" in your dummy function which will cause a runtime error and you can trace the error from there.

Otherwise you may need to just change the function in your type and as you suggested and let the compiler find the mismatches for you.
Follow me at ITSpeedway.net.

Offline Ashmoor

  • Jr. Member
  • **
  • Posts: 20
Re: Change function/variable name in code files
« Reply #2 on: July 15, 2018, 04:05:06 AM »
Thanks, the dummy function idea is great! I didn't think about opening bmax files in notepad++ but it makes perfect sense with the high quality find/replace tools there.