| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1582 人关注过本帖
标题:求助——delphi程序结束时‘无效指针’的提示
只看楼主 加入收藏
maomao862532
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-29
收藏
 问题点数:0 回复次数:2 
求助——delphi程序结束时‘无效指针’的提示
程序只有两个过程:formcreat,btn1click.代码全部通过,但程序运行完时,输出文件已经生成,但project文件运行到最后end时出现提示:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help   
---------------------------
我程序的源代码如下,请各位大哥大姐给我找找原因,项目急需(这是段代码是建立一个模型,读取输入文件,进行计算,然后把结果写入输出文件):

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Math;


type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    n:Integer;
    d:array of TDateTime;
    wa:array of Double;
    SD:TDateTime;
    SW:Double;
    da:array of TDateTime;
    dat:array of Double;
    Le:array of Double;
    Ve:array of Double;
    W:array of Double;
    B:array of array of Double;
    E:array of array of Double;
    F:array of array of Double;
    WV,WL,WD:array of array of array of Double;
    RV,RL,RD:array of array of Double;
    RV1,RL1,RD1:array of array of Double;
    RV2,RL2,RD2:array of array of Double;
    AA2:array of Double;
    AV,AL,AD:array of Double;
    BV,BL,BD:array of Double;
    R2:array of array of Double;
    B2:array of Double;
    B3:array of Double;
    fina:array of Double;
    B4:array of Double;
    procedure Result(fina:array of Double);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
const
    L:array[0..6] of Integer=(145,150,155,160,165,170,175);
    V:array[0..7] of Integer=(0,5,10,15,20,25,30,35);
    SL=5;
    SV=5;


implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var   myfile:TextFile;
      s:string;
      date:TDateTime;
      i,j,k,p:Integer;
      water,temp,def,sum4,sum5,sum6:Double;
      maxRL1,minRL1,maxRV1,minRV1,maxRD1,minRD1:Double;
      a0,b0,c0,d0,e0,f0,g0,h0,i0,j0,a1,a2,a3:Double;
      maxa,maxb:array of Double;
      sum1,sum2,sum3:Double;
      m:Integer;
      y:Integer;
begin
//********************** 导入数据 **********************
  AssignFile(myfile,extractfilepath(Application.ExeName)+'in.txt');
  Reset(myfile);
  Readln(myfile,s);
  n:=StrToInt(Copy(s,1,Pos(',',s)-1));
  s:=Copy(s,Pos(',',s)+1,Length(s));
  m:=StrToInt(Copy(s,1,Pos(',',s)-1));
  s:=Copy(s,Pos(',',s)+1,Length(s));
  y:=StrToInt(s);
  SetLength(d,m);
  SetLength(wa,y);
  Readln(myfile,s);
  for i:=0 to m-2 do
  begin
    d[i]:=StrToInt(Copy(s,1,Pos(',',s)-1));
    s:=Copy(s,Pos(',',s)+1,Length(s));
  end;
  d[m-1]:=StrToInt(s);
  SD:=Abs(d[1]-d[0]);
  Readln(myfile,s);
  for i:=0 to y-2 do
  begin
    wa[i]:=StrToFloat(Copy(s,1,Pos(',',s)-1));
    s:=Copy(s,Pos(',',s)+1,Length(s));
  end;
  wa[y-1]:=StrToFloat(s);
  SW:=Abs(wa[1]-wa[0]);
  SetLength(da,n);
  SetLength(dat,n);
  SetLength(Le,n);
  SetLength(Ve,n);
  SetLength(W,n);
  for i:=0 to n-1 do
  begin
    Readln(myfile,s);
    date:=StrToDateTime(Copy(s,1,Pos(',',s)-1));
    s:=Copy(s,Pos(',',s)+1,Length(s));
    water:=StrToFloat(Copy(s,1,Pos(',',s)-1));
    s:=Copy(s,Pos(',',s)+1,Length(s));
    temp:=StrToFloat(Copy(s,1,Pos(',',s)-1));
    s:=Copy(s,Pos(',',s)+1,Length(s));
    def:=StrToFloat(s);
    da[i]:=date;
    dat[i]:=(da[i]-da[0])/365;
    Le[i]:=water;
    Ve[i]:=temp;
    W[i]:=def;
  end;
//*****************************************
  SetLength(B,8,y);
  SetLength(WV,n,8,y);
  for j:=0 to y-1 do
   for k:=0 to 7 do
  begin
    B[k,j]:=0;
  end;
  for i:=0 to n-1 do
   for j:=0 to y-1 do
    for k:=0 to 6 do
  begin
    if (W[i]>=Wa[j]) and (W[i]<=Wa[j+1])  then
    begin
     if (Ve[i]>V[k]) and (Ve[i]<=V[k+1]) then
     begin
       WV[i,k,j]:=(1-abs(W[i]-wa[j])/SW)*(1-abs(Ve[i]-V[k])/5);
       WV[i,k+1,j]:=(1-abs(W[i]-wa[j])/SW)*(1-abs(Ve[i]-V[k+1])/5);
       WV[i,k,j+1]:=(1-abs(W[i]-wa[j+1])/SW)*(1-abs(Ve[i]-V[k])/5);
       WV[i,k+1,j+1]:=(1-abs(W[i]-wa[j+1])/SW)*(1-abs(Ve[i]-V[k+1])/5);
     end;
    end;
     B[k,j]:=B[k,j]+WV[i,k,j];
  end;
//****************************************
  SetLength(E,7,y);
  SetLength(WL,n,7,y);
  for j:=0 to y-1 do
   for k:=0 to 6 do
   begin
     E[k,j]:=0;
   end;
  for i:=0 to n-1 do
   for j:=0 to y-1 do
    for k:=0 to 5 do
  begin
    if (W[i]>=Wa[j]) and (W[i]<=Wa[j+1])  then
    begin
     if (Le[i]>L[k]) and (Le[i]<=L[k+1]) then
     begin
       WL[i,k,j]:=(1-abs(W[i]-wa[j])/SW)*(1-abs(Le[i]-L[k])/5);
       WL[i,k+1,j]:=(1-abs(W[i]-wa[j])/SW)*(1-abs(Le[i]-L[k+1])/5);
       WL[i,k,j+1]:=(1-abs(W[i]-wa[j+1])/SW)*(1-abs(Le[i]-L[k])/5);
       WL[i,k+1,j+1]:=(1-abs(W[i]-wa[j+1])/SW)*(1-abs(Le[i]-L[k+1])/5);
     end;
    end;
      E[k,j]:=E[k,j]+WL[i,k,j];
  end;
//*******************************************
   SetLength(F,m,y);
   SetLength(WD,n,m,y);
  for j:=0 to y-1 do
    for k:=0 to m-1 do
   begin
     F[k,j]:=0;
   end;
   for i:=0 to n-1 do
   for j:=0 to y-1 do
    for k:=0 to m-2 do
  begin
    if (W[i]>=Wa[j]) and (W[i]<=Wa[j+1])  then
    begin
     if (dat[i]>d[k]) and (dat[i]<=d[k+1]) then
     begin
       Wd[i,k,j]:=(1-abs(W[i]-wa[j])/SW)*(1-abs(dat[i]-d[k])/SD);
       Wd[i,k+1,j]:=(1-abs(W[i]-wa[j])/SW)*(1-abs(dat[i]-d[k+1])/SD);
       Wd[i,k,j+1]:=(1-abs(W[i]-wa[j+1])/SW)*(1-abs(dat[i]-d[k])/SD);
       Wd[i,k+1,j+1]:=(1-abs(W[i]-wa[j+1])/SW)*(1-abs(dat[i]-d[k+1])/SD);
     end;
    end;
     F[k,j]:=F[k,j]+WD[i,k,j];
  end;
//********************************************
  SetLength(maxa,8);
   a0:=B[1,0];
  for k:=0 to 7 do
  begin
   for j:=0 to y-1 do
   begin
     if B[k,j]>=a0 then
     a0:=B[k,j];
   end;
    maxa[k]:=a0;
  end;
  SetLength(maxb,y);
   for j:=0 to y-1 do
   begin
    for k:=0 to 7 do
    begin
      if B[k,j]>=a0 then
      a0:=B[k,j];
    end;
     maxb[j]:=a0;
   end;
   SetLength(RV,8,y);
   for k:=0 to 7 do
    for j:=0 to y-1 do
  begin
    RV[k,j]:=B[k,j]/max(maxa[k],maxb[j]);
  end;
//********************************************
   SetLength(maxa,7);
   b0:=E[1,0];
  for k:=0 to 6 do
  begin
   for j:=0 to y-1 do
   begin
     if B[k,j]>=a0 then
     b0:=B[k,j];
   end;
    maxa[k]:=b0;
  end;
  SetLength(maxb,y);
   for j:=0 to y-1 do
   begin
    for k:=0 to 6 do
    begin
      if B[k,j]>=a0 then
      b0:=B[k,j];
    end;
     maxb[j]:=b0;
   end;
   SetLength(RL,7,y);
   for k:=0 to 6 do
    for j:=0 to y-1 do
  begin
    RL[k,j]:=B[k,j]/max(maxa[k],maxb[j]);
  end;
//********************************************
  SetLength(maxa,m);
   c0:=E[1,0];
  for k:=0 to m-1 do
  begin
   for j:=0 to y-1 do
   begin
     if B[k,j]>=a0 then
     c0:=B[k,j];
   end;
    maxa[k]:=c0;
  end;
  SetLength(maxb,y);
   for j:=0 to y-1 do
   begin
    for k:=0 to m-1 do
    begin
      if B[k,j]>=a0 then
      c0:=B[k,j];
    end;
     maxb[j]:=c0;
   end;
   SetLength(RD,m,y);
   for k:=0 to m-1 do
    for j:=0 to y-1 do
  begin
    RD[k,j]:=B[k,j]/max(maxa[k],maxb[j]);
  end;
//********************************************
  SetLength(RL1,7,y);
  for j:=0 to y-1 do
   for k:=0 to 6 do
  begin
    RL1[k,j]:=L[k]-wa[j];
  end;
  d0:=0;
  e0:=0;
  for j:=0 to y-1 do
   for k:=0 to 6 do
   begin
     if RL1[k,j]>=d0 then
     d0:=RL1[k,j];
     if RL1[k,j]<=e0 then
     e0:=RL1[k,j];
   end;
   SetLength(RL2,7,y);
   maxRL1:=d0;
   minRL1:=e0;
  for j:=0 to y-1 do
   for k:=0 to 6 do
  begin
    RL2[k,j]:=(e0+0.5*d0)/(RL1[k,j]+0.5*d0);
  end;
  sum1:=0;
  for j:=0 to y-1 do
   for k:=0 to 6 do
  begin
    sum1:=sum1+RL2[k,j];
  end;
  a1:=sum1/7*y;
//*************************
  SetLength(RV1,8,y);
  for j:=0 to y-1 do
   for k:=0 to 7 do
  begin
    RV1[k,j]:=V[k]-wa[j];
  end;
  f0:=0;
  g0:=0;
  for j:=0 to y-1 do
   for k:=0 to 7 do
   begin
     if RV1[k,j]>=f0 then
     f0:=RV1[k,j];
     if RV1[k,j]<=g0 then
     g0:=RV1[k,j];
   end;
   SetLength(RV2,8,y);
   maxRV1:=f0;
   minRV1:=g0;
  for j:=0 to y-1 do
   for k:=0 to 7 do
  begin
    RV2[k,j]:=(g0+0.5*f0)/(RV1[k,j]+0.5*f0);
  end;
  sum2:=0;
  for j:=0 to y-1 do
   for k:=0 to 7 do
  begin
    sum2:=sum2+RV2[k,j];
  end;
  a2:=sum2/7*y;
//*************************
  SetLength(RD1,m,y);
  for j:=0 to y-1 do
   for k:=0 to m-1 do
  begin
    RD1[k,j]:=d[k]-wa[j];
  end;
  h0:=0;
  i0:=0;
  for j:=0 to y-1 do
   for k:=0 to m-1 do
   begin
     if RD1[k,j]>=h0 then
     h0:=RD1[k,j];
     if RD1[k,j]<=i0 then
     i0:=RD1[k,j];
   end;
   SetLength(RD2,m,y);
   maxRD1:=h0;
   minRD1:=i0;
  for j:=0 to y-1 do
   for k:=0 to m-1 do
  begin
    RD2[k,j]:=(i0+0.5*h0)/(RD1[k,j]+0.5*h0);
  end;
  sum3:=0;
  for j:=0 to y-1 do
   for k:=0 to m-1 do
  begin
    sum3:=sum3+RD2[k,j];
  end;
  a3:=sum3/m*y;
//******************************
  SetLength(AA2,3);
  j0:=a1+a2+a3;
  AA2[1]:=a1/j0;
  AA2[2]:=a2/j0;
  AA2[3]:=a2/j0;
//********************************************
  SetLength(AL,7);
  SetLength(AV,8);
  SetLength(AD,m);
  SetLength(BL,y);
  SetLength(BV,y);
  SetLength(BD,y);
  SetLength(R2,3,y);
  SetLength(B2,y);
  SetLength(B3,y);
  SetLength(fina,n);
  for i:=0 to n-1 do
  begin
   for k:=0 to 5 do
   begin
    if (Le[i]>=L[k]) and (Le[i]<=L[k+1]) then
     AL[k]:=1-abs(Le[i]-L[k])/5;
     AL[k+1]:=1-abs(Le[i]-L[k+1])/5;
   end;
   for k:=0 to 6 do
   begin
     if (Ve[i]>=V[k]) and (Ve[i]<=V[k+1]) then
     AV[k]:=1-abs(Ve[i]-V[k])/5;
     AV[k+1]:=1-abs(Ve[i]-V[k])/5;
   end;
   for k:=0 to m-1 do /
   begin
     if (dat[i]>=d[k]) and (dat[i]<=d[k+1]) then
     AD[k]:=1-abs(dat[i]-d[k])/SD;
     AD[k+1]:=1-abs(dat[i]-d[k])/SD;
   end;
   BL[0]:=0;
   BV[0]:=0;
   BD[0]:=0;
   for j:=0 to y-1 do
   begin
    for k:=0 to 6 do
    begin
     BL[j]:=BL[j]+AL[k]*RL[k,j];
    end;
    for k:=0 to 7 do
    begin
     BV[j]:=BV[j]+AV[k]*RV[k,j];
    end;
    for k:=0 to m-1 do
    begin
     BD[j]:=BD[j]+AD[k]*RD[k,j];
    end;
   end;
   for j:=0 to y-1 do
   begin
     R2[0,j]:=BL[j];
     R2[1,j]:=BV[j];
     R2[2,j]:=BD[j];
   end;
   sum4:=0;
   sum5:=0;
   sum6:=0;
   for j:=0 to y-1 do
   begin
    for k:=0 to 2 do
    begin
      sum6:=sum6+AA2[K]*R2[k,j];
    end;
     B2[j]:=sum6;
     B2[j]:=B2[j]*B2[j];
     sum4:=sum4+B2[j];
     B3[j]:=wa[j]*B2[j];
     sum5:=sum5+B3[j];
   end;
   fina[i]:=sum5/sum4;
  end;
  SetLength(B4,n);
  for i:=0 to n-1 do
  begin
    B4[i]:=W[i]+fina[i];
  end;
  CloseFile(myfile);
  result(fina);
end;

procedure TForm1.Result(fina:array of Double);
var  rf:TextFile;
      i:Integer;
      str0,str1,str2,str3,ok:string;
begin
  Rewrite (rf,extractfilepath(Application.ExeName)+'out.txt');
  Writeln(rf,'**'+'              '+'**'+'         '+'**'+'        '+'**');
  str0:='';str1:='';str2:='';str3:='';
     for i:=0 to n-1 do
    begin
      str0:=DateToStr(da[i]);
      str1:=FormatFloat('0.0000',W[i]);
      str2:=FormatFloat('0.0000',B4[i]);
      str3:=FormatFloat('0.0000',fina[i]);
      ok:='#'+str0+';'+'       '+str1+';'+'       '+str2+';'+'       '+str3+';';
      Writeln(rf,ok);
    end;
   CloseFile(rf);
  Application.Terminate;
end;

procedure TForm1.FormCreate(Sender: TObject);
var ff:string;
begin
 ff:=extractfilepath(Application.ExeName)+'test.txt';
 if FileExists(ff) then
  begin
    btn1Click(Sender);
  end
 else
  application.Terminate;
end;

end.
搜索更多相关主题的帖子: project class operation message stopped 
2011-08-29 10:41
maomao862532
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-29
收藏
得分:0 
问题已经自己解决,收贴
2011-08-29 16:04
zhang402
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-4-23
收藏
得分:0 
回复 2楼 maomao862532
怎么解决的?
2016-05-17 16:12
快速回复:求助——delphi程序结束时‘无效指针’的提示
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018302 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved