首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

变量赋值后仍为nil的有关问题

2012-02-13 
变量赋值后仍为nil的问题程序中,对变量赋值操作都是类似的,而uob1赋值能成功,而uob2,uob3赋值后仍为nilflo

变量赋值后仍为nil的问题
程序中,对变量赋值操作都是类似的,而uob1赋值能成功,而uob2,uob3赋值后仍为nil
              flow1赋值能成功,而flow2赋值后仍为nil;这是为什么啊,急...,请高人指点,
              Tflow,Tuob   是自定义的类.
type
      queueptr=^queuenode;
      queuenode=record
      data:Tflow;
      next:queueptr;
end;
linkedquetp=record
front,rear:queueptr;
end;
var
      flow1,flow2:Tflow;
      re1:TRectBox;
      uob1,uob2,uob3:Tuob;
      count:integer;//活动数量
      number:integer;//flow数量
      num:integer;//use_flow数量
type   uobarray=array   of   Tuob;
var   uobar:uobarray;
type   flowarray=array   of   Tflow;
var     flowar:flowarray;
type   usearray=array   of   Tuse_res;
var   usear:usearray;
implementation
//确定活动:按照活动的顺序存入数组
procedure   GetUobs();
var   i,j:integer;
begin
        count:=0;
        for   i:=0   to   FrmMain.ComponentCount-1   do
        begin
              if   midstr(FrmMain.Components[i].Name,1,3)= 'Uob '   then
                count:=count+1;
        end;
        setlength(uobar,count);
        count:=0;
        for   i:=0   to   FrmMain.ComponentCount-1   do
        begin
              if   midstr(FrmMain.Components[i].Name,1,3)= 'Uob '   then
                  begin
                      uob1:=Tuob(FrmMain.Components[i]);
                      uobar[count]:=uob1;
                      count:=count+1;
                  end;
        end;
        //排序
        for   i:=0   to   count-1   do
        begin
            uob1:=uobar[i];
            for   j:=i+1   to   count-1   do
                begin
                    if   uobar[j].Left <uob1.Left   then
                    begin
                          uob2:=uob1;
                          uob1:=uobar[j];
                          uobar[j]:=uob2;
                    end;
                end;
              uobar[i]:=uob1;
        end;
end;
//获得flow,按模型中从左到右顺序存入数组


procedure   Getflows();
var   i,j:integer;
begin
      number:=0;
      for   i:=0   to   FrmMain.ComponentCount-1   do
      begin
              if   midstr(FrmMain.Components[i].Name,1,3)= 'Flo '   then
                number:=number+1;
      end;
      setlength(flowar,number);
      number:=0;
      for   i:=0   to   FrmMain.ComponentCount-1   do
        begin
              if   midstr(FrmMain.Components[i].Name,1,3)= 'Flo '   then
                  begin
                        flow1:=Tflow(FrmMain.Components[i]);
                        flowar[number]:=flow1;
                        number:=number+1;
                  end;
        end;

              //排序
        for   i:=0   to   count-1   do
        begin
            flow1:=flowar[i];
            for   j:=i+1   to   count-1   do
                begin
                    if   flowar[j].Left <flow1.Left   then
                    begin
                          flow2:=flow1;
                          flow1:=flowar[j];
                          flowar[j]:=flow2;
                    end;
                end;
              flowar[i]:=flow1;
        end;
end;


//确定预计活动时间   (EST,   LET)
procedure   CalcuEAI();
var   i,j,m,n:integer;
        jun1:Tjunction;
begin
      GetUobs();
      Getflows();
      n:=0;
      uobar[0].EST:=0;
      uobar[0].LET:=strtoint(uobar[0].max_dur);
      for   i:=0   to   number-1   do
      begin
                        //与
              if   (midstr(flowar[i].begin_id,1,3)= 'Jan ')   and(midstr(flowar[i].end_id,1,3)= 'Uob ')   then
                begin
                          for   j:=0   to   FrmMain.ComponentCount-1   do
                            begin


                                    if   FrmMain.Components[j].Name=flowar[i].begin_id   then
                                      begin
                                            jun1:=Tjunction(FrmMain.Components[j]);
                                            break;
                                      end;
                            end;
                          if   jun1.juntype= '扇出 '   then
                          begin
                                    for   j:=0   to   number-1   do
                                    begin
                                        if   flowar[j].end_id=jun1.Name   then
                                            begin
                                                  for   m:=0   to   count-1   do
                                                  begin
                                                        if   flowar[j].begin_id=uobar[m].Name   then
                                                            uob1:=uobar[m];
                                                        if   flowar[i].end_id=uobar[m].Name   then
                                                            uob2:=uobar[m];
                                                  end;
                                            break;


                                            end;
                                    end;
                                    uob2.EST:=uob1.EST+strtoint(uob1.min_dur);
                                    uob2.LET:=uob1.LET+strtoint(uob2.max_dur);
                          end;
                          if   jun1.juntype= '扇入 '   then
                          begin
                                  for   j:=0   to   number-1   do
                                  begin
                                        if   flowar[j].end_id=jun1.Name   then
                                        begin
                                                for   m:=0   to   count-1   do
                                                begin
                                                      if   (flowar[j].begin_id=uobar[m].Name)and   (n=0)   then
                                                        begin
                                                        uob1:=uobar[m];
                                                        n:=n+1;
                                                  end;
                                                      if   (flowar[j].begin_id=uobar[m].Name)and   (n=1)   then
                                                      begin
                                                      uob3:=uobar[m];


                                                      n:=n+1;
                                                      end;
                                                      if   flowar[i].end_id=uobar[m].Name   then
                                                      uob2:=uobar[m];
                                                end;
                                        end;
                                  end;
                                  if   (uob1.EST+strtoint(uob1.min_dur))> (uob3.EST+strtoint(uob3.min_dur))   then
                                  uob2.EST:=uob1.EST+strtoint(uob1.min_dur)
                                  else
                                  uob2.EST:=uob3.EST+strtoint(uob3.min_dur);

                                  if   uob1.LET   >   uob3.LET   then
                                  uob2.EST:=uob1.LET+strtoint(uob2.max_dur)
                                  else
                                  uob2.EST:=uob3.LET+strtoint(uob2.max_dur);
                          n:=0;
                          end;
                end;
     
end;


[解决办法]
十分的凌乱
[解决办法]
//
if uobar[j].Left <uob1.Left then
begin
uob2:=uob1;
uob1:=uobar[j];
uobar[j]:=uob2;
break; // < < < < < < < <如果没有猜错,应该加上个跳出循环
end;
[解决办法]
有可能像楼上说的。
因为是在循环里面赋值,有可能最后的时候是个空的了。
你可以追踪一下结果测试一下
------解决方案--------------------


我觉上次的分析不对

if uobar[j].Left <uob1.Left then // < < < <有可能是这个条件没有成立过
begin
uob2:=uob1; // < < < < <关键是这句话没有被执行
uob1:=uobar[j];
uobar[j]:=uob2;
end;

楼主自己调试看看吧

热点排行