Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Unexplained Value Change

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
alexiat
Asked:
alexiat
  • 7
  • 4
1 Solution
 
ziolkoCommented:
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
 
ziolkoCommented:
is this value passed as parameter to some method?
anyway piece of code would be a great help

ziolko.
0
 
alexiatAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ziolkoCommented:
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
 
ziolkoCommented:
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
 
alexiatAuthor Commented:
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
 
ziolkoCommented:
>>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
 
alexiatAuthor Commented:
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
 
ziolkoCommented:
>>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
 
alexiatAuthor Commented:
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
 
ziolkoCommented:
>>I like to understand rather than just "do".
and that's the best approach to programming:)

ziolko.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now