第一次摸delphi  我.......
通常
if 表达式 then
      语句1
else 
      语句2;

根据语法,语句1后面不能有; 如果加了会怎么样?????如果我if then后面要跟不止一个语句1,还要有语句3 4....要怎么写???
以上是最重要的问题还有就是我做计算器的时候
if last='0' then
      first:='除数不能为o'     //之后first的内容会输出到editi这个文本框中
else
    first:=floattostr(strtofloat(first)/strtofloat(last));运行的时候 比如输入2/0 他就直接报错异常了。
如果在 first:='除数不能为o'加上 ;
实验的时候 输入2/0 editi显示仍是2,我不知道计算了没有。。然后归零下(计算器通常有这个归零的键的吧)再做 editi 2/0 显示就得到了 除数不能为o这究竟是为什么????!!!
 

解决方案 »

  1.   

    if ... then
    begin
    ....;
    ....;
    end else
    begin
    ....;
    if ... then
      ....;
    ....;
    end;
      

  2.   

    一个计算器 DEMOhttp://www.2ccc.com/article.asp?articleid=3234
      

  3.   

    1.
    if 1>0 then
    begin
      showmessage('1确实大于0');
    end
    else
    begin
      showmessage('太阳从西边出来了');
    end; 2.
    procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Length(MaskEdit1.Text)>30
      then
        begin
          if Key=#8
          then Button17.Click;
          Key:=#0;
        end;   Form1.KeyPreview:=True;
      if Key in ['1']
      then Button1.Click
      else if Key in['2']
           then Button2.Click
      else if Key in['3']
           then Button3.Click
      else if Key in['4']
           then Button4.Click
      else if Key in['5']
           then Button5.Click
      else if key in ['6']
           then Button6.Click
      else if Key in ['7']
           then Button7.Click
      else if key in ['8']
           then Button8.Click
      else if key in ['9']
           then button9.Click
      else if key in ['0']
           then button10.Click
      else if Key=#107
           then Button13.Click
      else if Key=#109
           then Button14.Click
      else if Key=#106
           then Button15.Click
      else if Key=#111
           then Button16.Click
      else if Key in [#103,#13,#187]
           then Button20.Click
      else if Key =#8
           then Button17.Click
      else if Key =#46
           then button18.Click;
    end;
      

  4.   


    这是你的算法问题
    if 表达式 then
    begin
    语句1;
    语句2;
    语句3;
    语句4;
    语句5;
    语句6;
    end
    else  if 表达式 then
    begin
    语句1;
    语句2;
    语句3;
    语句4;
    语句5;
    语句6;
    end
    else
    begin
    语句1;
    语句2;
    语句3;
    语句4;
    语句5;
    语句6;
    end
      

  5.   

    if a>b then
    begin
      showmessage('a>b');
    end else
    if a<b then
    begin
      showmessage('a<b');end else
    begin
      showmessage('a=b');
    end;