1

Why does the code below return TRUE in Delphi 7 and FALSE in Delphi 2010? TBitBtn is a descendant of TButton.

    type
      TForm1 = class(TForm)
        Button1: TButton;
        BitBtn1: TBitBtn;
        procedure Button1Click(Sender: TObject);
      private
      public
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TestControl( aControl: TControl);
    begin
      if (aControl is TButton) then showmessage('TRUE') else showmessage('FALSE');
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      TestControl(BitBtn1);
    end;
RobertFrank
  • 7,332
  • 11
  • 53
  • 99
  • 1
    Is `TBitBtn` really the only class you tested before concluding that `is` is the thing that's different? – Rob Kennedy Jun 08 '10 at 18:59
  • 1
    Just a very minor small little tiny detail but did you know there is a BoolToStr function (I didn't until recently) – Remko Jun 08 '10 at 21:07
  • Thanks, Remko. I was looking for that just the other day, but didn't find it. Glad you mentioned it! - but it just returns the integer representation. I know there's one that returns a string ("True" or "False") but haven't been able to remember where it is! – RobertFrank Jun 08 '10 at 21:50
  • use BoolToStr(SomeBoolean, True), the 2nd parameter is UseBoolStr ;-) – Remko Jun 09 '10 at 06:21

1 Answers1

15

is did not change. TBitBtn is a subtype of TCustomButton, not TButton, as you state.

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
  • 4
    Yes, and that did change, I think between D2007 and D2009 – jasonpenny Jun 08 '10 at 18:41
  • That's it! Thanks, Craig. I got stung by going back to Delphi 7's help to check it's ancestor! It never occurred to me to check in D2010's help (which I try to avoid when I can...) Thanks, Craig and I voted you, Jason, up too! SO rocks! – RobertFrank Jun 08 '10 at 19:10
  • 5
    Tom, the help is never the place I look for stuff like that. I always consult the source code directly. Ctrl+click on the `TBitBtn` identifier to be taken to its declaration. – Rob Kennedy Jun 08 '10 at 20:22
  • 2
    This topic was covered last year: http://stackoverflow.com/questions/946316/what-happened-to-codegears-tbitbtn-and-tbutton-inheritence-chain – Remy Lebeau Jun 08 '10 at 22:38