Solved

Form not closong, freezes...important..help

Posted on 2003-12-10
19
384 Views
Last Modified: 2010-04-05
I have the following code..
Form = new TfrmABC(NULL);
...some methods to load form data n stuff
do a ShowModal() for the form
i close dn return, then i do
Form->free();
This is where i am having a problem. The form fails to destroy and freezes
I get no error message.

While using debug, i get the message
Access voilation in module...'bordbk61.dll'. Read of address...

I have no event on the FormDestroy event

What can cause such a problem.

Appreciate the help.

Thanks,
Preetham.
0
Comment
Question by:kingpreetham
  • 8
  • 4
  • 3
  • +3
19 Comments
 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
Nothing obvioulsy wrong in those lines. Must be something in the form. Anything in the OnClose event?
0
 

Author Comment

by:kingpreetham
Comment Utility
no, there is an event on the OnCreateEvent, but nothing OnDestroy or OnClose...
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
try to use

Form->Release();

instead of

Form->free();

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
oops, c is casesensitive, could be also release
0
 
LVL 2

Expert Comment

by:Robn
Comment Utility
Are you creating any threads or anything like that? Sounds to me like a memory leak or memory overwrite issue.
0
 
LVL 8

Expert Comment

by:gmayo
Comment Utility
Try:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
      Action := caFree;
end;

So the form frees itself rather than you doing it manually.

Geoff M.
0
 

Author Comment

by:kingpreetham
Comment Utility
I tried Form->Release();, there is no problem executing the Release, but then there
is transfer control to the FormDestroy method, there is nothing it does..however it hangs
at the end of execution of this method....
I am using threads, but not creating a thred in this form..
I have obj A creating a thread calling a function in obj B.
obj B creates the form and destroys it.
0
 

Author Comment

by:kingpreetham
Comment Utility
EDIT:I have obj A creating a thread calling a function in obj B.
I have obj A creating a thread. This thread sends a message which is caught in a function in obj B.
0
 
LVL 2

Expert Comment

by:Robn
Comment Utility
Does the form interact with the thread at all, or does the thread interact with the form aside from creating and destroying it? Is it a modal form? Are you waiting on this threads at all?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kingpreetham
Comment Utility
let me put it in more detail.
I have a.exe and b.ocx
a.exe starts a thread that sends messages.
b.ocx has a callback that activates upon receiving a message.
first, b.ocx creates the form(modal) it then waits for data from
the exe. After it got all the data, it waits until the user closes the
form.
When the user closes the form, it hangs.
0
 
LVL 2

Expert Comment

by:Robn
Comment Utility
How is the data being sent to the form?
0
 

Author Comment

by:kingpreetham
Comment Utility
th exe calls a method of the ocx...the ocx gets the data, it then uses a CopyToObject interface to copy the data to the controls on the form
0
 
LVL 2

Expert Comment

by:Robn
Comment Utility
why does a.exe use a thread to communicate with the OCX file?
0
 

Author Comment

by:kingpreetham
Comment Utility
i dont want the form to wait for all the data to open, i open the form and populate the controls as the thread passes data to it...
this is coz some of the controls are hidden in tabs of the form and need not be loaded when displaying the form initially..
0
 
LVL 3

Expert Comment

by:Stefaan
Comment Utility
Hm, tough one, when your Thread updates the controls on the form, make sure that all the Form updates are in a procedure and you call it using a Synchronise.

Example, I have a thread which updates the caption of a button, so I make a UpdateGui method on my thread :

procedure TMyThread.UpdateGui;
begin
  // I passed the button that needs to be updated to the constructor,
  // or you could also create a property for it and set the property
  // when you create the Thread.
  FButton.Caption := 'New Caption';
end;

procedure TMyThread.Execute;
var
  lcv : Integer;
begin
  For lcv := 0 to 999 do
  begin
    // Do Some Stuff

    // Update the Gui
    Synchronise( UpdateGui );
  end;
end;


Everytime you make an update to the Gui from within your thread you should use the Synchronise, since the complete VCL isn't fully thread safe.
0
 

Author Comment

by:kingpreetham
Comment Utility
what if UpdateGui is from another unit.
0
 
LVL 3

Accepted Solution

by:
Stefaan earned 240 total points
Comment Utility
Well, then that might be your problem.  I wouldn't know how to solve it correctly, but you might try to call that method from within a Synchronised method of your thread.

0
 

Author Comment

by:kingpreetham
Comment Utility
Thanks  Stefaan, i created a Synchronised method and called it from there....it worked.
0
 
LVL 3

Expert Comment

by:Stefaan
Comment Utility
Glad I could help you out :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now