Link to home
Start Free TrialLog in
Avatar of kingpreetham
kingpreetham

asked on

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.
Avatar of andrewjb
andrewjb
Flag of United Kingdom of Great Britain and Northern Ireland image

Nothing obvioulsy wrong in those lines. Must be something in the form. Anything in the OnClose event?
Avatar of kingpreetham
kingpreetham

ASKER

no, there is an event on the OnCreateEvent, but nothing OnDestroy or OnClose...
Avatar of kretzschmar
try to use

Form->Release();

instead of

Form->free();

meikl ;-)
oops, c is casesensitive, could be also release
Are you creating any threads or anything like that? Sounds to me like a memory leak or memory overwrite issue.
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.
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.
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.
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?
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.
How is the data being sent to the form?
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
why does a.exe use a thread to communicate with the OCX file?
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..
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.
what if UpdateGui is from another unit.
ASKER CERTIFIED SOLUTION
Avatar of Stefaan
Stefaan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks  Stefaan, i created a Synchronised method and called it from there....it worked.
Glad I could help you out :-)