Page 1 of 1
Code optimization
Posted: 27 Mar 2014 9:43
by Tonton Luc
Hi,
How to optimize this following code ?
Code: Select all
constants
% contenu_visible = b_true.
contenu_visible = b_false.
clauses
start():-
if contenu_visible = b_true then
Win = getVpiWindow() % here is TaskWindow\frm1.pro(52,15)
else
Win = applicationWindow::get():getVpiWindow()
end if,
Container = activeXContainer::new(Win),
...
TaskWindow\frm1.pro(52,15) warning c651: Unreachable or excessive code (removed by the optimization)
Posted: 27 Mar 2014 10:17
by George
constants
% contenu_visible = b_true.
contenu_visible = b_false.
clauses
start():-
if contenu_visible = b_true then
Win = getVpiWindow() % here is TaskWindow\frm1.pro(52,15)
else
Win = applicationWindow::get():getVpiWindow()
end if,
Container = activeXContainer::new(Win),
First of all,
You have used the constants value
Code: Select all
constants
contenu_visible = b_false.
You can't change a constant value anywhere in the code - It is the one time initialization
The value for the constant variable is " b_false" - So, It always move to else loop - As a result, there is no use of "contenu_visible = b_true" condition which always fail..
Now see your code :
Code: Select all
clauses
start():-
%No use of If clause - it will always fail and move to else loop
%Because you are using the constant variable that never change during run time
if contenu_visible = b_true then
Win = getVpiWindow() % here is TaskWindow\frm1.pro(52,15)
else
Win = applicationWindow::get():getVpiWindow()
end if,
Container = activeXContainer::new(Win)
If you want to make the contenu_visible variable to change during run time, you may use,
fact variable or properties and make use that for the if loop comparison
example
Code: Select all
facts
contenu_visible : boolean := true.
Ex:
Posted: 27 Mar 2014 10:40
by Tonton Luc
Hi,
Tks for your help.
I've changing my code as follow and now, any warning message at compile time :
Code: Select all
constants
% contenu_visible = b_true.
contenu_visible = b_false.
predicates
get_win:()-> vpiDomains::windowHandle procedure().
#if contenu_visible = b_true #then
clauses
get_win() = getVpiWindow().
#else
clauses
get_win() = applicationWindow::get():getVpiWindow().
#endif
clauses
start():-
Win = get_win(),
Container = activeXContainer::new(Win),
...
Posted: 27 Mar 2014 11:06
by George
You are trying through conditional compilation
Code: Select all
#if contenu_visible = b_true #then
clauses
get_win() = getVpiWindow().
#else
clauses
get_win() = applicationWindow::get():getVpiWindow().
#endif
Code: Select all
constants
% contenu_visible = b_true.
contenu_visible = b_false.
Since you have used conditional compilation, application never compile the "contenu_visible = b_true" block until you manually going to change the constant value
According to your coding, application always compile the else block and again, no use of "If block" -
And it will not give you any compilation error.
If you have true intention of two different branches in your project where user need to change the constant value - then use conditional compilation
: Else, go for the fact variable or properties and do the run time dynamic changes
Posted: 27 Mar 2014 11:20
by Tonton Luc
Hi,
The user never need to change the constant value => only me, sometime I need to change it manually before to compile my project.
Posted: 27 Mar 2014 11:27
by George
It upto your call,
Depends upon the requirement, you can setup the constants value and build the new setup - The final setup will use only the last modified constant value -
If you need to change the value, every time you have to do it manually which is really not good..
So, play with that depends upon the requirements..