这是我点击时得到的错误btnInfoClick
调试器异常通知
Project_PAT_Phase_3.exe 引发异常类 EAccessViolation,并带有消息“模块 'Project_PAT_Phase_3.exe 中地址 004047E0 的访问冲突”“读取地址 00000022”。
程序运行顺利,没有任何错误,直到我单击代码中所示的按钮。请感谢您的帮助。
unit Navigation;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, InfoPopUp;
type
Tvector = Array[1..14] of string;
TFrmNavigation = class(TForm)
btnVote: TButton;
RdgInfo: TRadioGroup;
Label2: TLabel;
btnInfo: TButton;
procedure btnInfoClick(Sender: TObject);
private
public
MyFile : TextFile;
sLine : string;
sArrayParty : Tvector;
end;
var
FrmNavigation: TFrmNavigation;
implementation
procedure TFrmNavigation.btnInfoClick(Sender: TObject);
var
K : integer;
iCheck : integer;
begin
FrmInfo.Visible := true;
K := 1;
iCheck := 0;
if FileExists('PartyInfo.txt') <> True
then
begin
MessageDlg('File does not exist',mtError,[mbOK],0);
Exit;
end;// end of If statement
AssignFile(MyFile,'PartyInfo.txt');
Reset(MyFile);
while NOT eof(MyFile) do
begin
Inc(K);
Readln(MyFile,sLine);
sLine := sArrayParty[K];
end;//end of While
closefile(MyFile);
case RdgInfo.ItemIndex of
0 : begin
FrmInfo.Caption := 'African Christian Democratic Party (ACDP)';
FrmInfo.redOutput.Text := sArrayParty[1];
end;
1 : begin
FrmInfo.Caption := 'African National Congress (ANC)';
FrmInfo.redOutput.Text := sArrayParty[2];
end;
end;
下面的最后一个end.
是错误在代码中弹出的位置,但它在项目单元中,这很奇怪,因为当我有一个断点时,异常会在 while 循环处停止程序。
program PAT_Phase_3;
uses
Forms,
WelcomePage in 'WelcomePage.pas' {frmWP},
Navigation in 'Navigation.pas' {FrmNavigation},
InfoPopUp in 'InfoPopUp.pas' {FrmInfo};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TfrmWP, frmWP);
Application.CreateForm(TFrmNavigation, FrmNavigation);
Application.CreateForm(TFrmInfo, FrmInfo);
Application.Run;
end.