* * *

Author Topic: Execute multiple things with 1 checkbox  (Read 712 times)

lulZghost

  • Newbie
  • Posts: 3
Execute multiple things with 1 checkbox
« on: April 27, 2017, 07:09:33 pm »
Hi, I just started with Lazarus some Days ago and still test with the program.

I make something basic (we also have at school) but extend it a bit.
I make a checkbox, that enable and disable the TEdit1. But I want to do multiple things with this one checkbox.

It worked with one command fine, but I dont know how to add another one. I tryed many things, search the web, but find nothing.

I know for you it might be simple, but I just started and am stuck right now. Please help me :D

Kujo

  • Newbie
  • Posts: 1
Re: Execute multiple things with 1 checkbox
« Reply #1 on: April 27, 2017, 07:22:17 pm »
Hi, if you have more than one command to use with if, while, repeat, for, with, you must use begin..end, that represents a block of instructions

if CheckBox1.Checked then
begin
  edit1.Enabled := False;
  edit1.Caption := 'This row is temporary disabled';
end
else
  edit1.Enabled := True;

P.S. you can use begin..end also after "else":

if ..... then
begin
  ...
end
else begin
  ....
end;
« Last Edit: April 27, 2017, 07:25:31 pm by Kujo »

Handoko

  • Hero Member
  • *****
  • Posts: 1514
  • My goal: build my own game engine using Lazarus
Re: Execute multiple things with 1 checkbox
« Reply #2 on: April 27, 2017, 07:30:12 pm »
Hello lulZghost and Kujo,
Welcome to this forum.

@lulZghost

If you do what Kujo said, your code should work correctly.

Also, properly indent your code (as what Kujo did) will make your code easier to read and debug. Usually we use 2 spaces to start a new block.

Have fun!

FTurtle

  • Full Member
  • ***
  • Posts: 177
Re: Execute multiple things with 1 checkbox
« Reply #3 on: April 27, 2017, 10:14:12 pm »
Code: Pascal  [Select]
  1. implementation
  2.  
  3. uses strutils;
  4.  
  5. {$R *.lfm}
  6.  
  7. { TForm1 }
  8.  
  9. procedure TForm1.CheckBox1Change(Sender: TObject);
  10. begin
  11.   Edit1.Enabled := not CheckBox1.Checked;
  12.   Edit1.Text := IfThen(CheckBox1.Checked, 'This row is temporary disabled', '');  // uses strutils
  13. end;
  14.  

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus