[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

From Brazil, bug in Delphi Studio Enterprise 7.0???

Excuse my English :)

I am developing a Mdi-Clx application and when creating the forms I am receiving the message, at some moments : "Invalid Pointer Operation"

The code for creation of the forms is:

if (nameform = nil) then
     nameform := Tnameform.Create(Application);
else
  begin
      nameform.windowstate := wsnormal;
      nameform.bringtofront;
  end;

When closing: (OnClose)

  nameform := nil;
  Action := caFree;

The Borland of Brazil does not know to answer which is the problem, somebody knows?
0
lucarval
Asked:
lucarval
  • 3
  • 3
  • 2
  • +5
1 Solution
 
mocartsCommented:
you must paste (or place somewhere) all original code to allow analyze us it completely (code you provided will not compile as there is ; before else ;).
there can be many possibilities of exception raised depending on when form is created (onTimer etc.), when destroyed. what happens onDestroy?

wbr, mo.
0
 
j42Commented:
> When closing: (OnClose)
>  nameform := nil;
>  Action := caFree;

I suppose you are using an instance (nameform) in the definition of your class (Tnameform). This will work as long as you have just one instance.



Regards
J
0
 
lucarvalAuthor Commented:
Excuse my (;), for each form I use a name (nameform, tnameform), (nameform1,tnameform1), (nameform2,tnameform2), the code:

In the Onclick event of main form MDI-CLX:

procedure TForm1.bitbtn1click(Sender : TObject);
begin
  if (nameform = nil) then
  begin
      nameform := Tnameform.Create(Application);
  end
  else
  begin
      nameform.windowstate := wsnormal;
      nameform.bringtofront;
  end;
end;

In the OnClose event of forms MDI-CLX:

procedure TForm1.Form1OnClose(Sender : TObject;
Var Action : TCloseAction);
begin
  nameform := nil;
  Action := caFree;
end;

The message "Invalid Pointer Operation" appears at any time, in aplicacoes that possess more than four forms and after to open and to close the forms vary times the forms.

0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
mocartsCommented:
this code doesn't clear the question :)

procedure TForm1.Form1OnClose(Sender : TObject;
Var Action : TCloseAction);
is this a main form's OnClose event handler? (as TForm1 involved in declaration..)

is nameform global var?
is there other places where you use nameform variable?
and what is the reason to use Application as Owner for newly created forms (instead of Self)?

wbr, mo.
0
 
kretzschmarCommented:
the problem is here

 nameform := nil;

you cannot simple nil an object,
you must destroy it
(usually this notifies also other objects,
like the parent or the owner)
 
use instead

FreeAndNil(nameForm);

if the nil is not needed for comparing,
then i prefer
nameform.release; //but this will not nil the variable nameform

meikl ;-)

0
 
lucarvalAuthor Commented:
Form1 is the MDI-CLX main form and nameform, nameform2, nameform3 are the MDI-CLX form child, already I tried with .self and the same message "Invalid Pointer Operation" occur.

                       Form1 (TForm1)
                             |
              ----------------------------------
              |          |         |           |
           nameform  nameform1  nameform2   nameform3
0
 
tkalchevCommented:
The problem is here :

When closing: (OnClose)

 nameform := nil;
 Action := caFree;


Action := caFree is ENOUGH to free the variable. This internally will try to make nameform.Free and when nameform is nil it will fail of course. Leave only Action := caFree;
0
 
mocartsCommented:
if all child windows are with FormStyle := fsMDIChild;  then it's already in MainForm's (FormStyle := fsMDIForm) MDIChildren collection.

type
  // main form
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure ShowChildForm(FormClass: TFormClass);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses Unit2; // contains child form

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowChildForm(TForm2);
end;

procedure TForm1.ShowChildForm(FormClass: TFormClass);
var
  i: integer;
begin
  for i := 0 to self.MDIChildCount -1 do
    if MDIChildren[i] is FormClass then
    begin
      MDIChildren[i].WindowState := wsNormal;
      MDIChildren[i].BringToFront;
      exit;
    end;
  // not found - then create
  with FormClass.Create(Self) do
    Show;
end;


hint: in this case you can use one event handler for all buttons..
then you only need to assign button tags in main form's onCreate to apropriate class:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Tag := integer(TForm2);
  ..
  ButtonN.Tag := integer(TFormN);
end;

and Buttons OnClick event handlers point to:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowChildForm(TFormClass(TComponent(Sender).Tag));
end;

wbr, mo.
0
 
SteveWaiteCommented:
try something like this instead!

try
  nameform.windowstate := wsnormal;
  nameform.bringtofront;
except
  nameform := Tnameform.Create(Application);
end;

Regards
Steve
0
 
lucarvalAuthor Commented:
Eureka!!!

The problem was decided, who was causing was the component ToolBar, I removed of the project and functioned correctly.

Thanks.
0
 
kretzschmarCommented:
puh, guessing no one guessed that ;-)

glad you got it work

meikl ;-)
0
 
CleanupPingCommented:
lucarval:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
moduloCommented:
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now