Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strtoint problem

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I have been using Delphi for more than 10 years and I have run in to a problem that I have never seen before. I have converted the current date to a string, "20091115' and I want to convert it to an integer. i have also tried to convert '2009', '11' and '15' and get the same message as follows:
E2171 Variable 'CurrYearMonDay' inaccessible here due to optimization.

How do I solve this problem?
 
To be able to use the built-in debugger efficiently (and the same applies to external debuggers like TDW - Turbo Debugger for Windows), you need to ensure a few compiler settings are set the right way.

An Important setting is:

Optimization Off
Enabling optimization would prevent you from examining the value of a variable after it has gone out of scope. A variable is gone out of scope if there is no further reading access to this variable in the flow of code even though you may be far from the end of a function's code block. At that point it is no longer available for inspection - there's no point holding on to what no one else is going to need, right? Usually this seems to happen just right after you want to look at this value.. but instead you get an error message "Variable 'XXX' inaccessible here due to optimization".
So turn off optimizations for your debugging builds.

Aaron
 
You might also have another strtoint function within your scope.
 
Dunno if its of any help but, what I do if I have a problem seeing a variable value, I display the value in a temporary label or edt box on the form.
Hannes
 
There is a check box that says "Allow Function Calls" which can help - but optimization does have to be off for this to work most of the time.
 
DjangMan's suggestion of another strtoint function in scope is my first guess too. You can quickly see where a function resides by simply resting your mouse over the function name, and the popup will show something like

Code:
func SysUtils.StrToInt: function(const S: String): Integer - sysutils.pas (4067)

telling you exactly where the function is declared in which file and what line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top