TRzComboBox problem is Delphi 10.2?

Components on the Raize Lists palette: list boxes, check lists, combo boxes, tree views, list views, grids, etc.

TRzComboBox problem is Delphi 10.2?

Postby Norm@Home » Sat Nov 25, 2017 5:47 pm

I'm working on a problem I recently found with a Delphi program under 10.2 where I'm using TRzComboBoxes and I'm really having a hard time understanding what's going on. Take this code snip it:
Code: Select all
  If cbPublisher.Text <> 'All' Then
   Begin
     { Some code here }
      End
   Else
   Begin
     While qNames.SQL.Count > 1 Do qNames.SQL.Delete(1);
   End;


The problem I'm having is that when I trace through this and the value of cbPublisher.Text is 'All' the else statement should execute and in the debugger I've tested cbPublisher = 'All' and the result = True and yet the else doesn't execute. I tried changing this to this:
Code: Select all
  If cbPublisher.Text <> 'All' Then
   Begin
     { Some code here }
      End;
   End;
 If cbPublisher = 'All' Then
   Begin
     While qNames.SQL.Count > 1 Do qNames.SQL.Delete(1);
   End;

and still the statement under the "If cbPublisher = 'All' Then" does not execute even though the condition is true ('All' = 'All') in the debugger. Any ideas?
Norm@Home
 
Posts: 8
Joined:
Wed Mar 15, 2017 5:16 pm

Re: TRzComboBox problem is Delphi 10.2?

Postby Raize Support » Sun Nov 26, 2017 4:55 pm

Hi,

There may be a couple things going on here but right off the bat, I don't believe the code as written will execute. What I mean is that "if cbPublisher = 'All' then" should result in a syntax error because cbPublisher is a combo box and not a string. I assume that statement should read "if cbPublisher.Text = 'All' then".

Aside from that, I just created a test program where I dropped a TRzComboBox and a TRzButton on a form and then in the OnClick event handler for the button I entered your first code snippet. I did not drop a query component on the form, so I commented out the while loop and replaced with a simple ShowMessage statement. I then added several items to the ComboBox including "All" and then ran the app. When I selected one of the other values from the combo box and click the button, nothing happened, which was expected. When I selected "All" and the clicked the button, the ShowMessage dialog was indeed displayed.

I then set a break point and reran the app and when I selected "All" and clicked the button, the breakpoint fired.

The fact that the else part of your if test is not executing suggest two possible explanations. First, you are running the app without debugging so no breakpoints at all will fire. The second is that the qNames.SQL.Count property is 0 and thus the body of the while loop never executes and the appearance is that the statement is skipped.

Hope this helps,
Ray
Raize Software Support
Raize Software
http://www.raize.com
Raize Support
 
Posts: 603
Joined:
Fri Mar 25, 2011 9:04 pm


Return to Lists

Who is online

Users browsing this forum: No registered users and 2 guests

cron