Solved

Unexplained Value Change

Posted on 2008-10-03
11
192 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 123
Comparing dates in Delphi. Greater than/ Less than 3 216
Base1 Encode/Decode 3 81
Delphi: making a BW image transparent 10 59
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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