Link to home
Start Free TrialLog in
Avatar of Norm-al
Norm-alFlag for United States of America

asked on

Access Violation at ShowModal in Delphi

I have a grid that double clicks to launch a form. This form is launched from another grid with no problems but from this particular form, I keep getting an access violation... The grid that launches this form with no problems is saved in the same location as the form whereas this grid getting problems is saved in a different folder. That should not matter right?
procedure TfrmStories.gvErrorListDblClick(Sender: TObject);
var vRecIdx, vErrorNo: Variant;
begin
  inherited;
  if gvErrorList.Controller.SelectedRecordCount < 1 then begin
    MessageDlg('Please select a record to edit', mtError, [mbOK], 0);
    Abort;
  end;
  Screen.Cursor := crSQLWait;   // cursor wait
  frmErrorDataEntry1 := TfrmErrorDataEntry1.Create(Self);
  with frmErrorDataEntry1 do begin
    sDataEntryMode := 'EDIT';
    sJobnum      := TcxGridDBTableView(Self.level1.GridView).DataController.dataset.FieldValues['Jobnum'];
    sPart        := TcxGridDBTableView(Self.level1.GridView).DataController.dataset.FieldValues['Part'];
    sErrorID     := TcxGridDBTableView(Self.level1.GridView).DataController.dataset.FieldValues['ErrorID'];
    sCaller := 'GMERRORREPORTING';  // define the calling form
    sDataEntryMode := 'EDIT';
    ShowModal;
    Screen.Cursor := crArrow;
  end;
  FreeAndNil(frmErrorDataEntry1);
  gvErrorList.DataController.RefreshExternalData;
end;

Open in new window

Avatar of phadar
phadar

Do you get your AV when the form is created, shown or closed?
Regardless, you need to call "Screen.Cursor := crArrow;" before "Showmodal"
Avatar of Norm-al

ASKER

during debug, from ShowModal, it goes to the form's FormCreate then jumps back to ShowModal and gets the error.
Avatar of Norm-al

ASKER

It never makes it to FormShow on the form I'm trying to launch... makes me wonder if its because the form is saved in a different location?
You might have a component(s) on that form causing your AV. Try to remove all the components on that form, comment any codes related to those components so you won't have any compiler error and start running by putting back components one at a time until you'll find the one.
Avatar of Norm-al

ASKER

components on calling form or the form I am trying to show?
ASKER CERTIFIED SOLUTION
Avatar of phadar
phadar

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
Avatar of Norm-al

ASKER

I got past the AV by removing a line in the code that referred to a form that was no longer being used but now I get a different exception. The form comes up but I get this error:

Additional Error Message: Key value for this row was changed or deleted at the data store. The local row is now deleted
It looks like you have 2 different origins dealing with the same record of a dataset.
Is there any relevant code in the forms OnShow, OnActivate, or OnPaint event handlers?

Sometimes the debugger will skip over those unless you explicitly set a breakpoint inside them. Have a look at the events that have been coded for this form in the Object Inspector.

I would advise not deleting any code, just comment it out temporarily.

You should be able to fix the AV without introducing new errors by deleting code.

You can use if Assigned(Object_Name) to check if an object is accessible at that point of time.

It might also help to understand the history of this task. Was it working yesterday and has now stopped working?
Access Violation is caused when you have Variable is pointing to an garbage value and a proper object.
You must be include the required form in implementation part try to open that by double click from code.\
IF that opening than the connection is right.
if thats not form in not been seared by grid.