KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Code Refactoring of Changed Table and Field Names
PRODUCT: 4D Developer | VERSION: 11 | PLATFORM: Mac & Win
Published On: May 14, 2008
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Renaming a table or a table's fields automatically refactors the various method code to reflect the name change. However, if a method is simultaneously open while making the change, either in the preview pane of Explorer or a method editor window, the renaming may not appear to update in the code being displayed.

In 4D Version 2004, the open code indeed is not refactored, and you have to update it by hand. But in 4D V11 SQL, the code is refactored; the open view of the code simply has not been refreshed. To see this firsthand:

Rename a table or one of its fields: Click twice, to select for editing (slowly--do not double-click), on the name of the desired table or field in the Structure editor or in the Tables section of Explorer, and enter the changed name.

If you have a method which references that table or field open in a method editor window, or the preview pane of the Explorer, it is probably still showing the old name of the table or field. In fact, if you click on some of its code, it may turn red, indicating that the name change has not refactored to the code and is in an error state. To get the code to refresh and reflect the table name refactoring:

Close the method editor window if it is open. The code being viewed here will not refresh--a new window must be opened.

If Explorer is showing the code in the preview pane, it probably has not refreshed yet. To reload it, either click on the method name in the left pane, click to view something else in Explorer and come back to the method, or simply click on the "Explorer" toolbar button.

Now the method code in the preview pane reflects the renaming, and you can reopen it in a code editor window and see the refactored code there too.

NOTE EXCEPTION: If you hit the "Enter" key of your keyboard's numpad while in the method editor, the refactoring will not work. As per tech tip # 49061, the numpad enter key invokes tokenizing and syntax checking on the method, which locks in the visible object names in the code. If this happens, you will indeed have to recode the table or field name by hand to match the change.