Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Radio Buttons Simulation

edited June 2003 in RAP
Hi,

I'm trying to display in reports the settings of radio buttons as they
appear on a number of forms in the application. Since there are no Radio
Button components in RB (DB or otherwise, a la CheckBox component), I'm
trying to construct them, for each radio button, by using two circles, one
inside the other with the inner one using black fill. The layout looks fine
except that now I need to be able to turn the Visible property of the inner,
black-filled circle on and off based on the setting of the field in the
database. I have tried the obvious as I show below. In the interest of
simplicity, the example below assumes two radio buttons to represent whether
a direction is Up or Down. Assume the buttons (the inner circle components)
are called RbUp and RbDown, respectively, and the database field appears in
a pipeline, RplTable, as the boolean field 'UpDown'. If True, I want to
make RbUp visible and RbDown not visible, and vv. At design time, I am
making both radio buttons NOT visible. I also added a DBCheckBox tied to the
same field so I can tell if the database field setting is correct or not.
This DBCheckBox displays correctly in all cases.

RbUp.Visible := RplTable['UpDown']

and

RbUp.Visible := not RplTable['UpDown'].

I have tried all the following:

1. Set up a global procedure that includes both above statements and call it
from the global OnCreate event.
2. Create OnPrint events for RbUp and RbDown and add the statements there,
respectively. This resulted in a runtime error along the lines of "Cannot
run RbUpOnPrint program".
3. Same as (2) above except on the OnDrawCommandCreate. This did not report
an error but did not turn on the visibility of either radio button.

Am going about this the right way, or is there an easier way to accomplish
this task. The same would apply for any number of radio buttons tied
together.

Thank you for your help.

Waguih

Comments

  • edited June 2003
    First, get it working from within the context of Delphi event handlers. This
    will be easier to debug first, then port it over to a RAP based report. Are
    you creating a TppDrawShape set to draw a circle? In the
    PropertiesToDrawCommand method of the radio button component, you need to
    control the visibility of the TppDrawShape in that method, as well as
    control the drawing of a circle in the PaintDesignControl method, which is
    what is shown in the designer.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    Hi Jim,

    Thanks for your response. I'm not sure I fully understand your response,
    though. I think that the circles I'm using direct from the RB Designer's
    toolbar are actually TppShape and not TppDrawShape. Now I can see that
    TppShape has the two methods that you mention (PropertiesToDrawCommand and
    PaintDesignControl) in its TppPrintable ancestor, but I'm still not sure
    whetther you are suggesting that I create an RB RadioButton component as a
    descendant of TppShape and override these two methods to add the control of
    the Visibility property. If not, then I'm still not clear on which event of
    TppShape I should attach my code to.

    Having said all that, I continued down the path I was going and here's what
    I found. Adding any code to the OnDrawCommandCreate and OnDrawCommandClick
    events didn't help in any way. However, and this is really weird, adding the
    code:

    RbUp.Visible := RplTable['UpDown']

    to the OnPrint event actually worked but only for the "Up" circle. This was
    generating an error before when I also had the code:

    RbDown.Visible := not RplTable['UpDown']

    code added to the "Down" circle. When I removed the "Down" circle code, the
    "Up" circle code worked.

    So I went back and added the "Down" circle code "Identical" to the "Up"
    circle code, i.e. without the "not". This also worked, except of course both
    "radio buttons" were now identical instead of opposite. I added back the
    "not" and it broke again. Finally I did the obvious and changed the "Down"
    circle code to read:

    if RplTable['UpDown'] then
    RbDown.Visible := False
    else
    RbDown.Visible := True;

    and, as expected, it worked. I tried that on multiple sets of radio buttons
    (paired circles) and they all behaved the same way. My question therefore
    is: Is there a problem compiling event code where the logical operator "not"
    is used directly with a data pipeline field?

    This seems to have resolved my immediate problem. I would still very much
    like to understand your suggestion above so it can help me with future
    issues, and would also ask you to comment on what I've described above.

    Thanks for your continued help.

    Waguih

  • edited June 2003
    I was thinking you were following the architecture of your RB control using
    the methods shown to be overridden similar to the demo RCL DB Checkbox
    control. You can create your own draw command class and handle the drawing
    of the circles and text using one draw command and override the Draw routine
    of the draw command class to draw them all from one single draw command.
    This way the device won't render them, but rather the draw command will
    render itself.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    I as actually not going down that path at all as I don't feel I'm fluent
    enough using RB to be creating my own RB controls. I might start tackling
    that as, from checking out the RCL DB Checkbox demo, I can now better
    understand what you're saying.

    I would still be interested in knowing whether the problem I'm having when
    using the statement:
    RbDown.Visible := not RplTable['UpDown']
    in the OnPrint even is a verifiable one, or if I'm doing something wrong
    there.

    Thanks again, Jim.

    Waguih

  • edited June 2003
    Oh, sorry, the best event to toggle visibilities is the band's BeforePrint
    event. That should do the trick.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    Thanks, Jim. I'll try that.

    Waguih

This discussion has been closed.