Solved

Unexplained Value Change

Posted on 2008-10-03
11
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

631 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