Topic: Auto checkbox when text present

I need a special script to check if a TextBox contains any text to automatically switch an invisible checkbox to "True" so in the user interface, there is only a "yes" displayed.

example:

Table Computers

Rem_Status                           Remark
0
1                                            Hard disk drive exchanged


On the user interface, there is only "yes" displayed to not clutter the visual and the information could be displayed when opening the row.

Screenshots attached

Post's attachments

Attachment icon image2.png 15.34 kb, 278 downloads since 2015-03-03 

2 (edited by tcoton 2015-03-03 09:45:12)

Re: Auto checkbox when text present

I managed to switch to "yes" when a remark is present but not to "no" when we delete the comment...

//Rem_status checkbox Admin form, if a remark is present, then check the box automatically
procedure Admin_Remark_OnChange (Sender: string);
begin
    if Admin.Remark.Text<>'' then Admin.Rem_Status.Checked:=True else Admin.Rem_Status.Checked:=False;

end;

Any suggestion?

3 (edited by mathmathou 2015-03-03 12:49:22)

Re: Auto checkbox when text present

I created a blank projet with just Form1, Edit1 and a Checkbox1

When I enter some text in the Edit1, the checkbox is automaticaly checked, and when I empty the Edit1, the checkbox unchecks. It works for me with this code :

procedure Form1_Edit1_OnChange (Sender: string);
begin
    if Form1.Edit1.Text<>'' then
    Form1.CheckBox1.Checked:=True
    else
    Form1.CheckBox1.Checked:=False;
end;

Project is attached


Have a good day


Mathias


PS : Version si 1.49

Post's attachments

Attachment icon checkbox_checked.zip 332.2 kb, 511 downloads since 2015-03-03 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

4 (edited by tcoton 2015-03-03 18:18:10)

Re: Auto checkbox when text present

Ok, it is the same code and actually I think I found a bug:

during my test, I had checked the first checkbox manually to see if "Yes" was properly displayed and I left it checked before implementing the script. Then after that, clearing the text fields did not change the checkbox to "false".

I have unchecked the checkbox manually and now, it is working as expected.

Thanks for the hint!

Re: Auto checkbox when text present

Yes, you are right, it's the same code smile


But I made a little modification to it this morning :


1- Checkbox Visible is disabled by default, so that on opening of Form1 it is not shown.


2 - Then, when you type text in the Edit1, the checkbox appears and is checked by default


3 - If you erase the text in Edit1, the checkbox disappears again


4- and so on when you write or erase text in the Edit1



Wasn't it what you initially wanted ?

procedure Form1_Edit1_OnChange (Sender: string);

begin
    if Form1.Edit1.Text<>'' then
    begin
        Form1.CheckBox1.Visible:=True;
        Form1.Checkbox1.Checked:=True;
    end;
    if Form1.Edit1.Text='' then
    begin
        Form1.CheckBox1.Visible:=False;
    end;
end;
begin
end.

Have a good day

Mathias

Post's attachments

Attachment icon checkbox_checked2.zip 332.31 kb, 546 downloads since 2015-03-03 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor