Вопрос

Access violation at address 004295A6 in module 'frameprj.exe'. Read of address 6432FF68.

I Use Delphi2007 and I want to build an app which contains a form, a advtoolbar, advofficepager and a mainmenu. Based on what button from MainMenu I Click a different Menu should load on the AdvToolBar and a page should be created if it doesn't exists or should be set as active page if it exists. The problem is after creating the pages when I click on a MainManu item again I get this error, and It looks like i get it because of the AdvToolBar.Menu := Menu; line of code.

Here is the code.

unit framepage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, frameFunctii, framePersone, AdvOfficePager,
  Menus, AdvToolBar;

type
  TForm1 = class( TForm )
    AdvOfficePager1 : TAdvOfficePager;
    MainMenu1 : TMainMenu;
    Personal1 : TMenuItem;
    Functii1 : TMenuItem;
    Exit1 : TMenuItem;
    Adaugare1 : TMenuItem;
    Inspectare1 : TMenuItem;
    AdvToolBar1 : TAdvToolBar;

    procedure Exit1Click( Sender : TObject );
    procedure Personal1Click( Sender : TObject );
    procedure Inspectare1Click( Sender : TObject );
    procedure Adaugare1Click( Sender : TObject );
    procedure AdvOfficePager1ClosedPage( Sender : TObject; PageIndex : Integer );
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1 : TForm1;


implementation

{$R *.dfm}

uses
  DataModule, frameAdaugareFunctie;

procedure TForm1.Personal1Click( Sender : TObject );

var
  fp : TFrame2;
  AdvOfficePager11 : TAdvOfficePage;
  i : Integer;
  gasit : boolean;
begin
  gasit := False;
  AdvToolBar1.Menu := nil;
  for i := 0 to AdvOfficePager1.AdvPageCount - 1 do
    begin
      if AdvOfficePager1.AdvPages[i].Caption = 'Personal'
      then
        begin
          AdvOfficePager11 := AdvOfficePager1.AdvPages[i];
          AdvToolBar1.Menu := fp.MainMenu1;
          gasit := True;
        end;
    end;
  if not gasit
  then
    begin
      AdvOfficePager11 := TAdvOfficePage.Create( AdvOfficePager1 );
      AdvOfficePager11.Caption := 'Personal';
      fp := TFrame2.Create( AdvOfficePager11 );
      fp.Parent := AdvOfficePager11;
      fp.Align := alClient;
      AdvOfficePager11.ShowClose := True;
      AdvOfficePager1.AddAdvPage( AdvOfficePager11 );
      AdvOfficePager1.ButtonSettings.CloseButton := True;
      AdvToolBar1.Menu := fp.MainMenu1;
    end;

  AdvOfficePager1.ActivePage := AdvOfficePager11;

end;

procedure TForm1.Adaugare1Click( Sender : TObject );

var
  frmAdgFct : TframeAdgFunctie;
  AdvOfficePager13 : TAdvOfficePage;
  i : Integer;
  gasit : boolean;
begin
  gasit := False;
  for i := 0 to AdvOfficePager1.AdvPageCount - 1 do
    begin
      if AdvOfficePager1.AdvPages[i].Caption = 'Adaugare functie'
      then
        begin
          AdvOfficePager13 := AdvOfficePager1.AdvPages[i];
          gasit := True;
        end;
    end;
  if not gasit
  then
    begin
      AdvOfficePager13 := TAdvOfficePage.Create( AdvOfficePager1 );
      AdvOfficePager13.Caption := 'Adaugare functie';
      frmAdgFct := TframeAdgFunctie.Create( AdvOfficePager13 );
      frmAdgFct.Parent := AdvOfficePager13;
      frmAdgFct.Align := alClient;
      AdvOfficePager13.ShowClose := True;
      AdvOfficePager1.AddAdvPage( AdvOfficePager13 );
      AdvOfficePager1.ButtonSettings.CloseButton := True;
    end;
  AdvOfficePager1.ActivePage := AdvOfficePager13;

end;

procedure TForm1.AdvOfficePager1ClosedPage( Sender : TObject; PageIndex : Integer );
begin
  AdvToolBar1.Menu := nil;
end;

procedure TForm1.Exit1Click( Sender : TObject );
begin
  DataModule1.Free;
  Form1.Close;
end;

procedure TForm1.Inspectare1Click( Sender : TObject );
var
  ff : TFrame1;
  AdvOfficePager12 : TAdvOfficePage;
  i : Integer;
  gasit : boolean;
begin
  AdvToolBar1.Menu := nil;
  gasit := False;
  for i := 0 to AdvOfficePager1.AdvPageCount - 1 do
    begin
      if AdvOfficePager1.AdvPages[i].Caption = 'Functii'
      then
        begin
          AdvOfficePager12 := AdvOfficePager1.AdvPages[i];
          AdvToolBar1.Menu := ff.MainMenu1;
          gasit := True;
        end;
    end;
  if not gasit
  then
    begin
      AdvOfficePager12 := TAdvOfficePage.Create( AdvOfficePager1 );
      AdvOfficePager12.Caption := 'Functii';
      ff := TFrame1.Create( AdvOfficePager12 );
      ff.Parent := AdvOfficePager12;
      ff.Align := alClient;
      AdvOfficePager12.ShowClose := True;
      AdvOfficePager1.AddAdvPage( AdvOfficePager12 );
      AdvOfficePager1.ButtonSettings.CloseButton := True;
      AdvToolBar1.Menu := ff.MainMenu1;
    end;

  AdvOfficePager1.ActivePage := AdvOfficePager12;

end;

end.
Это было полезно?

Решение

At this line

AdvToolBar1.Menu := fp.MainMenu1;

in TForm1.Personal1Click, the variable fp has not been initialised.

Furthermore, at this line

AdvToolBar1.Menu := ff.MainMenu1;

in TForm1.Inspectare1Click, the variable ff has not been initialised.

You must initialise variables before you attempt to use them.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top