Log In    |    Knowledge Base    |    4D Home
Tech Tip: How can I install my 4D 2003 component in a 4D 2004 database?
PRODUCT: 4D Insider | VERSION: 2004 | PLATFORM: Mac & Win
Published On: November 29, 2006

So you developed a great component in 4D 2003 but lost the source database in a hard drive crash. You still have some databases with the component installed but now have no way to generate a new component. What can you do to get the component code into a new database?

Unfortunately there is no way to "upgrade" a component without the source database that it was created from. However there are many techniques that can be used to get the public methods out of the component and into a new/different database. This Tech Tip is not all inclusive of the solutions that are available but if you are comfortable with parsing text files and, as a bonus, good with regular expressions you may find the technique presented in this Tech Tip useful.

You can, of course, export each method from the 2003 database with 4th Dimension, one at a time, until all of the desired methods have been exported. But would it not be better to do it in a batch? 4D Insider and 4D Pack are quite handy in this situation.

The simplified scenario is:

  1. Export the methods with 4D Insider.
  2. (optional) Scrub the exported file for unnecessary information.
  3. Parse the exported file for method names and method bodies with 4D.
  4. Generate new methods with the 4D Pack plug-in.

PLEASE NOTE: Please do not use this technique to steal copyrighted code. If the component is not your own, check with the developer to make sure they are okay with this.

The first step, exporting the code with 4D Insider, is already well documented. Check the 4D Insider documentation for more information on how to use 4D Insider's export feature. The result should be a text file containing the method bodies of your component's public methods (with some other extraneous information).

Once the methods have been exported to a text file you may want to clean this text file up. This is where knowledge of regular expressions comes in handy as you can use any number of string processing tools to scrub unwanted information out of the file. At the minimum you will need to choose a delimiter to know where one method ends and the next method begins before moving on to the final steps. You can, of course, make this clean-up part of your 4D code as well (but will need a plug-in to use regex in 4D).

The second to last step is to parse the exported file for the method names and bodies. The design of the parsing algorithm is left to the developer as it will depend on the structure chosen for the file to import.

The final step, creating the new methods in 4D, is easy with the "AP Create method" command from the 4D Pack plug-in. Once you have parsed the method bodies and method names you need only call this command in a loop to create your new methods (passing in the relevant parameters). Note that the method body needs to be a BLOB.

Of course this technique does not apply only to moving component code. It can be extended, in a much more general sense, to exporting and importing any 4D code. The combination of 4D Insider's export feature and the ability to programmatically create methods with 4D Pack can prove a powerful combination.