+1 800 256 3608 (toll-free in North America) or +49 7531 90 60 10| service@combit.com

Programmatically add a project include

Is it possible to add a project include from code to a new project? If so, can anyone provide some example code? We are using Progress OpenEdge, but other language examples would also be welcome.

You can use the object model to do this. In C#, a code snippet would read

// Create new DOM project, type LlProject.List
using (ProjectList proj = new ProjectList(LL))
{
    proj.Open(Path.Combine(Application.StartupPath, "dynamic.lst"), LlDomFileMode.Create, LlDomAccessMode.ReadWrite);
    var template = proj.ProjectTemplates.AddNew();
    // file name needs to be a proper formula, thus the awkward escaping
    template.FileName = "\"MyNewTemplate.lst\"";
}

On the API side, this results in:

▪;1000;21.06.2019 13:49:01.108;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; >LlDomGetProject(1,0039E4B0)
▪;1000;21.06.2019 13:49:01.108;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; <LlDomGetProject() -> 0 (00000000)
▪;1000;21.06.2019 13:49:01.109;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; >LlDomGetObject(0D434844,'ProjectTemplates',0039E4C4)
▪;1000;21.06.2019 13:49:01.109;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; <LlDomGetObject() -> 0 (00000000) ['0D434D08']
▪;1000;21.06.2019 13:49:01.110;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; >LlDomCreateSubobject(0D434D08,0,'',0039E4B0)
▪;1000;21.06.2019 13:49:01.110;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; <LlDomCreateSubobject() -> 0 (00000000) ['1D7C9780']
▪;1000;21.06.2019 13:49:01.110;2;LL.DOM;DE8;100:2=CMLL24♦101:1=1; >LlDomSetProperty(1D7C9780,'FileName','"MyNewTemplate.lst"')
▪;1000;21.06.2019 13:49:01.111;2;LL.DOM;DE8;100:2=CMLL24♦101:1=0; <LlDomSetProperty() -> 0 (00000000)

Hi Jochen, thanks for your suggestion. Tried this, but it only seems to be possible on an existing project. So I am creating an (empty?) project and add the template. Is there also a way to do this otherwise? I would like to have the user enter the project file using the standard list and label “new” dialog and then add the template while the project is “newed”.
If that’s not possible then creating the project first is the only option. In which case I would like to detect whether the user has made changes to the project - if not, then I could delete the “empty” project (assuming this was in fact a cancel action). Is there a way to detect this?

Hi Jos :slight_smile:.

You could still use our standard file dialog by calling into LL.Core.LlSelectFileDlgTitleEx(). This is the direct wrapper for the native file dialog. Note the hidden LlProject.FileAlsoNew member for the LlProject enum, thus pass something like LlProject.List | LlProject.FileAlsoNew to allow the creation of a new file.

With the file name received this way, you could create a new file at the required path via DOM, add the template (or add this file as template, not exactly sure what your workflow should be) and then open the Designer or Print, this time suppressing the file dialog by setting AutoShowSelectFile to false on the component. Would that help?

Jochem, your solution still creates the file on disk, so I would still need a mechanism to detect if the user has actually done something against this “temporary” file. If not, I would like to delete the file as - logically speaking - the user decided not to save the new report. So how can I detect that?

You could try and check the OnSaveFilename event which is triggered whenever the user saves a file in the Designer.

I tried that but the problem is that I want to detect that the user didn’t save the file.

Wouldn’t that just be “my event handler never got called”? So - simply set a boolean member to false initially, to true in the handler and check if it still is false when the Designer returns?

No, it did get called. The boolean won’t help as I discovered that calling Design() immediately triggers the event handler. So I used a counter and increment that in OnSaveFilename. If the value is 1 when returning from Design() then save was never pressed.

The EventArgs have a member SavedInDesigner that allows to check if the event was really triggered by interactively saving. That should work even better than a counter. I’ll set this thread to “solved” anyway then. Enjoy the summer - we’ll hit 35° centigrade today with 39° expected tomorrow :sunny:.

Thanks, that works better indeed.

1 Like

Btw: I noticed that ~LST and LSV files get created in the folder where the LST file is when running Design(). This is regardless of the settings for LlSetPrinterDefaultsDir and LlPreviewSetTempPath

The former is a backup of the file created when entering the designer and can be suppressed by setting LL_OPTION_PROJECTBACKUP (constant value 115) to 0. The latter is a small sketch preview that may also be suppressed if you don’t need it by setting or creating the text value HKCU\Software\combit\cmbtll\<YourAppName>\CompatDrawSketch to F currently cannot be suppressed but safely deleted as well.