Odwołanie do innej formy, access violation-ale czemu?

0

Witam,
chcę żeby program po uruchomieniu sprawdził w rejestrze czy użytkownik zapisał w nim hasło, czy może ma się o nie zawsze pytać po uruchomieniu. Zrobiłem prostą foremkę, z jednym TEdit i TButton. Tylko że cokolwiek bym nie chciał zrobić z tą małą formą, zawsze mam:

Debugger Exception Notification
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0046ED1E in module 'Project1.exe'. Read of address 000002FC'. Process stopped. Use Step or Run to continue.

Kod Form1 wygląda mniej-więcej tak:

{$I mysqlinc.inc}

unit Unit1;

interface

uses
  Unit2, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, Spin, uMysqlVio, uMysqlCT,
  uMysqlClient, uMysqlHelpers, Registry;

type
  TForm1 = class(TForm)
 { ... komponenty ... }
    procedure SQLReconnectAndSaveClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  MySQLClient: TMySQLClient;
  Registry: TRegistry;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Registry:=TRegistry.Create;
  MySQLClient:=TMySQLClient.create;

  if(Registry.OpenKey('Firma', true)) then
    begin
{ ... }
      if(Registry.ReadBool('SQLPassAskAtStart')) then
        begin
          SQLPassAskAtStart.Checked:=True;


          Form2.Button1.Caption:='Hello';		{ <<<=== tą linię zaznacza delphi na niebiesko }


        end
      else
        begin
          SQLPassAskAtStart.Checked:=False;
          SQLPass.Text:=Registry.ReadString('SQLPass');
        end;
 { ... }
    end
  else ShowMessage('Nie udało się otworzyć rejestru!');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MySQLClient.close;
StatusBar1.Panels.Items[0].Text:='Stan MySQL: Rozłączony';

MySQLClient.Free;
Registry.Free;
end;

end.

Tym bardziej jestem sfrustrowany, że niedawno pisałem inny program, gdzie odwołania do innych form robiłem identycznie...

pozdrawiam
Paweł Lis

0

Prawdopodobnie OnCreate Form1 uruchamiane jest przed utworzeniem Form2. Zamień kolejność tworzenia form w pliku dpr albo twórz Form2 dynamicznie wedle potrzeb.

0

Też w końcu na to wpadłem. Trochę przerobiłem program tak że Form2 samo teraz zaczyna to co do niego należy.

1 użytkowników online, w tym zalogowanych: 0, gości: 1