Board index » delphi » Access violation when accessing table from secondary form

Access violation when accessing table from secondary form

I have a form that creates a child form.  The child form has a uses clause
that references the parent.  The parent form has a table that I'd like to
reference from the child, but when I do, I get an AV.

Code is shown below, thanks for help!

Parent code:

procedure TForm1.button1click(sender:TObject);
var f: TFormChild;
begin
     f:=TFormChild.create(application);
     f.showmodal;
     f.release;
end;

Child code:

...
uses form1;
...
procedure TFormChild.button1click(sender: TObject);
begin
     formParent.table1.refresh;  // generates the AV
end;

 

Re:Access violation when accessing table from secondary form


There is one more detail on this.  Form1 shown below is actually a subform
from yet another form.  Thanks for help!
Quote
Bill Seven <b...@include.com> wrote in message news:3a606ff4$1_1@dnews...
> I have a form that creates a child form.  The child form has a uses clause
> that references the parent.  The parent form has a table that I'd like to
> reference from the child, but when I do, I get an AV.

> Code is shown below, thanks for help!

> Parent code:

> procedure TForm1.button1click(sender:TObject);
> var f: TFormChild;
> begin
>      f:=TFormChild.create(application);
>      f.showmodal;
>      f.release;
> end;

> Child code:

> ...
> uses form1;
> ...
> procedure TFormChild.button1click(sender: TObject);
> begin
>      formParent.table1.refresh;  // generates the AV
> end;

Re:Access violation when accessing table from secondary form


Bill, my guess is that the problem is in the parentForm.  Is that a
function you wrote to get a reference to self.parent?  It might be
returning nil, so try puttin in an assert statement to see if this is
the case:

  assert(parentForm <> nil);
  parentForm.Table1.Refresh;

Hope that helps,
Leo

Quote
Bill Seven wrote:
> There is one more detail on this.  Form1 shown below is actually a subform
> from yet another form.  Thanks for help!

> Bill Seven <b...@include.com> wrote in message news:3a606ff4$1_1@dnews...

>> I have a form that creates a child form.  The child form has a uses clause
>> that references the parent.  The parent form has a table that I'd like to
>> reference from the child, but when I do, I get an AV.

>> Code is shown below, thanks for help!

>> Parent code:

>> procedure TForm1.button1click(sender:TObject);
>> var f: TFormChild;
>> begin
>>      f:=TFormChild.create(application);
>>      f.showmodal;
>>      f.release;
>> end;

>> Child code:

>> ...
>> uses form1;
>> ...
>> procedure TFormChild.button1click(sender: TObject);
>> begin
>>      formParent.table1.refresh;  // generates the AV
>> end;

--
Leo Seaman                       (800) 279-9717
WebTech (formerly DPR)    
http://www.webtechcorp.com       "Programmers Teaching Programmers"

Re:Access violation when accessing table from secondary form


What is formParent? Are you sure it returns a valid reference to the parent
form.

--
Bill

Other Threads