...

View Full Version : delphi 7, is checkbox ticked?



sir pannels
11-12-2008, 04:28 PM
hi there,

trying to work out if a checkbox is checked or not in delphi.. Have been googling but to no success. My checkbox is called 'dtfiles' and I tried this:


if (TForm1.dtfiles.asInteger>0) then
//Checked:= true
ShowMessage('ticked');
else
//Checked:= false;
ShowMessage('not ticked');
end;

However that errors and says "method identifier expected"

Does any one have any info on this?

many thanks

AlexV
11-12-2008, 07:41 PM
Use:


if dtfiles.Checked then
ShowMessage('ticked')
else
ShowMessage('not ticked');

1) Don't need to put "end" without "begin".
2) () are not required in "if" in Delphi (not like C/C++).
3) ";" is not allowed before an "else".
4) You are using the class name TForm1 which is TCustomForm descendant. You need to use the name of the form instead. In this example it's probably "Form1". Depending of the scope of your code, "Form1" can be skipped...

sir pannels
11-13-2008, 09:00 AM
thanks wolf, useful pointers there :)

sir pannels
11-13-2008, 01:30 PM
hi wolf,

one thing that confuses me... if you dont need end or anything, how does the code know when the else code ends?


cheers

AlexV
11-13-2008, 02:36 PM
Since you can't use ; before an else the if ends with the first ; after the else.

You can ONLY omit begin/end for a single line statement...

All these are valid:



if true then
beep();


if true then
begin
beep(); //You can also omit ; on this line but I never do it
end;


if true then
beep()
else
MessageDlg('foo', mtInformation, [mbOK], 0);


if true then
begin
beep();
inc(i); //Equivalent of i++
end
else
MessageDlg('foo', mtInformation, [mbOK], 0);


if true then
begin
beep();
inc(i);
end
else
begin
beep();
MessageDlg('foo', mtInformation, [mbOK], 0);
end;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum