我在一个函数里定义了个变量 i:integer;
然后做了个循环,for i:=0 to 9 do 
可是,从一进入这个函数,就发现 i:=3 了,i这个变量只有这个函数中才有,其他地方都没有,怎么办啊?

解决方案 »

  1.   

    用softice跟踪看,这么少分,艾。!
      

  2.   

    ???不可能吧!这样试试
    先: i:=0 然后再
    for i:=0 to 9 do 
      

  3.   

    siyu2002(=猛犸=) 没遇到,只能说明你幸福啊!!!我该怎么办?
      

  4.   

    把project options的compiler
    optimization的钩点掉试试
      

  5.   

    大概是Delphi出问题了,你把代码copy到别人机器上试试吧
      

  6.   

    干脆这样
    var i,j:integer;
    begin
      j:=0;
      i:=j;
    for i:=0 to 9 do 
    ....end;
      

  7.   

    试了几部机都是这个样子function TreeToCreateTable(et: TElTree): Boolean;  procedure insertsql(aqTmp: TADOQuery; strSql, sTbName: string);
      begin
        strSql:=Copy(strSql, 1, length(strSql)-1)+')';
        with aqTmp do
        begin
          Close;
          Sql.Clear;
          Sql.Add(strSql);
          ExecSql;      Close;
          Sql.Clear;
          Sql.Add(' exec SPT_STSJDXB_INSERT '''+sTbName+''',-1,''T'' ');
          ExecSql;      Close;
          Sql.Clear;
          Sql.Add(' exec SPT_STZDMCB_INSERT '''+sTbName+''' ');
          ExecSql;      Close;
        end;
      end;var
      i: integer;
      eti: TElTreeItem;
      sTbName, strSql, strPre, sType: string;
      aqTmp1: TADOQuery;begin
      try
        Result := False;
        aqTmp1 := TADOQuery.Create(Application);
        aqTmp1.Connection := dm.acData;    strSql := '';                for i:=0 to et.Items.Count-1 do
        begin
          eti := et.Items.Item[i];
          if eti=nil then
          begin
            Result := true;
            exit;
          end;      if eti.iEdit<>2 then
          begin
            result := true;
            Continue;
          end;      if eti.Level=0 then
          begin
            if strSql<>'' then
              InsertSql(aqTmp1, strSql, sTbName);        sTbName := eti.Flag;
            strSql := '';
            strSql := ' create table '+sTbName+'(id int NOT NULL IDENTITY(1, 1) CONSTRAINT PK_id'+sTbName+' PRIMARY KEY CLUSTERED, ';
          end
          else
            if eti.ChildrenCount<=0 then
            begin
              try
                c := StrToInt(eti.Flag2);
              except
                c := -1;
              end;
              sType := SelectNodeType(eti, eti.ImageIndex, c, strPre);          if sType<>'' then
                strSql := strSql + eti.Flag+' '+ sType+' Null,';
            end;
        end;
        if strSql<>'' then
          InsertSql(aqTmp1, strSql, sTbName);    aqTmp1.Free;
        Result := true;    
      except
        aqTmp1.Free;
        Result := False;
      end;
    end;
      

  8.   

    你先这样试试看啊:::::::procedure TForm1.Button1Click(Sender: TObject);
    var
      i:Integer;
    begin
      for i:=0 to 9 do
        ShowMessage(IntToStr(i));
    end;
      

  9.   

    我认为这和机器、DELPHI、消息无关,是程序中内存泄漏造成的,你在i:integer前加一句sX:String试试,如果for里的i不再是3就肯定是这个问题。你仔细查查整个程序中和指针有关的部分。
      

  10.   

    Sunlily(阳光)  你的方法不行,
    jsandy(江苏安迪)  用你的方法,在循环内加了个ShowMessage就可以了,但是我总不能真的这么去实现吧?会被人给劈了的!!救救我吧!!!
      

  11.   

    Sunlily(阳光)  ,嘻嘻,原来你的方法好管用哦!
      

  12.   

    对了,你可以另外定义一个变量j
    然后:for i:= 0 to 10 do
    beign
      j:= i;
      {在用到i的地方全换成j,就可以了。以前好像就是这么办的}
    end;
      

  13.   

    TO:ll7777(游魂野鬼)
    我的方法是管用还是不管用呀?