Hi all,
I am currently struggling with the following problem:
I have a sub-project (which contains sort of basic functionality) which is used in multiple projects. But sometimes one project needs to change the behavior of one basic function (from the sub-project) without affecting the other projects that use the sub-project.
I am looking for a way to be able to change that behavior only in the project, without changing the function in the sub-project (a sort of overriding).
One way I found is to copy the entire library from the sub-project into the project and change the function, but this makes it difficult to actually follow what was changed.
If I create a ctrl lib with just the changed function in the project, it works only if the changed function does not use other functions from sub-project ctrl lib.
Have you encountered this problem? Do you have any idea how this could be solved?
Thank you,
Corina Bota
Same function in project and sub-project
- kilianvp
- Posts:443
- Joined: Fri Jan 16, 2015 10:29 am
Re: Same function in project and sub-project
You can build a hook function. In your code you then check if the function exists and execute it.
basic function
hook in your project
load the ctl with your hook via LoadCtrlLibs
BR
Kilian von Pflugk
basic function
Code: Select all
if (isFunctionDefined("HOOK_someFunctionName"))
{
HOOK_someFunctionName(parameter);
}
Code: Select all
HOOK_someFunctionName(parameter)
{
}Code: Select all
[ui]
LoadCtrlLibs = "NewFile"
[ctl]
LoadCtrlLibs = "NewFile"Kilian von Pflugk
- gschijndel
- Posts:376
- Joined: Tue Jan 15, 2019 3:12 pm
Re: Same function in project and sub-project
Another way would be a object-oriented programming and create a subclass and only override the single function and use this class in the project.
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: Same function in project and sub-project
Normally on a single machine only one WinCC OA project is started.
Changes in a library in a sub project will only 1 specific project.
How does your setup look like that several projects might be affected?
Best Regards
Leopold Knipp
Senior Support Specialist
Changes in a library in a sub project will only 1 specific project.
How does your setup look like that several projects might be affected?
Best Regards
Leopold Knipp
Senior Support Specialist
- CorinaBota
- Posts:4
- Joined: Wed Jun 17, 2020 9:47 am
Re: Same function in project and sub-project
We have several clients which use different projects, but they all have one common library included in the config file as sub-project.leoknipp wrote: ↑ Fri Nov 19, 2021 1:54 pm Normally on a single machine only one WinCC OA project is started.
Changes in a library in a sub project will only 1 specific project.
How does your setup look like that several projects might be affected?
Best Regards
Leopold Knipp
Senior Support Specialist
For example, client 1 will use a project having in the config file:
[general]
pvss_path = "C:/Siemens/Automation/WinCC_OA/3.18"
proj_path = "D:/some_eaxmple_path/client_1/common_lib"
proj_path = "D:/some_eaxmple_path/client_1/client_1_project"
Another client will use another project with this config file, but using the same common_lib:
[general]
pvss_path = "C:/Siemens/Automation/WinCC_OA/3.18"
proj_path = "D:/some_eaxmple_path/client_2/common_lib"
proj_path = "D:/some_eaxmple_path/client_2/client_2_project"
So the code in common_lib is the same. client_1 and client_2 are two totally different projects; they are run on different machines but they both use common code from common_lib.
common_lib contains some basic functionality but sometimes these need to be slightly changed from project to project, so that we do not duplicate code.
- CorinaBota
- Posts:4
- Joined: Wed Jun 17, 2020 9:47 am
Re: Same function in project and sub-project
Thank you for the ideea, I will try this.kilianvp wrote: ↑ Fri Nov 19, 2021 9:47 am You can build a hook function. In your code you then check if the function exists and execute it.
basic functionhook in your projectCode: Select all
if (isFunctionDefined("HOOK_someFunctionName")) { HOOK_someFunctionName(parameter); }
load the ctl with your hook via LoadCtrlLibsCode: Select all
HOOK_someFunctionName(parameter) { }
BRCode: Select all
[ui] LoadCtrlLibs = "NewFile" [ctl] LoadCtrlLibs = "NewFile"
Kilian von Pflugk