我在编写时出现了以下的错误,我的程序如下:
function TForm1.IsWin(isblack:boolean):boolean;    //自定义函数
Label l1;   //定义标号  l1是标号名称
var
 i,j,wtag:integer;
begin IsWin:=false;
 if isblack then
   wtag:=1
 else
   wtag:=2;
for i:=0 to 16 do
for j:=0 to 12 do
 begin
 {判断是否有一行连成}
   if(i<13) and (tag[i,j]=wtag) and (tag[i+1,j]=wtag) and (tag[i+2,j]=wtag) and
     (tag[i+3,j]=wtag) and (tag[i+4,j]=wtag) then
   begin
     IsWin:=true;
     goto l1;  //跳到标号处
   end;
..........//以下省略运行时出现错误提示:
[Error] U_Five.pas(35): Label declared and referenced, but not set: 'l1'
我对照了错误表,解释为:标号被<label>说明及引用,但不能设置。
但是我不明白为什么会出错?为什么不能设置?怎么设置才对?请高手指点!

解决方案 »

  1.   

    你要goto到哪里啊?标号l1没有设置啊,比如加在begin 后面:
    begin
    l1:  // 这里
     IsWin:=false;
     if isblack then
       wtag:=1
     else
       wtag:=2;
    ...
      

  2.   

    你的标号没有设置呀:
    标号最好还是用 用意义的字符吧,免得出错!
    改正后的
    function TForm1.IsWin(isblack:boolean):boolean;    //自定义函数
    Label l1;   //定义标号  l1是标号名称
    var
     i,j,wtag:integer;
    begin IsWin:=false;
     if isblack then
       wtag:=1
     else
       wtag:=2;
    for i:=0 to 16 do
    for j:=0 to 12 do
     begin
     {判断是否有一行连成}
       if(i<13) and (tag[i,j]=wtag) and (tag[i+1,j]=wtag) and (tag[i+2,j]=wtag) and
         (tag[i+3,j]=wtag) and (tag[i+4,j]=wtag) then
       begin//==========================下面改正===============
      11:   IsWin:=true;//把标号写在这里,呵呵我也犯过这个毛病!
         goto l1;  //跳到标号处
       end;
    ..........//以下省略
      

  3.   

    var label nextfiled1;
    begin
      语句
       nextfiled1:
      语句
      goto nextfiled1;
    end;
      

  4.   

    11:
    后面就是你要GOTO到的语句
    给你个最好的例子(DELPHI中的),注意他的写法!
    procedure FindFirstAnswer;
    var X, Y, Z, Count: Integer;
    label FoundAnAnswer;
    begin
      Count := SomeConstant;
      for X := 1 to Count do
        for Y := 1 to Count do
          for Z := 1 to Count do
            if ... { some condition holds on X, Y, and Z } then
              goto FoundAnAnswer;
     
      ... {code to execute if no answer is found }
      Exit;
     
      FoundAnAnswer:
        ... { code to execute when an answer is found }end;