This article was brought to you by the guys from VDF-GUIdance.
For more DataFlex targeted articles see http://www.vdf-guidance.com


Generate DataFlex source for ActiveX controls via Command Line

by Wil van Antwerpen

Summary

This is a small program that you can use to generate DataFlex source from the command line for the activex controls that you have. This is especially useful if you develop activex controls.
Size: 2 KB Download
Date Created: 05/04/2016
Date Updated: 05/04/2016
Author: Wil van Antwerpen
Company: Antwise Solutions


Created: 2016-04-05

The problem


if you happen to be one of those persons that develops ActiveX controls and consume those from within DataFlex then you probably recognize the following work flow.

  • Shut down DataFlex Studio
  • build your activex control
  • Start DataFlex Studio
  • Go to menu File -> New -> Select "Class" -> "Import COM ActiveX" control
  • Use the scroll bar in the list that displays all ActiveX controls
  • Hit generate.

What's wrong with that you might wonder?

Well.. if you forget to close the DataFlex Studio then new changes made to your control are -for whatever reason- missed. Yep, you'll end up wondering why it didn't see the change.

Next locating your control in that List isn't exactly easy as they tend to be very long and there's no search function built into it.

The command line version



So what did I do?

The way that the Studio generates the source for your ActiveX controls is actually done via .... wait for it .... Com Automation.

You can find it in your list of Com Automation controls in the Studio.
It is called "DataFlex COM Class Generator" and is supplied to you via the comclsgen.dll in your DataFlex Studio bin folder. You have to generate the DataFlex source of that automation control yourself.

The reason is that this class generator is VERSION specific. So you should only generate classes for the same DataFlex version.

With that generated ComClsGen.pkg file in hand you can then compile the command line version of the program I attached to this post.

You use the program like follows:
  ComCLSGenCLI.exe MyControl.ocx "C:\DataFlex Projects\Demo Application\AppSrc\cComMyControl.pkg"


As a result you can now trigger generating the new DataFlex package source in your building events from the tools that you build the ActiveX in.

Download



COMClsGenCLI-20160405.zip

FAQ



Q. I tried to compile the tool, but I am missing the package ComClsGen.pkg so cannot compile.

A. Correct, the Com Class generator is a DataFlex version specific control, so I cannot supply the package. You have to generate it yourself.
For that go to
  • File New -> "Class" -> Import Com Automation.
  • Now scroll down the list until you see: "DataFlex Com Class Generator ver ()". There might be multiple versions available.
  • Select the version that matches comclsgen.dll in the runtime folder of the DataFlex version that you want to generate source for.
  • Click OK to Generate the source

Q. My com control generates multiple classes. Something goes wrong with the naming of some of those classes.

A. Yes, that's a known issue. So far I really only needed to generate 1 class and have not added the code to handle multiple classes. Quick testing however showed that it sometimes actually works fine.
If not then look at the line:
            // If you have more as one class in here you want to adjust it!
            Move (sClassPrefix+sClassNames) to sClassNames

Check what is in the sClassNames variable and adjust the values to your needs.

Q. I developed a COM Automation control and it doesn't work?

A. Note that this tool was built for ActiveX controls, not automation controls.
And as it was made very quickly for my own use, it is not as extensive as it could have been.
So at the moment it only enumerates the list of controls that you would see in the Studio under "Import COM ActiveX" not "Import COM Automation".

It is easy enough to change though.
Just change the line:
       Move OLELibTypeControl to ControlType


into:
       Move OLELibTypeAutomation to ControlType

and it should work for automation controls.

Forum



Relevant threads at the forum are:

http://support.dataaccess.com/Forums/showthread.php?57440-Fully-automated-COM-class-generation

and

http://support.dataaccess.com/Forums/showthread.php?58642-Generate-DataFlex-source-for-ActiveX-control-via-Command-Line