?
Solved

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

Posted on 2003-03-31
14
Medium Priority
?
317 Views
Last Modified: 2010-04-04
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
Comment
Question by:lucarval
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +5
14 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 8238016
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
 
LVL 2

Expert Comment

by:j42
ID: 8238261
> 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
 

Author Comment

by:lucarval
ID: 8238401
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:mocarts
ID: 8238462
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8238495
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
 

Author Comment

by:lucarval
ID: 8238586
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
 
LVL 9

Expert Comment

by:tkalchev
ID: 8238693
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
 
LVL 9

Expert Comment

by:mocarts
ID: 8238706
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
 
LVL 3

Expert Comment

by:SteveWaite
ID: 8239401
try something like this instead!

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

Regards
Steve
0
 

Author Comment

by:lucarval
ID: 8239661
Eureka!!!

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

Thanks.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8239690
puh, guessing no one guessed that ;-)

glad you got it work

meikl ;-)
0
 

Expert Comment

by:CleanupPing
ID: 9316530
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10800723
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question