How to Convert a File--Generate Source

Top  Previous  Next

If a file's definition needs to be changed and meaningful data exists, follow these steps to convert the file. This method creates an executable file that you can ship to end users to convert their data files. If you want to convert a file without creating a file conversion program see How to Convert a File (without generating source) .

The conversion program generated by this method is designed to be compiled and built using the Clarion version 7 and higher.

 

1.

Open (load) the dictionary that contains the file to be modified.

2.

Copy the data file definition to a new name. To copy a file definition, highlight the file to be copied in the DCT Explorer and press CTRL+C, then press CTRL+V to paste it. You will be prompted to supply a new name and prefix. (Example - copy Customer to OldCustomer)

An alternative would be to copy the entire dictionary to a new name. You might use this method if there are multiple files to be converted in one session. Clarion allows files to be converted from one dictionary to another.

3.

After the file definition has been copied, make any necessary changes (add fields, change the file driver type, etc.) to the definition with the original name. In our example above, the Customer file is the file to be modified.

4.

In the DCT Explorer, right click on the CUSTOMER table, and select the following conversion option:

You can specify a source file structure (i.e., OldCustomer) to convert from three different options. The structure to use as the source can be directly on disk (using Data File), a table definition in the current dictionary (using Table Definition), or a table definition in another dictionary (using Table Definition from another DCT).

The table structure that you select first in the DCT Explorer is always the target or output of the conversion program.

If you have Clarion.NET installed, you also have the option of generating a conversion program in standard Clarion# format to generate a conversion program that runs with the .NET Framework.

5.

In the Select a Table dialog, highlight the source table and press the Select button.

6.

The Select New Project File dialog appears. Accept or modify the default name (convert.cwproj), and the desired folder name, and press the Save button.

Project files determine what source file to compile, and how to build (link) it. The default extension of project files is *.cwproj.

When you press the Save button, this will generate all the Clarion source code necessary to take the data in the Source Filename, and copy it into a new Target Filename, using the file format specified by the Target Structure.

7.

The Select Destination Data File dialog appears. Highlight the selected file to convert to and press the Open button.

8.

Another dialog pops up that asks you if you would like to load the data conversion program. Press the Yes button.

The best reason to generate Clarion source code for the data conversion is to provide you the opportunity to modify the code before you compile and execute it to handle any special data conversion needs you may have. This makes the conversion process completely flexible to handle any situation that can occur.

9.

Choose View  Solution Explorer (or press CTRL+ALT+L).

Expand the Convert project node, and highlight the Convert.clw file, then press the Open button in the Solution Explorer toolbar, or you can right-click and select Open from the popup menu, or simply double-click on the file to open it.

Clarion’s Text Editor appears with the file loaded, ready to edit.

10.

Edit the source code as required to make the field assignments.

See Editing Source Code to Make Field Assignments

11.

Press to Make and Run the conversion program.

After the conversion program runs:

12.

Check the file that has just been converted by opening it with the Database Browser.

After viewing the converted file, some clean up steps are all that's left to do:

13.

Delete the "old" file definition from the active dictionary, or archive it into a backup dictionary file.

14.

If the converted file is located in a different directory, you may now copy it into the working program directory. If you renamed the file, you may rename it to the original file name at this time.

The conversion process is now complete. This example created a CONVERT.EXE executable which you may ship to end users to convert their files.