irishsnowman
Technical User
I have used Borland delphi 7, for programming.
The individual procedures run fine.
But when i use the program in loop the program will give Access Voilation at some location.
But at different time at different number of iterations.
I tried to write something (like the local variable stack state) in a log file, Many times the file contains incomplete last sentance like: if it was to write "The number of Nodes 5" It writes "The numbe "
I have used records(structs) and many dynamic arrays which are setlength with in the procedures.
When I use a memmory managemnt program as uses (lib), It fail after giving result of more iterations.
when i used Borland Delphi 2006 trial version:
the individual procedures also stops working, giving out access voilations.
When i traced into it I found that when a record is passed to a procedure its component suddenly gets wrong address (or its values change to zero or large numbers).
this happends when I was using setlenght for another component of some other record, which is also passed through the parameters of the procedure.
can someone look into it.
Thanks
--------------CALL TO PROCEDURE-------------------------------
crossovertrees(Ft1,n1,Ft2,n2,ta,tb);
---------------PROCEDURE-------------------------------------
Procedure CrossoverTrees(var PrntTree1:TFeatTree; TrimNd1:integer;
var PrntTree2:TFeatTree; TrimNd2:integer;
var OfsprTree1:TfeatTree; var OfsprTree2:TFeatTree);
var
s1a,s1b,s2a,s2b,st1:stack;
cnctNd1,cnctNd2,lenTreeA,LenTreeASub,lenTreeB,LenTreeBSub,idx1,idxsb:integer;
n1,k,j,i,sh1,nsIndex,lenTreeAi,LenTreeBi,idxsa,idx2:integer;
TreeASub,TreeBSub:TFeatTree;
ActiveNd1,ActiveNd1A
TFeatNd;
begin
if (TrimNd1<=high(PrntTree1.FeatNd))and (TrimNd2<=high(PrntTree2.FeatNd))then
begin
setlength(s1a.sindex,30);
s1a.Top:=0;
setlength(s1b.sindex,30);
s1b.Top:=0;
setlength(s2a.sindex,30);
s1a.Top:=0;
setlength(s2b.sindex,30);
s2b.Top:=0;
setlength(ofsprTree1.FeatNd,30);
setlength(treeAsub.FeatNd,30);
setlength(ofsprTree2.FeatNd,30);
setlength(treeBsub.FeatNd,30);
BisectTree(PrntTree1,TrimNd1,cnctNd1,OfsprTree1,TreeASub,s1a,s1b);
BisectTree(PrntTree2,TrimNd2,cnctNd2,OfsprTree2,TreeBSub,s2a,s2b);
setlength(st1.sindex,50);
st1.Top:=0;
idx1:=high(OfsprTree1.featNd);
LenTreeA:=high(OfsprTree1.FeatNd);
LenTreeBSub:=high(TreeBSub.FeatNd);
setlength(OfsprTree1.FeatNd,LentreeA+LenTreeBSub+1);
LenTreeAi:=LenTreeA;
for k:=1 to high(OfsprTree1.FeatNd) do
begin
if OfsprTree1.FeatNd[k].index=cnctNd1 then
begin
if high(OfsprTree1.FeatNd[k].Sons)>=1 then setlength(OfsprTree1.FeatNd[k].Sons,high(OfsprTree1.FeatNd[k].Sons)+2)
else setlength(OfsprTree1.FeatNd[k].Sons,2);
OfsprTree1.FeatNd[k].Sons[high(OfsprTree1.FeatNd[k].Sons)]:=@OfsprTree1.FeatNd[LenTreeA+1];
end;
end;
for i:=1 to high(TreeBSub.FeatNd) do
begin
LenTreeA:=LenTreeA+1;
OfsprTree1.FeatNd[LenTreeA]:=TreeBSub.FeatNd;
OfsprTree1.FeatNd[LenTreeA].index:=LenTreeA;
if LenTreeA=(LentreeAi+1) then
begin
for k:=1 to high(OfsprTree1.FeatNd) do
if OfsprTree1.FeatNd[k].index=cnctNd1 then OfsprTree1.FeatNd[LenTreeA].Father:=@OfsprTree1.FeatNd[k];
end
else OfsprTree1.FeatNd[LenTreeA].Father:=@OfsprTree1.FeatNd[TreeBSub.FeatNd.Father.index+LenTreeAi];
if high(TreeBSub.FeatNd.sons)>=1 then
for j:=1 to high(TreeBSub.FeatNd.sons) do
begin
nsIndex:=TreeBSub.FeatNd.sons[j].index-1;
OfsprTree1.FeatNd[LenTreeA].Sons[j]:=@OfsprTree1.FeatNd[LenTreeA+nsIndex];
end;
OfsprTree1.FeatNd[LenTreeA].index:=LenTreeA;
end;
//idx2:=high(ofsprTree2.featNd);
LenTreeB:=high(ofsprTree2.FeatNd);
LenTreeASub:=high(TreeASub.FeatNd);
setlength(ofsprTree2.FeatNd,LenTreeB+LenTreeASub+1);
LenTreeBi:=LenTreeB;
for k:=1 to high(ofsprTree2.FeatNd) do
begin
if ofsprTree2.FeatNd[k].index=cnctNd2 then
begin
if high(ofsprTree2.FeatNd[k].Sons)>=1 then setlength(ofsprTree2.FeatNd[k].Sons, high(ofsprTree2.FeatNd[k].Sons)+2)
else setlength(ofsprTree2.FeatNd[k].Sons,2);
ofsprTree2.FeatNd[k].Sons[high(ofsprTree2.FeatNd[k].Sons)]:=@ofsprTree2.FeatNd[LenTreeB+1];
end;
end;
for i:=1 to high(TreeASub.FeatNd) do
begin
LenTreeB:=LenTreeB+1;
ofsprTree2.FeatNd[LenTreeB]:=TreeASub.FeatNd;
ofsprTree2.FeatNd[LenTreeB].index:=LenTreeB;
if LenTreeB=(LentreeBi+1) then
begin
for k:=1 to high(ofsprTree2.FeatNd) do
if ofsprTree2.FeatNd[k].index=cnctNd2 then ofsprTree2.FeatNd[LenTreeB].Father:=@ofsprTree2.FeatNd[k];
end
else ofsprTree2.FeatNd[LenTreeB].Father:=@ofsprTree2.FeatNd[TreeASub.FeatNd.Father.index+LenTreeBi];
if high(TreeASub.FeatNd.sons)>=1 then
for j:=1 to high(TreeASub.FeatNd.sons) do
begin
nsIndex:=TreeASub.FeatNd.sons[j].index-1;
ofsprTree2.FeatNd[LenTreeB].Sons[j]:=@ofsprTree2.FeatNd[LenTreeB+nsIndex];
end;
end;
AddMatrixtoTree(OfsprTree1);
ConstructDistMatFromVXMatix(OfsprTree1.TreeMatrix, high(OfsprTree1.TreeMatrix.VXValue));
ConstructFAMArrays(OfsprTree1.TreeMatrix);
AddMatrixtoTree(ofsprTree2);
ConstructDistMatFromVXMatix(ofsprTree2.TreeMatrix, high(ofsprTree2.TreeMatrix.VXValue));
ConstructFAMArrays(ofsprTree2.TreeMatrix);
end;
end;
the type definition is as
Type
PTFeatNd=^TFeatNd;
TFeatNd = Record
PtrFAM:TFAM; //this is not a pointer but a record again
FLIndex:integer;
Father
TFeatNd;
Sons: array of PTFeatNd;
index:integer;
depth:integer;
end;
TFeatTree = Record
FeatNd:Array of TFeatNd;
TreeMatrix:TFAM;
Fit:single;
end;
can someone help
The individual procedures run fine.
But when i use the program in loop the program will give Access Voilation at some location.
But at different time at different number of iterations.
I tried to write something (like the local variable stack state) in a log file, Many times the file contains incomplete last sentance like: if it was to write "The number of Nodes 5" It writes "The numbe "
I have used records(structs) and many dynamic arrays which are setlength with in the procedures.
When I use a memmory managemnt program as uses (lib), It fail after giving result of more iterations.
when i used Borland Delphi 2006 trial version:
the individual procedures also stops working, giving out access voilations.
When i traced into it I found that when a record is passed to a procedure its component suddenly gets wrong address (or its values change to zero or large numbers).
this happends when I was using setlenght for another component of some other record, which is also passed through the parameters of the procedure.
can someone look into it.
Thanks
--------------CALL TO PROCEDURE-------------------------------
crossovertrees(Ft1,n1,Ft2,n2,ta,tb);
---------------PROCEDURE-------------------------------------
Procedure CrossoverTrees(var PrntTree1:TFeatTree; TrimNd1:integer;
var PrntTree2:TFeatTree; TrimNd2:integer;
var OfsprTree1:TfeatTree; var OfsprTree2:TFeatTree);
var
s1a,s1b,s2a,s2b,st1:stack;
cnctNd1,cnctNd2,lenTreeA,LenTreeASub,lenTreeB,LenTreeBSub,idx1,idxsb:integer;
n1,k,j,i,sh1,nsIndex,lenTreeAi,LenTreeBi,idxsa,idx2:integer;
TreeASub,TreeBSub:TFeatTree;
ActiveNd1,ActiveNd1A
begin
if (TrimNd1<=high(PrntTree1.FeatNd))and (TrimNd2<=high(PrntTree2.FeatNd))then
begin
setlength(s1a.sindex,30);
s1a.Top:=0;
setlength(s1b.sindex,30);
s1b.Top:=0;
setlength(s2a.sindex,30);
s1a.Top:=0;
setlength(s2b.sindex,30);
s2b.Top:=0;
setlength(ofsprTree1.FeatNd,30);
setlength(treeAsub.FeatNd,30);
setlength(ofsprTree2.FeatNd,30);
setlength(treeBsub.FeatNd,30);
BisectTree(PrntTree1,TrimNd1,cnctNd1,OfsprTree1,TreeASub,s1a,s1b);
BisectTree(PrntTree2,TrimNd2,cnctNd2,OfsprTree2,TreeBSub,s2a,s2b);
setlength(st1.sindex,50);
st1.Top:=0;
idx1:=high(OfsprTree1.featNd);
LenTreeA:=high(OfsprTree1.FeatNd);
LenTreeBSub:=high(TreeBSub.FeatNd);
setlength(OfsprTree1.FeatNd,LentreeA+LenTreeBSub+1);
LenTreeAi:=LenTreeA;
for k:=1 to high(OfsprTree1.FeatNd) do
begin
if OfsprTree1.FeatNd[k].index=cnctNd1 then
begin
if high(OfsprTree1.FeatNd[k].Sons)>=1 then setlength(OfsprTree1.FeatNd[k].Sons,high(OfsprTree1.FeatNd[k].Sons)+2)
else setlength(OfsprTree1.FeatNd[k].Sons,2);
OfsprTree1.FeatNd[k].Sons[high(OfsprTree1.FeatNd[k].Sons)]:=@OfsprTree1.FeatNd[LenTreeA+1];
end;
end;
for i:=1 to high(TreeBSub.FeatNd) do
begin
LenTreeA:=LenTreeA+1;
OfsprTree1.FeatNd[LenTreeA]:=TreeBSub.FeatNd;
OfsprTree1.FeatNd[LenTreeA].index:=LenTreeA;
if LenTreeA=(LentreeAi+1) then
begin
for k:=1 to high(OfsprTree1.FeatNd) do
if OfsprTree1.FeatNd[k].index=cnctNd1 then OfsprTree1.FeatNd[LenTreeA].Father:=@OfsprTree1.FeatNd[k];
end
else OfsprTree1.FeatNd[LenTreeA].Father:=@OfsprTree1.FeatNd[TreeBSub.FeatNd.Father.index+LenTreeAi];
if high(TreeBSub.FeatNd.sons)>=1 then
for j:=1 to high(TreeBSub.FeatNd.sons) do
begin
nsIndex:=TreeBSub.FeatNd.sons[j].index-1;
OfsprTree1.FeatNd[LenTreeA].Sons[j]:=@OfsprTree1.FeatNd[LenTreeA+nsIndex];
end;
OfsprTree1.FeatNd[LenTreeA].index:=LenTreeA;
end;
//idx2:=high(ofsprTree2.featNd);
LenTreeB:=high(ofsprTree2.FeatNd);
LenTreeASub:=high(TreeASub.FeatNd);
setlength(ofsprTree2.FeatNd,LenTreeB+LenTreeASub+1);
LenTreeBi:=LenTreeB;
for k:=1 to high(ofsprTree2.FeatNd) do
begin
if ofsprTree2.FeatNd[k].index=cnctNd2 then
begin
if high(ofsprTree2.FeatNd[k].Sons)>=1 then setlength(ofsprTree2.FeatNd[k].Sons, high(ofsprTree2.FeatNd[k].Sons)+2)
else setlength(ofsprTree2.FeatNd[k].Sons,2);
ofsprTree2.FeatNd[k].Sons[high(ofsprTree2.FeatNd[k].Sons)]:=@ofsprTree2.FeatNd[LenTreeB+1];
end;
end;
for i:=1 to high(TreeASub.FeatNd) do
begin
LenTreeB:=LenTreeB+1;
ofsprTree2.FeatNd[LenTreeB]:=TreeASub.FeatNd;
ofsprTree2.FeatNd[LenTreeB].index:=LenTreeB;
if LenTreeB=(LentreeBi+1) then
begin
for k:=1 to high(ofsprTree2.FeatNd) do
if ofsprTree2.FeatNd[k].index=cnctNd2 then ofsprTree2.FeatNd[LenTreeB].Father:=@ofsprTree2.FeatNd[k];
end
else ofsprTree2.FeatNd[LenTreeB].Father:=@ofsprTree2.FeatNd[TreeASub.FeatNd.Father.index+LenTreeBi];
if high(TreeASub.FeatNd.sons)>=1 then
for j:=1 to high(TreeASub.FeatNd.sons) do
begin
nsIndex:=TreeASub.FeatNd.sons[j].index-1;
ofsprTree2.FeatNd[LenTreeB].Sons[j]:=@ofsprTree2.FeatNd[LenTreeB+nsIndex];
end;
end;
AddMatrixtoTree(OfsprTree1);
ConstructDistMatFromVXMatix(OfsprTree1.TreeMatrix, high(OfsprTree1.TreeMatrix.VXValue));
ConstructFAMArrays(OfsprTree1.TreeMatrix);
AddMatrixtoTree(ofsprTree2);
ConstructDistMatFromVXMatix(ofsprTree2.TreeMatrix, high(ofsprTree2.TreeMatrix.VXValue));
ConstructFAMArrays(ofsprTree2.TreeMatrix);
end;
end;
the type definition is as
Type
PTFeatNd=^TFeatNd;
TFeatNd = Record
PtrFAM:TFAM; //this is not a pointer but a record again
FLIndex:integer;
Father
Sons: array of PTFeatNd;
index:integer;
depth:integer;
end;
TFeatTree = Record
FeatNd:Array of TFeatNd;
TreeMatrix:TFAM;
Fit:single;
end;
can someone help