请教,delphi程序问题。

TheMadMan 2013-08-02 05:45:47
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
count1:Integer;
// a,b,c:Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
count1:=count1+1;
if (count1 mod 2=1) then
ListBox1.Items.Add('HELLO WORLD!');
else
ListBox1.Items.Add('HELLO FRIEND!');
end;

end.
后面的判断,我分别注释后都能显示出来,但是放一起就会报错。请问原因。
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
TheMadMan 2013-08-07
  • 打赏
  • 举报
回复
引用 2 楼 sololie 的回复:

if (count1 mod 2=1) then
   ListBox1.Items.Add('HELLO WORLD!') // 这里不能有分号,因为这句话没说完,下面还有 否则
else
   ListBox1.Items.Add('HELLO FRIEND!');
end;
多谢,这些习惯还是不适应,见谅 、
Mit1208 2013-08-07
  • 打赏
  • 举报
回复
代码结束才使用分号。
LastAvengers 2013-08-02
  • 打赏
  • 举报
回复
sololie 大哥说得对 还有 if (count1 mod 2=1) then 最好写成if (count1 mod 2)= 1 then
sololie 2013-08-02
  • 打赏
  • 举报
回复

if (count1 mod 2=1) then
   ListBox1.Items.Add('HELLO WORLD!') // 这里不能有分号,因为这句话没说完,下面还有 否则
else
   ListBox1.Items.Add('HELLO FRIEND!');
end;
sololie 2013-08-02
  • 打赏
  • 举报
回复
ListBox1.Items.Add('HELLO WORLD!'); // 最后的;号去掉

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧