Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Non local variable access in cb function
Topic Summary: Problem occurs only in included file
Created On: 29-Nov-2005 10:25
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 29-Nov-2005 10:25
User is offline View Users Profile Print this message


Oliver Röpke

Posts: 42
Joined: 23-Nov-2005

Hello @ all,

I've got the following problem:
If I place a kind of list dialog into the the main file everything works fine. (see Main.dxl)

But if I place the list dialog into an inc file, e.g. for re-use reasons, the DXL engine reports the following errors:
-E- DXL: <SingleSelectListDlg.dxl:21> non local variable access (selection)
-E- DXL: <SingleSelectListDlg.dxl:21> non local variable access (str_array)
-E- DXL: <SingleSelectListDlg.dxl:22> non local variable access (selection)
-E- DXL: <SingleSelectListDlg.dxl:25> non local variable access (selected_item)
-E- DXL: <SingleSelectListDlg.dxl:25> non local variable access (str_array)


All variable access - both parameter variables and the local vairable selected_item are not visible to the cb function "onItemSelection()". But why? Can anyone help me please?
(see Main2.dxl + SingleSelectionDlg.inc)

Best,
Oliver


-------------------------
Greetings,<BR>Oliver<BR><BR><BR>Oliver Roepke<BR>Axis Engineering AG, Munich
Report this to a Moderator Report this to a Moderator
 29-Nov-2005 10:36
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

I'm pretty sure you can't nest functions, which would probably account for the errors you're seeing.

You should be able to delcare everything (DBs, DBEs, functions) at the top level, and declare the parameters passed into SingleSelectListDlg as globals, then only show the dialog box when you call the function in the include file. You can still return the selected_item from that new (smaller) function.

Hope that helps a little,
Paul.

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 29-Nov-2005 11:00
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Hi Oliver,

it seems to be a simple problem of the placement of the #include statement.
The #include directive is done by preprocessor, so it is the same, as you copy the text of included file at the place of #include statement.
In the code of your included file, you refer to variables, which are declared later in the Main2.dxl file, so they are not know at this time ....

And of cause Paul is right - you can not create callback functions within other functions!

Greetings
Reik Schröder

-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany

Edited: 29-Nov-2005 at 11:02 by Reik Schroeder
Report this to a Moderator Report this to a Moderator
 29-Nov-2005 13:35
User is offline View Users Profile Print this message


Dennis Lockshine

Posts: 113
Joined: 7-Apr-2003

quote:

Originally posted by: Reik Schroeder
And of cause Paul is right - you can not create callback functions within other functions!
This is not true. It all depends on where the DBE element variables are declared. As shown in my example below, nesting functions is entirely legal, however the the placement of variable declaration limits where they can be used.

It would seem like any variable declared within a function would also be available to a nested function, however this is not the case. Declare these DBE variables globally so all functions will be able to use them.

-Dennis
Report this to a Moderator Report this to a Moderator
 29-Nov-2005 13:45
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

Thanks for that clarification Dennis. I wasn't sure whether it could be done, so I've never attempted it. It's never really seemed important enough to try!

I'm guessing Oliver's intention is to be able to encapsulate everything about the dialog box in a single function (tell us why, Oliver!), but your solution seems just as good to me. I'd probably still split out the functions so they're not nested, because the encapsulation is effectively pushed to the file level by the need to keep the DBs and DBEs global.

Regards,
Paul.

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 29-Nov-2005 19:40
User is offline View Users Profile Print this message


Oliver Röpke

Posts: 42
Joined: 23-Nov-2005

Hi!
Thank you all for your clarifications.

quote:

Originally posted by: Paul Tiplady
never really seemed important enough to try! I'm guessing Oliver's intention is to be able to encapsulate everything about the dialog box in a single function (tell us why, Oliver!), but your solution seems just as
As an old C++ developer I wanted to encapsulate all the stuff of a single selection list dialog into a generic function with generic parameter names which is callable from any position in my code.
And of course I stumbled over the DXL rules about scope and visibility of variables.

I've learned the following lessons which forced me to change my thoughts about unitizing code:
 - Nested functions are permitted.
 - Variables which shall be accessible inside (nested) functions shall be declared global.
 - Unitize code only via *.inc files w/o extra encapsulating by functions if cb functions shall work on 
   user defined variables.
 - Place *.inc files containing statements exact at the position in the caller code where the statements
   shall be executed.

Did I forgot anything?

BTW: I wonder that I've not found such important information like the visibility of variables in functions in the DXL reference manual. What are your experience?

Best regards,
Oliver



-------------------------
Greetings,<BR>Oliver<BR><BR><BR>Oliver Roepke<BR>Axis Engineering AG, Munich
Report this to a Moderator Report this to a Moderator
 29-Nov-2005 19:43
User is offline View Users Profile Print this message


Oliver Röpke

Posts: 42
Joined: 23-Nov-2005

Here's my last msg again since I made a mistake using the quoted message:

Hi!
Thank you all for your clarifications.


As an old C++ developer I wanted to encapsulate all the stuff of a single selection list dialog into a generic function with generic parameter names which is callable from any position in my code.
And of course I stumbled over the DXL rules about scope and visibility of variables.

I've learned the following lessons which forced me to change my thoughts about unitizing code:
 - Nested functions are permitted.
 - Variables which shall be accessible inside (nested) functions shall be declared global.
 - Unitize code only via *.inc files w/o extra encapsulating by functions if cb functions shall work on 
   user defined variables.
 - Place *.inc files containing statements exact at the position in the caller code where the statements
   shall be executed.

Did I forgot anything?

BTW: I wonder that I've not found such important information like the visibility of variables in functions in the DXL reference manual. What are your experience?

Best regards,
Oliver



-------------------------
Greetings,<BR>Oliver<BR><BR><BR>Oliver Roepke<BR>Axis Engineering AG, Munich
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.