• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

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

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
kingpreetham
Asked:
kingpreetham
  • 8
  • 4
  • 3
  • +3
1 Solution
 
andrewjbCommented:
Nothing obvioulsy wrong in those lines. Must be something in the form. Anything in the OnClose event?
0
 
kingpreethamAuthor Commented:
no, there is an event on the OnCreateEvent, but nothing OnDestroy or OnClose...
0
 
kretzschmarCommented:
try to use

Form->Release();

instead of

Form->free();

meikl ;-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kretzschmarCommented:
oops, c is casesensitive, could be also release
0
 
RobnCommented:
Are you creating any threads or anything like that? Sounds to me like a memory leak or memory overwrite issue.
0
 
gmayoCommented:
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
 
kingpreethamAuthor Commented:
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
 
kingpreethamAuthor Commented:
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
 
RobnCommented:
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
 
kingpreethamAuthor Commented:
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
 
RobnCommented:
How is the data being sent to the form?
0
 
kingpreethamAuthor Commented:
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
 
RobnCommented:
why does a.exe use a thread to communicate with the OCX file?
0
 
kingpreethamAuthor Commented:
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
 
StefaanCommented:
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
 
kingpreethamAuthor Commented:
what if UpdateGui is from another unit.
0
 
StefaanCommented:
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
 
kingpreethamAuthor Commented:
Thanks  Stefaan, i created a Synchronised method and called it from there....it worked.
0
 
StefaanCommented:
Glad I could help you out :-)
0

Featured Post

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.

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