if
checkbox1.checked:= true thencheckbox1.caption:='lock'
combobox1.Enabled:=false
else
combobox1.Enabled:=true;如上代码...我愿意是:当checkbox1控件为选中状态时,它的名字就为lock,并且将combobox1改为未激活状态。
可为什么老是在then那里报错啊。
我怎么也看不出来是哪里出错了
向各位求助。谢谢!

解决方案 »

  1.   


    begin
    end
    去复习下语法吧
      

  2.   

    if checkbox1.checked  then 
    begin
      checkbox1.caption:='lock' 
      combobox1.Enabled:=false ;
    end
    else 
    combobox1.Enabled:=true
      

  3.   


    这样的写法,语法是没错了,但是。使用的时候能顺利嘛?我好像以前试过这样的写法,达不到目的,checkbox怎么点都选不中,我自己的写法如下:(用一个变量来控制)var
      m:integer;
    begin
      if m=1 then
      begin
        checkbox1.caption:='lock'; 
        combobox1.Enabled:=false ;
        m:=0;
      end else if m=0 then
      begin
        combobox1.Enabled:=true;
        m:=1;
      end;
    end;
      

  4.   

    貌似Then后只执行一句
    第二句视为else
      

  5.   

    晕了,我怎么把楼上回答的都复制过去并检查后运行达不到我想要的效果呢?
    要求:
    当checkbox1控件为选中状态时,它的名字就为lock,并且将combobox1改为未激活状态。 
    否则的话,CHECKBOX1的名字为unlock,COMBOBOX1为激活状态....
    上面是我没有说清楚
      

  6.   

    我自己慢慢摸了一下,这样写可以达到我的要求,是个很笨的方法,写两次就可以了
    begin
    if
    checkbox1.Checked then
    combobox1.enabled:=false
    else
    combobox1.enabled:=true;
    if checkbox1.Checked then checkbox1.Caption:='unlock '
    else
    checkbox1.Caption:='lock '   ;
    end;end.
    麻烦高手们帮我把以上的代码看有没有办法优化一下,不胜感激!
      

  7.   


    begin
      checkbox1.caption:='lock';
      if checkbox1.checked then
      begin
        checkbox1.caption:='unlock';
        checkbox1.enabled:=false;
      end else
        checkbox1.enabled:=true;
    end;
      

  8.   


    if checkbox1.Checked
    then checkbox1.Caption:='unlock ' 
    else checkbox1.Caption:='lock ';
    combobox1.enabled:=not heckbox1.Checked;
      

  9.   

    1 if语句不应该用:=,要用=
    2 没有begin...end
      

  10.   

    看来楼主的D基础也太烂了吧,这跟自学没多大关系吧,if checkbox1.checked= true then 
    begin
    checkbox1.caption:='lock' ;
    combobox1.Enabled:=false ;
    end
    else 
    combobox1.Enabled:=true; 
    楼主很强,很久未见楼主这般。。的了
      

  11.   

    哈哈,我估计原因是,他没把代码写到  CheckBox1Click(Sender: TObject); 这个事件中。
      

  12.   

    把以下代码COPY到CheckBox的ONCLICK 事件中。控件名字如果不是checkbox1 记得要改下面的代码if checkbox1.checked then
    begin
    checkbox1.caption:='lock' ;
    combobox1.Enabled:=false ;
    end
    else
    combobox1.Enabled:=true; 
      

  13.   

    if 
    checkbox1.checked:= true then 这是赋值 不是判断
      

  14.   

    不好意思,结贴晚了,因为问题一直没有想明白,以下是正确的代码,大家勿笑...
    时间的确花的太久了些,不过达到目的了procedure TForm1.CheckBox1Click(Sender: TObject);
    begin
    checkbox1.Caption:='unlock';
    if checkbox1.Checked = true then
    begin
    checkbox1.Caption:='unlock';
    combobox1.Enabled:=false;
    end else
    begin
    checkbox1.Caption:='lock';
    combobox1.Enabled:=true;
    end
    end;end.十分感谢大家的回答,更感谢大家的批评,这样更让我在出差的途中看DELPHI的书想到这个不会打瞌睡跟据tonylll兄的思路想出来的答案,所以选他的答案虽然不是理由,但是事实,不知道大家有没有一天到晚出差(在车上)有时还要连续上24小时班的经历(比如前天和昨天),有时下班早点又要处理家里和店里的事 只是因为自己的爱好想学门语言而捡起6年以前丢掉的东西从头开始学,有时的确会因为基础差而犯一些各位高手看起来很可笑的错误,希望大家批评中给以于指出,给于我更多动力.
    谢谢大家!
      

  15.   

    把完成后的图发上大家看一看,也许对以后我这样的菜鸟会有帮助
     锁定:http://cid-e4055a18739ae1a9.skydrive.live.com/self.aspx/.Public/delphi/sd.JPG
    解锁:http://cid-e4055a18739ae1a9.skydrive.live.com/self.aspx/.Public/delphi/js.JPG