主题:[讨论][求助]变量赋值不成功
程序中定义的变量Flow1赋值能成功,但Flow2赋值后仍为nil;
变量Uob1赋值能成功,但Uob1,Uob2赋值后仍为nil;
我尝试过用Assign函数,结果仍是nil,请教各位 应该怎么解决啊,谢谢了.
type
queueptr=^queuenode;
queuenode=record
data:Tflow;
next:queueptr;
end;
linkedquetp=record
front,rear:queueptr;
end;
Function Gethead(var Q:linkedquetp):Tflow;
Function Empty(var Q:linkedquetp):Boolean;
Procedure Enqueue(x:Tflow;var Q:linkedquetp);
procedure Dequeue(var Q:linkedquetp);
Procedure clear(var Q:linkedquetp);
Function Reachable(n1:TRectBox;n2:TRectBox):Boolean;
Function GetAnc(n1:TRectBox;n2:TRectBox):TRectBox;
procedure GetUobs();
procedure Getflows();
procedure CalcuEAI();
function CheckResource(uob1:Tuob;uob2:Tuob):boolean;
function Check_Res_Consist():boolean;
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
//函数值返回队列Q的队头元素。
Function Gethead(var Q:linkedquetp):Tflow;
begin
if Empty(Q) then ShowMessage('The queue is empty!')
else
result:=Q.front^.next^.data;
end;
//将元素x插入队列Q的队尾,入队
Procedure Enqueue(x:Tflow;var Q:linkedquetp);
begin
new(Q.rear^.next);
Q.rear:=Q.rear^.next;
Q.rear^.data:=x;
Q.rear^.next:=nil;
end;
//若Q是一个空队列,则函数值为true,否则为false。
Function Empty(var Q:linkedquetp):Boolean;
begin
result:=(Q.front=Q.rear);
end;
//将Q的队头元素删除。
procedure Dequeue(var Q:linkedquetp);
var
p:queueptr;
begin
if Empty(Q) then ShowMessage('The queue is empty!')
else
begin
p:=Q.front;
Q.front:=Q.front^.next;
dispose(p)
end;
end;
//使队列Q成为空队列。
Procedure clear(var Q:linkedquetp);
begin
Q.rear:=Q.front;
while Q.front<>nil do
begin
Q.front:=Q.front^.next;
dispose(Q.rear);
Q.rear:=Q.front;
end;
new(Q.front);
Q.front^.next:=nil;
Q.rear:=Q.front;
end;
//判断两结点是否可达
Function Reachable(n1:TRectBox;n2:TRectBox):Boolean;
var Q:linkedquetp;
i:Integer;
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow1:=Tflow(FrmMain.Components[i]);
if flow1.begin_id=n1.Name then
Enqueue(flow1,Q);
end;
end;
while Empty(Q)=false do
begin
flow1:=GetHead(Q);
Dequeue(Q);
if flow1.end_id=n2.Name then
begin
result:=true;
break;
end
else
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow2:=Tflow.Create(FrmMain.Components[i]);
if flow2.begin_id=flow1.end_id then
Enqueue(flow2,Q);
end;
end;
end;
end;
if Empty(Q) then result:=false;
end;
//获得祖先结点
Function GetAnc(n1:TRectBox;n2:TRectBox):TRectBox;
var
Q:linkedquetp;
i:integer;
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow1:=Tflow(FrmMain.Components[i]);
if flow1.end_id=n1.Name then
Enqueue(flow1,Q);
end;
end;
if Reachable(n1,n2) then result:=n1
else
begin
if Reachable(n2,n1) then result:=n2
else
begin
while Empty(Q)=false do
begin
flow1:=GetHead(Q);
Dequeue(Q);
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is TRectBox then
if FrmMain.Components[i].Name=flow1.begin_id then
re1:=TRectBox(FrmMain.Components[i]);
end;
if Reachable(re1,n2) then
begin
result:=re1;
break;
end
else
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow2:=Tflow(FrmMain.Components[i]);
if flow2.end_id=flow1.begin_id then
Enqueue(flow2,Q);
end;
end;
end;
end;
end;
end;
end;
//确定活动:按照活动的顺序存入数组
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;
变量Uob1赋值能成功,但Uob1,Uob2赋值后仍为nil;
我尝试过用Assign函数,结果仍是nil,请教各位 应该怎么解决啊,谢谢了.
type
queueptr=^queuenode;
queuenode=record
data:Tflow;
next:queueptr;
end;
linkedquetp=record
front,rear:queueptr;
end;
Function Gethead(var Q:linkedquetp):Tflow;
Function Empty(var Q:linkedquetp):Boolean;
Procedure Enqueue(x:Tflow;var Q:linkedquetp);
procedure Dequeue(var Q:linkedquetp);
Procedure clear(var Q:linkedquetp);
Function Reachable(n1:TRectBox;n2:TRectBox):Boolean;
Function GetAnc(n1:TRectBox;n2:TRectBox):TRectBox;
procedure GetUobs();
procedure Getflows();
procedure CalcuEAI();
function CheckResource(uob1:Tuob;uob2:Tuob):boolean;
function Check_Res_Consist():boolean;
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
//函数值返回队列Q的队头元素。
Function Gethead(var Q:linkedquetp):Tflow;
begin
if Empty(Q) then ShowMessage('The queue is empty!')
else
result:=Q.front^.next^.data;
end;
//将元素x插入队列Q的队尾,入队
Procedure Enqueue(x:Tflow;var Q:linkedquetp);
begin
new(Q.rear^.next);
Q.rear:=Q.rear^.next;
Q.rear^.data:=x;
Q.rear^.next:=nil;
end;
//若Q是一个空队列,则函数值为true,否则为false。
Function Empty(var Q:linkedquetp):Boolean;
begin
result:=(Q.front=Q.rear);
end;
//将Q的队头元素删除。
procedure Dequeue(var Q:linkedquetp);
var
p:queueptr;
begin
if Empty(Q) then ShowMessage('The queue is empty!')
else
begin
p:=Q.front;
Q.front:=Q.front^.next;
dispose(p)
end;
end;
//使队列Q成为空队列。
Procedure clear(var Q:linkedquetp);
begin
Q.rear:=Q.front;
while Q.front<>nil do
begin
Q.front:=Q.front^.next;
dispose(Q.rear);
Q.rear:=Q.front;
end;
new(Q.front);
Q.front^.next:=nil;
Q.rear:=Q.front;
end;
//判断两结点是否可达
Function Reachable(n1:TRectBox;n2:TRectBox):Boolean;
var Q:linkedquetp;
i:Integer;
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow1:=Tflow(FrmMain.Components[i]);
if flow1.begin_id=n1.Name then
Enqueue(flow1,Q);
end;
end;
while Empty(Q)=false do
begin
flow1:=GetHead(Q);
Dequeue(Q);
if flow1.end_id=n2.Name then
begin
result:=true;
break;
end
else
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow2:=Tflow.Create(FrmMain.Components[i]);
if flow2.begin_id=flow1.end_id then
Enqueue(flow2,Q);
end;
end;
end;
end;
if Empty(Q) then result:=false;
end;
//获得祖先结点
Function GetAnc(n1:TRectBox;n2:TRectBox):TRectBox;
var
Q:linkedquetp;
i:integer;
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow1:=Tflow(FrmMain.Components[i]);
if flow1.end_id=n1.Name then
Enqueue(flow1,Q);
end;
end;
if Reachable(n1,n2) then result:=n1
else
begin
if Reachable(n2,n1) then result:=n2
else
begin
while Empty(Q)=false do
begin
flow1:=GetHead(Q);
Dequeue(Q);
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is TRectBox then
if FrmMain.Components[i].Name=flow1.begin_id then
re1:=TRectBox(FrmMain.Components[i]);
end;
if Reachable(re1,n2) then
begin
result:=re1;
break;
end
else
begin
for i:=0 to FrmMain.ComponentCount-1 do
begin
if FrmMain.Components[i] is Tzjnline then
if MidStr(FrmMain.Components[i].Name,1,3)='Flo' then
begin
flow2:=Tflow(FrmMain.Components[i]);
if flow2.end_id=flow1.begin_id then
Enqueue(flow2,Q);
end;
end;
end;
end;
end;
end;
end;
//确定活动:按照活动的顺序存入数组
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;