函数执行到最后异常invalid pointer operation
procedure LINE_CMPControlText(Count1,Count2:integer;TR1,TR2:TRichEdit;StructInfo1,StructInfo2:array of StructInfomation;var MatchInfo:array of MatchInfomation);//5//对比两控件各行,选择匹配最当,记录在MatchInfo数组中
var
Str1,Str2:string;
i1,i2,i:integer;//循环变量
Length1,length2:integer;
N:integer;//匹配成功个数
percent:integer;
TempInfo: array of TempInfomation;//临时数组
begin
i1:=1;
SetLength(TempInfo,Count2);//设置临时数组长度(保存与TR2各行匹配的信息)
while(i1<=count1)do
begin
Str1:=StructInfo1.lstring;
Length1:=length(Trim(Str1));
//ShowMessage(Str1);
for i2:=1 to Count2 do
//此循环匹配Str1与TR2各行,并将信息填入TempInfo数组中,为下一个For铺垫
begin
Str2:=StructInfo2.lstring;
length2:=length(Trim(Str2));
N:=LINE_CompareString(Str1,Str2);
if(length1>=length2)then
percent:=Trunc(N*100/length1)
else percent:=Trunc(N*100/length2);
TempInfo.Number:=N;//为临时数组赋值
TempInfo.percent:=percent;
end;
MatchInfo.percent:=TempInfo.percent;//For循环前赋初值
MatchInfo.TR1Line:=i1;
MatchInfo.TR2Line:=1;
MatchInfo.MatchNumber:=TempInfo.Number;
for i:=1 to count2 do
//选择percent最大项,赋予MatchInfo数组
begin
if(TempInfo.percent=100)then
//如果匹配比为100,则直接赋值跳出
begin
MatchInfo.TR1Line:=i1;
MatchInfo.TR2Line:=i;
MatchInfo.MatchNumber:=TempInfo.Number;
MatchInfo.Percent:=TempInfo.percent;
break;
end;
if(i<=count2-1)then
begin
if(TempInfo.percent<TempInfo.Percent)then
begin
MatchInfo.percent:=TempInfo.percent;
MatchInfo.TR2Line:=i+1;
MatchInfo.TR2Line:=i1;
MatchInfo.MatchNumber:=TempInfo.Number;
end
end
end;
i1:=i1+1;
end;
ShowMessage('ok');
弹出对话框后,异常
end;
后来,我检查了以下是数组少了,改了之后程序正常运行不出现异常,但是关闭窗口时又出现上面的异常! {:1_1:} 解决啦,之前网上搜说要加USE ShareMem 单元,我把它删除ok
页:
[1]