John B
2008-08-03 22:05:33 UTC
Hello,
After I recompile my original D6 program in RDS2007, it crashes when closing
a sub form. However, the original executable works fine. I think this may
be related to either the new memory manager in RDS2007. In other words, the
MM may be doing something that has exposed a bug in my code not seen before.
Please help!!!
------
My program is based on an SDI template, but is designed similar to the D6
IDE, with the main form displaying just the menus and toolbars, which then
act upon whatever subform is active. To synch the ActionList on the active
subform with the one on the main form, I assign a custom event handler to
Screen.OnActiveFormChange in the OnCreate event handler of the main form:
procedure T_SDIMain.FormCreate(Sender: TObject);
begin
Screen.OnActiveFormChange := MyActiveFormChanged;
. . .
end;
In the MyActiveFormChanged procedure, I update a private variable of the
Main form to point to the active subform, then use this to call actions of
the appropriate subform based on the user clicking buttons/menus on the main
form:
Type
T_SDIMain = class(TForm)
Private
FActiveViewer : TmcBaseForm;
. . .
end;
procedure T_SDIMain.MyActiveFormChanged (Sender: TObject);
var i: integer;
begin //This code is critical to maintaining a proper link to the apps
baseforms
if (Screen.ActiveForm = Self) then
begin
if not Assigned(FActiveViewer) then
begin //for case when last ActiveViewer is closed
For i := 0 to Screen.FormCount-1 {downto 0} do
if (Screen.Forms[i] is TmcBaseForm) and
((Screen.Forms[i] as TmcBaseForm).Counted) then
begin
Screen.Forms[i].SetFocus; // changes active form to next
mcbaseform
break;
end;
end;
end else
if Screen.ActiveForm is TmcBaseForm then
begin
FActiveViewer := Screen.ActiveForm as TmcBaseForm;
end else
begin
FActiveViewer := nil;
end;
end;
I then use the Update method of the main form's TActionList to synch to
status of the Main form actions to those on the active subform:
procedure T_SDIMain.ActionList1Update(Action: TBasicAction; var Handled:
Boolean);
begin
if Assigned(FActiveViewer) and
(FActiveViewer is TmcBaseForm) then
begin
FActiveViewer.alBaseFormUpdate (Action, Handled); //Calls the update
method of the subform's TActionList
//Set Main actions to enable/disable toolbuttons and menus
actSavePic.Enabled := (FActiveViewer as
TmcBaseForm).actSavePic.Enabled;
actSaveCAD.Enabled := (FActiveViewer as
TmcBaseForm).actSaveCAD.Enabled;
actPrint.Enabled := (FActiveViewer as
TmcBaseForm).actPrint.Enabled;
actPrintPreview.Enabled := (FActiveViewer as
TmcBaseForm).actPrintPreview.Enabled;
end;
My application works fine until I attempt to close a form, after which I get
an Access violation on:
actSavePic.Enabled := (FActiveViewer as
TmcBaseForm).actSavePic.Enabled;
This occurs whether I comment out the line above it or not, nor can I use
the debugger to step through the code, since this involves the Update
method.
Any ideas would be greatly appreciated!!!
John
After I recompile my original D6 program in RDS2007, it crashes when closing
a sub form. However, the original executable works fine. I think this may
be related to either the new memory manager in RDS2007. In other words, the
MM may be doing something that has exposed a bug in my code not seen before.
Please help!!!
------
My program is based on an SDI template, but is designed similar to the D6
IDE, with the main form displaying just the menus and toolbars, which then
act upon whatever subform is active. To synch the ActionList on the active
subform with the one on the main form, I assign a custom event handler to
Screen.OnActiveFormChange in the OnCreate event handler of the main form:
procedure T_SDIMain.FormCreate(Sender: TObject);
begin
Screen.OnActiveFormChange := MyActiveFormChanged;
. . .
end;
In the MyActiveFormChanged procedure, I update a private variable of the
Main form to point to the active subform, then use this to call actions of
the appropriate subform based on the user clicking buttons/menus on the main
form:
Type
T_SDIMain = class(TForm)
Private
FActiveViewer : TmcBaseForm;
. . .
end;
procedure T_SDIMain.MyActiveFormChanged (Sender: TObject);
var i: integer;
begin //This code is critical to maintaining a proper link to the apps
baseforms
if (Screen.ActiveForm = Self) then
begin
if not Assigned(FActiveViewer) then
begin //for case when last ActiveViewer is closed
For i := 0 to Screen.FormCount-1 {downto 0} do
if (Screen.Forms[i] is TmcBaseForm) and
((Screen.Forms[i] as TmcBaseForm).Counted) then
begin
Screen.Forms[i].SetFocus; // changes active form to next
mcbaseform
break;
end;
end;
end else
if Screen.ActiveForm is TmcBaseForm then
begin
FActiveViewer := Screen.ActiveForm as TmcBaseForm;
end else
begin
FActiveViewer := nil;
end;
end;
I then use the Update method of the main form's TActionList to synch to
status of the Main form actions to those on the active subform:
procedure T_SDIMain.ActionList1Update(Action: TBasicAction; var Handled:
Boolean);
begin
if Assigned(FActiveViewer) and
(FActiveViewer is TmcBaseForm) then
begin
FActiveViewer.alBaseFormUpdate (Action, Handled); //Calls the update
method of the subform's TActionList
//Set Main actions to enable/disable toolbuttons and menus
actSavePic.Enabled := (FActiveViewer as
TmcBaseForm).actSavePic.Enabled;
actSaveCAD.Enabled := (FActiveViewer as
TmcBaseForm).actSaveCAD.Enabled;
actPrint.Enabled := (FActiveViewer as
TmcBaseForm).actPrint.Enabled;
actPrintPreview.Enabled := (FActiveViewer as
TmcBaseForm).actPrintPreview.Enabled;
end;
My application works fine until I attempt to close a form, after which I get
an Access violation on:
actSavePic.Enabled := (FActiveViewer as
TmcBaseForm).actSavePic.Enabled;
This occurs whether I comment out the line above it or not, nor can I use
the debugger to step through the code, since this involves the Update
method.
Any ideas would be greatly appreciated!!!
John