常駐Exe(1年中立ち上げっぱなしのExe)で
1.特定の時間になると、メインフォームの画面Aから画面Bを自動的に表示。
2.画面Bで処理を実行。
3.処理終了後に画面Bを自動的に閉じる。
の処理を行いたいのですが、画面Bが閉じない事象が発生して困っています。
常に発生せず、今までに6回中、2回発生しています。
閉じない状態の画面Bの右上の×ボタン(ウィンドウを閉じるボタン)を押すと
「モジュール'xxx'のアドレスxxxxxxxxでアドレスxxxxxxxxに対する読み込み違反がおきました。」
画面B上の2つのボタンを押すと
「無効なポインタ操作」
「不正な引数が渡されました」
とエラーメッセージが表示されます。
画面Bを閉じることができず、Exeを終了するしかありません。
原因を教えて下さい。
バージョン:Delphi7 Enterprise
以下、ソースの概略です。
■UnitA;(画面A)
procedure TFormA.OpenB;
if FormB = nil then begin
// コンストラクタ
FormB := TFormB.CreateForm(Application);
FormB.Main;
■UnitB(画面B)
var
FormB: TFormB;
implementation
constructor TFormB.CreateForm(Owner: TComponent ;);
Create (Owner);
procedure TFormB.Main;
(* 画面Bで行う処理 *)
FormB.Close;
// TFormBのOnCloseイベント
procedure TFormB.FormClose(Sender: TObject; var Action: TCloseAction);
FormB := nil;
Action := caFree;
>procedure TFormB.FormClose(Sender: TObject; var Action: TCloseAction);
> FormB := nil;
> Action := caFree;
イベントハンドラ内で自分自身をFree または nil とすると、そのようなエラーに悩まされることもあります。
フォームを破棄するには Release すべきです。
OnClose イベントハンドラのなかで Action := caFree; の場合は Release が
呼ばれます。エラーは、閉じる動作ではなく、何か別の処理のせいでしょう。
ツイート | ![]() |