模块'frameprj.exe'中地址004295A6的访问冲突。读取地址6432FF68。
我使用Delphi2007,我想构建一个包含表单,advtoolbar,advofficepager和mainmenu的应用程序。基于来自MainMenu的按钮我单击一个不同的菜单应加载到AdvToolBar上,如果页面不存在则应创建一个页面,如果存在,则应设置为活动页面。问题是当我再次点击MainManu项目创建页面后,我收到此错误,看起来我得到它是因为AdvToolBar.Menu := Menu;
代码行。
这是代码。
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.
答案 0 :(得分:2)
在这一行
AdvToolBar1.Menu := fp.MainMenu1;
在TForm1.Personal1Click
中,变量fp
尚未初始化。
此外,在这一行
AdvToolBar1.Menu := ff.MainMenu1;
在TForm1.Inspectare1Click
中,变量ff
尚未初始化。
在尝试使用变量之前,必须先初始化变量。