Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Validation- Yes/No

[code]procedure TForm4.ComboBox1Exit(Sender: TObject);
var ok:boolean;
begin

ok:=false;
if upcase(combobox1.text) = 'YES' then ok:=true;

if upcase(combobox1.text) = 'NO' then ok:=true;

if ok=false then combobox1.Color:= clLime
{if any of the above in incorrect then make the colour lime green to show error}
else if length(combobox1.Text)=0 then combobox1.Color:=clred
{if there is nothing there, the box goes red}
else combobox1.color:=clWhite;
{otherwise it remains white}
end;

end.[/code]

it will accept YES and NO but not yes or no. And upcase doesn't work, it says:

"[Error] Unit4.pas(495): Incompatible types: 'Char' and 'TCaption'"

HELP!!

Comments

  • zibadianzibadian Posts: 6,349Member
    : [code]procedure TForm4.ComboBox1Exit(Sender: TObject);
    : var ok:boolean;
    : begin
    :
    : ok:=false;
    : if upcase(combobox1.text) = 'YES' then ok:=true;
    :
    : if upcase(combobox1.text) = 'NO' then ok:=true;
    :
    : if ok=false then combobox1.Color:= clLime
    : {if any of the above in incorrect then make the colour lime green to show error}
    : else if length(combobox1.Text)=0 then combobox1.Color:=clred
    : {if there is nothing there, the box goes red}
    : else combobox1.color:=clWhite;
    : {otherwise it remains white}
    : end;
    :
    : end.[/code]
    :
    : it will accept YES and NO but not yes or no. And upcase doesn't work, it says:
    :
    : "[Error] Unit4.pas(495): Incompatible types: 'Char' and 'TCaption'"
    :
    : HELP!!
    :
    If you want to upcase a string use the UpperCase() function.
Sign In or Register to comment.