Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShowModal Exception

Status
Not open for further replies.

ThunderForest

IS-IT--Management
Mar 3, 2003
189
US
When this code runs, it works the first time, but an exception (EAccessViolation) occurs the second, etc. time when showModal is executed again, with or without the editBox value assignments. Code behind the two buttons on ccChangeForm is
Code:
modalResult := mrOK
and
Code:
modalResult := mrCancel
What am I missing?

Code:
If (ccChangeForm = nil) then begin
    ccChangeForm := TccChangeForm.Create(nil);
end;
ccChangeForm.oldThingNo.text := FormA.QueryA.fieldByName('Thing').asString;
ccChangeForm.oldDateReq.text := FormA.QueryA.fieldByName('DateRequested').asString;
ccChangeForm.showModal;
ccChangeForm.free;

Getting answers before I'm asked.
Providing answers if I can.
 
Freeing the form does not reset the variable ccChangeForm. It still has the original value, so second time through the form is not created and the reference is to memory that has been reused.

after
ccChangeForm.free;
insert
ccChangeForm := nil;

Also take a look at the FreeAndNil function.

 
The freeAnNil functions looks good too. All I can say is to quote Homer Simpson: "Do-ooh". Thanks.

Getting answers before I'm asked.
Providing answers if I can.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top