Topic: change color based on sex

hi
Is there an script to change the color of a form based on sex?
What I want to do is to insert 2 check-boxes (Male / Female) in a form and when I check the male, the female box disables  and the form turn to blue and visa versa.
thank you

2 (edited by CDB 2022-06-13 09:52:14)

Re: change color based on sex

begin
   form1.color:= clGray;  //whatever default colour you want the form to be
   
   if form1.CheckBox1.Checked := True then
   begin
       form1.CheckBox2.Checked := False;  //make sure you don't have both boxes checked
      form1.color := clBlue;
   end
   else if
   begin
     form1.CheckboxBox2.Checked := True then
     form1.CheckBox1.Checked := False;
     form1.color := clred;
   end;
    

The above allows the form to keep it's default colour if no checkbox is ticked.

If you wished, in the form OnClose event, you could untick both checkboxes as above so that if the form is called again, everything is in it's default state.

On a clear disk you can seek forever

Re: change color based on sex

thanks for your reply but when I run this script I got an error for this line
"   if form1.CheckBox1.Checked := True then "

could you please attach a sample for your script
for example when the personnel is male the form changes to blue and if personnel is female the from turns to pink?
thank you so much

Re: change color based on sex

Hi,
I think it should be
   if form1.CheckBox1.Checked = True then  (ie, just an = rather than :=).
Derek.

Re: change color based on sex

Hi Derek
I did that too but still another error appears for the line "   else if "
please attach a sample because every time I correct this script another error pops up

6 (edited by identity 2022-06-13 14:36:09)

Re: change color based on sex

I used the following script instead of " else if" and it worked fine. Thank you


procedure Form1_CheckBox1_OnClick (Sender: TObject);
begin
      form1.color:= clBtnFace;

   if
   form1.CheckBox1.Checked = True then
   begin
       form1.CheckBox2.Checked := False;
      form1.color := clBlue;
   end;

end;

  procedure Form1_CheckBox2_OnClick (Sender: TObject);
begin
      form1.color:= clBtnFace;

   if
   form1.CheckBox2.Checked = True then
   begin
       form1.CheckBox1.Checked := False;
      form1.color := clFuchsia;
   end;
end;

Post's attachments

Attachment icon LinkFile File Name2.rar 373.02 kb, 134 downloads since 2022-06-13 

Re: change color based on sex

Hello Identify,
If there's no specific reason why you need to use a checkbox, then another option could be to use a combobox and link it to tables holding the 'sex' type and 'colors' rather than hard coding anything into your script.
Derek.

Post's attachments

Attachment icon form colour.zip 337 kb, 143 downloads since 2022-06-13