声明:
CONNECTINFO =record
       hName : string;
       lName : string;
       eName : string;
       sPort : string;
       ePort : string;
       end;
PConnectInfo=^ConnectInfo;
    F1:textfile;
    Btemp : boolean;    Topo :  TList;    //topo list执行:
procedure TFrmMain.SearchLines();
var i,j: integer;
    hShape,eShape,sport,eport : string;
    FIleName,FileToFind :String;
begin
  GetAllCon; //get all connect informations  Btemp := true;
  Filename:='temp.txt';
  FileToFind := FileSearch('temp.txt', UCCDraw1.GetCurLibPath);
  if filetofind<>'' then deleteFile(UCCDraw1.GetCurLibPath+'\temp.txt');  try
    assignfile(F1,FileName);
    begin
      reWrite(F1);
      
      i:=-1;
      j:=Topo.Count;      while i<=(j-1) do
      begin
        i:=i+1;
        j:= Topo.Count;
        if i<=(j-1) then begin
        hShape:= PConnectInfo(topo.Items[i]).hName;
        eShape :=  PConnectInfo(topo.Items[i]).eName;
        sport := PConnectInfo(topo.Items[i]).sPort;
        eport := PConnectInfo(topo.Items[i]).ePort;
        if copy(UCCDraw1.GetAttachProp(hShape,'CompID'),0,3)='021' then
        begin
          Writeln(F1,'@'+hshape+','+sPort+';');
          SearchLine1(hShape,sPort);
          Btemp := true;
          Continue;
        end;
        if copy(UCCDraw1.GetAttachProp(eShape,'CompID'),0,3)='021'  then
        begin
            Writeln(F1,'@'+eshape+','+ePort+';');
            SearchLine1(eShape,ePort);
            Btemp := True;
        end;
        end;
      end;
    end;
  finally
    closeFile(F1);
  end;end;procedure TFrmMain.GetAllCon;
var
    t,elem :variant;
    i,j,l,h : integer;
    conn: PConnectInfo;
begin
    if Topo.Count<>0 then Topo.Clear;  //?    t:=UCCDraw1.GetAllConnectionArray;
    l:=VarArrayLowBound(t,1);
    h:=VarArrayHighBound(t,1);
    for i:=0 to  (h-l) do
    begin
      elem:=VarArrayGet(t,i);
      new(conn);
      j:=0;
      conn.lName:=VarToStr(VarArrayGet(elem,j));
      j:=1;
      conn.hName:=VarToStr(VarArrayGet(elem,j));
      j:=2;
      conn.eName:=VarToStr(VarArrayGet(elem,j));
      j:=3;
      conn.sPort:=VarToStr(VarArrayGet(elem,j));
      j:=4;
      conn.ePort:=VarToStr(VarArrayGet(elem,j));
      topo.Add(conn);
    end;
end;procedure TFrmMain.SearchLine1(shape,port :string);
var i,j: integer;
    hShape,eShape,sport,eport : string;
    bch : boolean;
begin
  bch := False;
  if Btemp then       Btemp := False
  else if strtoint(copy(UCCDraw1.GetAttachProp(Shape,'CompID'),0,3)) in[18,19,20,21,28,29,17] then
    begin
     Writeln(F1,'$');
     exit;
    end;  i:=-1;
  j:=Topo.Count;  while i<=(j-1) do
  begin
    i:=i+1;
    j:= Topo.Count;
    if (j-1>i) and (not bch) then begin i:=0; bch:=True;end;   //
    if i<=(j-1) then  begin
    hShape:= PConnectInfo(topo.Items[i]).hName;
    eShape :=  PConnectInfo(topo.Items[i]).eName;
    sport := PConnectInfo(topo.Items[i]).sPort;
    eport := PConnectInfo(topo.Items[i]).ePort;
    if hShape=shape  then
    begin
      if sPort=port then
      begin
      Writeln(F1,'t'+eshape+','+eport+';');
      Topo.Delete(i);
      i:=i-1;
      SearchLine1(eshape,eport);
      continue;
      end else
      begin
        Writeln(F1,'z'+hShape+','+sport+';');
        SearchLine1(hShape,sport);
        Continue;
      end;    end;
    if eShape=shape  then
    begin
    if  ePort=port    then
    begin
      Writeln(F1,'t'+hshape+','+sport+';');
      Topo.Delete(i);
      i:=i-1;
      SearchLine1(hshape,sport);
      end else
      begin
        Writeln(F1,'z'+eShape+','+eport+';');
        SearchLine1(eShape,eport);
      end;
    end;
    end;
  end;end;
   我用递归函数来查找链表中的所有对象.topo里保存的是连接关系.子项的格式:连接线/起始对象/终了对象/起始点/终了点. 点属于对象.(起始点属于起始对象,终了点属于终了对象).
   查找时我先对整个链表进行循环,寻找适合的连接线进入递归函数.
   递归函数先查找与传入参数直接相连的连接线,记录后,将链表中的该子项删除,再找
           或是查找同一个对象但不相同的点的连接线记录,但不删除子项,继续查找.
出现问题  当我从递归中 返回时,有可能序号已经超过了链表的总数.会报错
          或是我没有超出,但先前循环过的子项已经被我删除,则有可能漏项.
      该如何解决?请指教.