小编Dav*_*rew的帖子

设置数组(记录)长度时,Delphi堆栈溢出和访问冲突错误

我正忙着构建一个应用程序,我在其中读取来自更多两个"记录"文件的数据.我有一个非常奇怪的错误,根据我打开文件的顺序弹出(参见下面的代码).

如果我点击button1后跟按钮2,从而调用"天气数据记录"文件,然后是"参数记录"文件,一切都很好.如果我反过来这样做,我得到一个"堆栈溢出",然后是"0x7c90e898的访问冲突:写入地址"错误.当我在Button1Click中为数组调用SetLength时会发生这种情况.

天气数据文件有大约550条记录,参数文件大约有45条记录.

任何人都可以看到我的代码明显错误吗?如果有人想用它们来测试,我不知道如何附加文件或使它们可用...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Grids,FileCtrl,Contnrs;

type  
    TWeatherData = record  
    MyDate : TDate;  
    Rainfall : Double;  
    Temperature : Double;  

  end;

  TParameters = record
    Species : string[50];
    ParameterName: string[50];
    ParameterValue : double;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject); …
Run Code Online (Sandbox Code Playgroud)

stack-overflow arrays delphi

3
推荐指数
1
解决办法
4627
查看次数

标签 统计

arrays ×1

delphi ×1

stack-overflow ×1