Solved

Unexplained Value Change

Posted on 2008-10-03
11
189 Views
Last Modified: 2013-11-05
I am totally confused about something so am looking to you gurus for help in understanding.  I realize there might not be a cut-and-dried answer but I really want to understand this.

I have a window with several combo boxes, checkboxes etc. It also uses Rave Reports with a custom connection.  When you click a button a report is generated.  When I enter the routine to open the custom connection the value of, say, the checkbox will say "checked" is false when it is "true".  However, if I use the entire window name; for instance, MyForm.checkbox, it is reported correctly.  I thought maybe I had some conflict in names so I named the checkbox to something totally nonsensical.  Still happens.  I even took everything off the window but a checkbox and buttons with minimum code and it still happens.  No memory leaks are reported in ReportMemoryLeaksOnShutdown.  I stepped through the code, even in the Rave report (nice code), and the global variable MyForm.checkbox is always correct.

So... why, on the window where the checkbox actually exists, would it be unable to report the value of a checkbox unless I have the entire window name attached? Since I have tracked this down I can work around it,however it makes me really uneasy.  I would just like to understand.  I use Delphi 2007 in Vista.  

Any insight from you experts would be appreciated.  Thanks.


0
Comment
Question by:alexiat
  • 7
  • 4
11 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 22632922
but how do you check those values?
in debug mode with watch set or when you move mouse over value when process is topped or you when you use some boolean operators or in any other way?


ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22632927
is this value passed as parameter to some method?
anyway piece of code would be a great help

ziolko.
0
 

Author Comment

by:alexiat
ID: 22632994
I first noticed it when I had a statement on MyForm of "if checked do this" and it wasn't being executed.  The checkbox value isn't passed as any parameter.  I stepped through my code and the Delphi watch list stated the value was false but the value MyForm.checkbox was true.  I can't really give a code snippet but here is the sequence.  The true/false comes from the Delphi watch list.

RaveProject.Execute  =>  checkbox.checked true
    RaveProject.CustomConnectionOpen  => checkbox.checked false; MyForm.checkbox.checked true
RaveProject.Close  => checkbox.checked true

Since the checkbox is local on the form I used the MyForm.checkbox value when I stepped through the report and it was always true, as it should be.



0
 
LVL 21

Expert Comment

by:ziolko
ID: 22633195
it's not possible that property value is changed "auto-magically" if MyForm.Checkbox.Checked always has correct value then we can exclude that some event handler is changing value for whatever reason.
so I guess it's scope issue, mostlikely there is other checkbox with same name in other linked unit.

also note that if you use:

var b1, b2: TCheckBox;
begin
  b1 := TCheckBox.Create(nil);
  b2 := TCheckBox.Create(nil);
  b1.Checked := True;
  with b1, b2 do
    if Checked then
      ShowMessage('checked')
    else
      ShowMessage('not checked');

only checked of b2 will be tested

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22633210
ahh make simple test: leave checkbox.checked (without MyForm) press control button and click on "checkbox" you'll jump to decaration of object which will be tested

ziolko.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:alexiat
ID: 22633365
Sorry for not understanding, but what do you mean by "press control button"?  Also, this happens with other components on the form too.  I was just using the checkbox as an example.  For instance, the itemindex of a listbox may be 0 but it shows as -1 at the same time the checkbox shows as false.  I know it makes no sense.  If it can't possibly be anything other than a scope problem I can work around that.  

0
 
LVL 21

Expert Comment

by:ziolko
ID: 22633484
>>Sorry for not understanding, but what do you mean by "press control button"?
press and hold "Ctrl" on your kyeboard move mouse over "checkox" in your code and click with mouse, cursor should jump to declaration of "checkbox".

if it happens with all controls it may be caused by having two forms running, if your form is autocreated and you create it also in runtime then one form may have properties set but you test properties of other one

ziolko.
0
 

Author Comment

by:alexiat
ID: 22633929
Thanks. The declarations are fine it is just as if inside this routine it has no idea of what the values are.
The report is auto created and at runtime.  So is is a safe assumption that it is simply a scope issue?
0
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 22634043
>>The report is auto created and at runtime.
first of all you have to decide you want to use autocreate form or run-time created, personally I would choose run-time  go to project -> options -> forms -> auto-create forms and remove it from there, also very important is to remove global variable declaration:

type
  TForm2 = class(TForm)
  private
  protected
  public
  end;

var  Form2: TForm2; <- remove those two lines
then everything should be ok

>>So is is a safe assumption that it is simply a scope issue?
yes, it was only about one component then I would say that value is changed somewhere in code, but in this case if you have problem with ALL of them I'm pretty sure that it's caused by having form doubled

ziolko.

0
 

Author Closing Comment

by:alexiat
ID: 31502718
Thank you. I always feel much better receiving a clarification from an expert like you. I like to understand rather than just "do".  I would be lost without you experts.  :-)
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22634213
>>I like to understand rather than just "do".
and that's the best approach to programming:)

ziolko.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now