Board index » delphi » PageControl.ActivePage not working in user defined procedure

PageControl.ActivePage not working in user defined procedure

I am using Delphi 6.0 and have a PageControl on a Child Form, and from the
MDI Parent form, I call a procedure located in the Child Form.

procedure TfrmAccount.AddNew();
begin
    if frmAccount.PageControlAccount.ActivePage.Name = 'TabSheet4' then
        //do some code here
end;

When I run the program, it give me an error on the above line: "Project
SalesProGlobal.exe raise exception class EAccessViolation......"

In the de{*word*81}, I noticed that form some reason, the frmAccount (the child
form) has a value of 'Nill'? I also have tried not to use the frmAccount in
front of the PageControl, but same error.

Any ideas on how to figure out which Tab is active from a user defined
procedure?

--

God Bless you,
Marco Napoli
http://www.ourlovingmother.org

 

Re:PageControl.ActivePage not working in user defined procedure


Quote
In article <3b678165$1_2@dnews>, Marco Napoli wrote:
> In the de{*word*81}, I noticed that form some reason, the frmAccount (the child
> form) has a value of 'Nill'? I also have tried not to use the frmAccount in
> front of the PageControl, but same error.

How are you creating the child form? Are you actually storing its address in
frmAccount?

Mike Orriss (TeamB and DevExpress)

Re:PageControl.ActivePage not working in user defined procedure


Marco,

Quote
>I am using Delphi 6.0 and have a PageControl on a Child Form, and from the
>MDI Parent form, I call a procedure located in the Child Form.

>procedure TfrmAccount.AddNew();
>begin
>    if frmAccount.PageControlAccount.ActivePage.Name = 'TabSheet4' then

There is no reason to use the frmAccount global variable. If you are using
MDI, you should forget about these auto-created variables anyway, because
they are of no use when you have more than one child of the same type.
Furthermore, they are assigned automatically only when you auto-create the
child form, which is not done in an MDI app.

Just code it as:

procedure TfrmAccount.AddNew();
begin
    if PageControlAccount.ActivePage.Name = 'TabSheet4' then

hth,

Eric Jansen.

Re:PageControl.ActivePage not working in user defined procedure


Hi Eric,

I also tried the same way that you suggested and still get the same error.
Really weird.

I define the procedure in the type as "procedure AddNew;". Is this correct,
could this be the problem?

Marco

Quote
"Eric Jansen" <e...@keyword.no.spam.nl> wrote in message

news:3b67c9d1_1@dnews...
| Marco,
|
| >I am using Delphi 6.0 and have a PageControl on a Child Form, and from
the
| >MDI Parent form, I call a procedure located in the Child Form.
| >
| >procedure TfrmAccount.AddNew();
| >begin
| >    if frmAccount.PageControlAccount.ActivePage.Name = 'TabSheet4' then
|
| There is no reason to use the frmAccount global variable. If you are using
| MDI, you should forget about these auto-created variables anyway, because
| they are of no use when you have more than one child of the same type.
| Furthermore, they are assigned automatically only when you auto-create the
| child form, which is not done in an MDI app.
|
| Just code it as:
|
| procedure TfrmAccount.AddNew();
| begin
|     if PageControlAccount.ActivePage.Name = 'TabSheet4' then
|
| hth,
|
| Eric Jansen.
|
|

Re:PageControl.ActivePage not working in user defined procedure


I am creating the from frmAccount from another Child Windows with the
following code:

TfrmAccount.Create(Self);

Marco

"Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
news:VA.00002418.356a968d@mikemain...
| In article <3b678165$1_2@dnews>, Marco Napoli wrote:
| > In the de{*word*81}, I noticed that form some reason, the frmAccount (the
child
| > form) has a value of 'Nill'? I also have tried not to use the frmAccount
in
| > front of the PageControl, but same error.
| >
|
| How are you creating the child form? Are you actually storing its address
in
| frmAccount?
|
| Mike Orriss (TeamB and DevExpress)
|
|

Re:PageControl.ActivePage not working in user defined procedure


Quote
In article <3b68068e_1@dnews>, Marco Napoli wrote:
> I am creating the from frmAccount from another Child Windows with the
> following code:

> TfrmAccount.Create(Self);

Provided you only require a single instance of this child, then the syntax
should be:

  frmAccount := TfrmAccount.Create(Self);

Mike Orriss (TeamB and DevExpress)

Re:PageControl.ActivePage not working in user defined procedure


After the:
frmAccount := TfrmAccount.Create(Self);

I called the:
frmAccount.Show;

Is the above the correct way?

And now the AddNew() works.

Thanks...
Marco

"Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
news:VA.00002426.368a0dcd@mikemain...
| In article <3b68068e_1@dnews>, Marco Napoli wrote:
| > I am creating the from frmAccount from another Child Windows with the
| > following code:
| >
| > TfrmAccount.Create(Self);
| >
|
| Provided you only require a single instance of this child, then the syntax
| should be:
|
|   frmAccount := TfrmAccount.Create(Self);
|
|
| Mike Orriss (TeamB and DevExpress)
|
|

Re:PageControl.ActivePage not working in user defined procedure


ps:

When I create the form frmAccount from a Child Form with the below code,
when I close the calling child form, the frmAccount Child form also close.
Is there any way to have a child form call another child form, and them not
being tied together?

Marco

Quote
"Marco Napoli" <ma...@avantitec.com> wrote in message

news:3b680deb$1_2@dnews...
| After the:
| frmAccount := TfrmAccount.Create(Self);
|
| I called the:
| frmAccount.Show;
|
| Is the above the correct way?
|
| And now the AddNew() works.
|
| Thanks...
| Marco
|
| "Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
| news:VA.00002426.368a0dcd@mikemain...
| | In article <3b68068e_1@dnews>, Marco Napoli wrote:
| | > I am creating the from frmAccount from another Child Windows with the
| | > following code:
| | >
| | > TfrmAccount.Create(Self);
| | >
| |
| | Provided you only require a single instance of this child, then the
syntax
| | should be:
| |
| |   frmAccount := TfrmAccount.Create(Self);
| |
| |
| | Mike Orriss (TeamB and DevExpress)
| |
| |
|
|

Other Threads