0

How can you use a case statement depending on the badge caption ? Tried :

procedure TForm2.Button1Click(Sender: TObject);
begin
case AdvBadgeGlowButton1.Caption of
'Test' :     showmessage('Test')
end;
''     :     showmessage('Empty')
end;

but am getting :

[dcc32 Error] Unit2.pas(29): E2001 Ordinal type required [dcc32 Error]

Unit2.pas(30): E2010 Incompatible types: 'Integer' and 'string'

Community
  • 1
  • 1
user763539
  • 3,509
  • 6
  • 44
  • 103
  • 1
    use IF THEN. String type cannot be used with `Case` – Zam Jan 28 '19 at 12:31
  • I don't think it's possible, because (as the error message points out) a String is not an ordinal type. It also seems bad practice to me; what if your code needs to work in other languages too? See if you can use an ID instead. That ID should determine the text in your control, and would be used as the variable in the `case` statement. – S.L. Barth is on codidact.com Jan 28 '19 at 12:31
  • You can't use `case` on anything that is not numeric (ordinal), as the error message says. Use `if...else` instead. – Ken White Jan 28 '19 at 13:14
  • Thank you @Ken White ... understood ... You can post the answer. – user763539 Jan 28 '19 at 13:28

1 Answers1

0

case cannot be used for values that are not ordinal types (typically integer values), as the error message says. You'll need to use if..else instead.

procedure TForm2.Button1Click(Sender: TObject);
begin
  if AdvBadgeGlowButton1.Caption = 'Test' then
    ShowMessage('Test')
  else if AdvBadgeGlowButton1.Caption = '' then
    ShowMessage('Empty')
  else
    ShowMessage('Got unknown caption ' + AdvBadgeGlowButton1.Caption);
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444