سؤال

I've got an old Delphi 7 application that, after some changes, gives the message "Access violation ... in 'ntdll.dll' ... " The message is repeated 4 times, and probably means that Windows is unable to paint something: then after that everything works correctly.

The actual line that triggers the messages is:

Tester.FormTester.Parent := main.FormMain.TesterSheet;

After the error messages, the parent is set correctly, and

  Tester.FormTester.Align := alClient;

works correctly, aligning FormTester to the client area of TesterSheet.

FormTester is created previously, but is not visible. Making it visible first does not fix the problem. TesterSheet is created previously, but is not visible. Using any other parent (other than Nil) does not fix the problem. Waiting does not fix the problem. Moving between Win7 and WinXP does not change the problem.

Running in the Delphi IDE, I get only the same error, which the IDE catches and shows as an exception. When I proceed through the exception (trace into), I get the same error messge box as before. (repeat exception/message)

What is the cause of this problem? What is the suggested solution?

هل كانت مفيدة؟

المحلول 2

As suggested in the comments, I 'checked every form and component'. I already knew that it wasn't an event property that was causing the problem, since I was already familiar with all events.

But I did find two combo-boxes that I did not expect to see.

As discussed at Empty string in Delphi / Windows combo box causes access exception, there is a known problem with Delphi 7.0 combo-boxes that causes a access-violation error when you access an empty line: http://qc.embarcadero.com/wc/qcmain.aspx?d=2246.

For no obvious reason, this known problem was triggered when the parent of the form was set.

Possible solutions include removing the combobox, patching the library, applying the 7.1 service pack, or upgrading.

In this case, the problem was resolved by removing the empty lines from the default string list of the combo-box.

نصائح أخرى

I'd need to see more code than you've posted to be sure, but the following code has been working for me in several applications for years :-

Procedure TfrmMain.ShowInPanel(pForm : TForm);
Begin
  If Assigned(FCurrForm) Then
    FCurrForm.Close;
  With pForm Do
  Begin
    FCurrForm := pForm;
    Parent := pnlMain; // pnlMain is the panel where the form is shown
    BorderStyle := bsNone;
    Align := alClient;
    Show;
    Update;
  End;
End;

It's then called like this :-

lfrmCategories := TfrmCategories.Create(pnlMain);
ShowInPanel(lfrmCategories);

Hopefully this will help you solve the problem.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top