これは、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.