Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    delphi 7, is checkbox ticked?

    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:

    Code:
        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

  • #2
    Regular Coder
    Join Date
    Oct 2008
    Posts
    214
    Thanks
    5
    Thanked 22 Times in 22 Posts
    Use:

    Code:
    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...

  • Users who have thanked AlexV for this post:

    sir pannels (11-13-2008)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    thanks wolf, useful pointers there

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    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

  • #5
    Regular Coder
    Join Date
    Oct 2008
    Posts
    214
    Thanks
    5
    Thanked 22 Times in 22 Posts
    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:

    Code:
        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;
    Last edited by AlexV; 11-13-2008 at 03:41 PM.


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •