I need to load at runtime a TextList, so I wandered around CmpDynamicText library and saw DynamicTextRegisterFile, DynamicTextUnregisterFile and so on.
Is there an usage example somewhere, or at least someone who has make it work?
Or should I replicate TextList infrastructure in IEC code instead, something like the following pseudocode?
Yes, but what's the right format for the file?
Is it the same as <textlistname>.txt or the one of globaltextlist.txt?
Should I unregister the previous file or not?</textlistname>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot seem to be able to change default texts. They are NOT changed from the default file even if I unregister it. But texts with IDs not present in the default file are imported successfully.
"outputfilename" is '/opt/data/mytl.txt'
It has only "Id;Default" instead of "Id;Default;it;en;de" columns.
LoadCustomFile (does not overrides default texts)
//Currentlanguagesave/restorebecauseontextreloadthelanguagerevertsto""//Evenwithoutit,sointhe""CURRENTLANGUAGEcase,defaulttextsarenotoverriddensize:=SysFile.SysFileGetSize(szFileName:=outputfilename,pResult:=ADR(res));currentLanguage:=VisuElems.CmpDynamicText.DynamicTextGetCurrentLanguage();IFres=CmpErrors.Errors.ERR_OKANDsize>24THEN//Unregisterreturns"1"=GENERICFAIL//andinPLClogappears"Could not unregister dynamic text file"VisuElems.CmpDynamicText.DynamicTextUnRegisterFile(szFile:='/opt/Project/PlcLogic/visu/mytl.txt');VisuElems.CmpDynamicText.DynamicTextRegisterFile(szFile:=outputfilename);VisuElems.CmpDynamicText.DynamicTextLoadDefaultTexts();//DynamicTextReloadTexts()inplaceofDynamicTextLoadDefaultTexts()doesnotworkeitherVisuElems.CmpDynamicText.DynamicTextChangeLanguage(stLanguage:=currentLanguage);VisuGlobals.customTextlist:=TRUE;ELSEVisuGlobals.customTextlist:=FALSE;END_IF
RemoveCustomFile (works and removes default texts that were only in the "override" text list but not in the system one)
VisuGlobals.customTextlist is used to ask for the text with DynamicTextGetDefaultTextW if TRUE (because otherwise one gets the language-specific text) and with DynamicTextGetTextW if FALSE.
Last edit: sgronchi 2022-03-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You'll have to adjust LoadNames.defaultfilename and LoadNames.outputfilename according to your system. I attached the custom "mytl" in the projectarchive.
If you set a breakpoint into LoadNames.LoadCustomFile, you'll see that resUnreg is 1 (generic fail).
To keep it short, I did not implement the logic which asks for default text if LoadNames.xCustom is true, because if unregistering fails it won't work anyway.
I need to load at runtime a TextList, so I wandered around CmpDynamicText library and saw DynamicTextRegisterFile, DynamicTextUnregisterFile and so on.
Is there an usage example somewhere, or at least someone who has make it work?
Or should I replicate TextList infrastructure in IEC code instead, something like the following pseudocode?
Nonetheless, it would be a pity to roll a poor man's version of the already builtin infrastructure.
Last edit: sgronchi 2022-02-25
Hey,
DynamicTextRegisterFile should do the trick I think.
Best regards,
Marcel
Yes, but what's the right format for the file?
Is it the same as <textlistname>.txt or the one of globaltextlist.txt?
Should I unregister the previous file or not?</textlistname>
They use the same file format, they just have additional languages depending on what you added.
Are you using the same file? Then a reload should be enough, no need to unregister and register.
Sorry, I messed up with the import file (not the globaltextlist.txt), the one that has the textlist as the first column.
I'd like to keep the original file if something goes wrong as a fallback solution, unregistering it if the other file is valid.
I cannot seem to be able to change default texts. They are NOT changed from the default file even if I unregister it. But texts with IDs not present in the default file are imported successfully.
"outputfilename" is '/opt/data/mytl.txt'
It has only "Id;Default" instead of "Id;Default;it;en;de" columns.
LoadCustomFile (does not overrides default texts)
RemoveCustomFile (works and removes default texts that were only in the "override" text list but not in the system one)
VisuGlobals.customTextlist is used to ask for the text with DynamicTextGetDefaultTextW if TRUE (because otherwise one gets the language-specific text) and with DynamicTextGetTextW if FALSE.
Last edit: sgronchi 2022-03-04
If it is not possible to understand why unregistering the default file fails, I think it's better to go the build-from-scratch way...
I think it is best to provide a small example project at this point
Hi Marcel,
here you are. Sorry for the delay.
You'll have to adjust LoadNames.defaultfilename and LoadNames.outputfilename according to your system. I attached the custom "mytl" in the projectarchive.
If you set a breakpoint into LoadNames.LoadCustomFile, you'll see that resUnreg is 1 (generic fail).
To keep it short, I did not implement the logic which asks for default text if LoadNames.xCustom is true, because if unregistering fails it won't work anyway.