How to add new columns in an existing dictionary from code

Hello !
Is it possible to modify existing dictionary through code?

It’s not very realistic. You’d have to call ClarionCL to export the dictionary to XML. Then write the code to manipulate the XML to make the changes you want. Finally, re-import back to DCT.
@Mark_Sarson has done some work with the DCTX xml format. Perhaps he has some thoughts to share?

Hi @Mario1 Welcome to the ClarionHub

It is possible, but it’s not so simple.

As @Rick_UpperPark mentioned, I have done some work on this, although my solution can also be a problem because of issues with what Clarion exports from the Dictionary. The problem before I start my response is that Clarion will only export what is “used” in the dictionary. Should you need other features not yet used, then you will go through the same process again.

I used Visual Studio to create a C# class based on the DCTX. There is an option if your clipboard contains XML to paste special, paste classes.

This will create many classes based on the XML in the clipboard, so in this case, will create classes based on the DCTX you add to the clipboard.

You can then use LINQ to parse, add to etc. the XML code, before finally exporting back to DCTX.

I do something like this in the Dictionary Versioniser that can be found here although in this application I am not adding to the DCT, but it is achievable.

I hope this helps a little.

The short answer is yes, the long answer is how do you want to modify the exported TXD file?
You can do this like @Mark_Sarson has done, you can do this using the clarion template language or you could just write your own app and edit the TXD yourself.

Although I’ve done most of my stuff with C6 dct’s as its simpler but I see no reason why it couldnt be done with C7+ dct txd formats.

So its possible to write template code to edit dct’s exported to a TXD, I actually have a procedure extension template which exports the procedure to a TXA file, modifies it and then reimports the modified TXA all from within an app at the click of a template button.

Potentially you could write a Utility template to modify the dct exported a TXD file and then reimport that TXD file back into a dct before the changes can cascade down to all the app files using the dct.

How exactly are you trying to add new columns to the dct?

For example, are you adding local variables to a procedure and want to be able to select one or more local variables to export to the dct and then select the file/table you want these local variables to be added to prom within a procedure extension template?

There’s lots of ways to do this, its just a question of how exactly you want to add these new columns.

Welcome to ClarionHub !

You don’t say what version of Clarion?

Clarion 2 - 6 the only format is TXD.

IIRC in Clarion 8 - 11 it does not import the TXD well or at all, it is best to use the XML format DCTX.

The TXD format is simpler. You could try a quick test to see if it imports. In the IDE export TXD is kind of hidden. You must change File Dialog file type to “All Files” then must type xxxx.TXD

I have often made bulk changes to DCTX in a text editor.

It si do-able, but strongly recomended do not try this. Considering changing some dictionary tables, always ends with error 47, so, changing-adding columns in dictionary is action that you do not use on daily basis…
Regards, Ozren.