Board index » cppbuilder » ListItems->Assign(...) makes Fault Protection ?

ListItems->Assign(...) makes Fault Protection ?

I need to savee the content of a ListView to a TListItems object, so I use:

        TListItems *ListItemSave=new TListItems(NULL);
        ListItemSave->Assign((TPersistent *)ListView1->Items);

This create at the second line an EAccessViolation
Why ? What is bad ?

Thanks

 

Re:ListItems->Assign(...) makes Fault Protection ?


I think it is to do with the fact that you passed a NULL pointer to the
TListItems constructor as the owner.  EAccessViolation is usually to do with
trying to use a NULL pointer.  If you pass the pointer of a genuine "Owner"
I'm sure it will work.

John

Quote
"Sam" <skne...@wanadoo.fr> wrote in message news:3b513cb5$1_2@dnews...
> I need to savee the content of a ListView to a TListItems object, so I
use:

>         TListItems *ListItemSave=new TListItems(NULL);
>         ListItemSave->Assign((TPersistent *)ListView1->Items);

> This create at the second line an EAccessViolation
> Why ? What is bad ?

> Thanks

Re:ListItems->Assign(...) makes Fault Protection ?


You don't need to cast to TPersistent, nor should you:

    ListItemSave->Assign(ListView1->Items);

Gambit

Quote
"Sam" <skne...@wanadoo.fr> wrote in message news:3b513cb5$1_2@dnews...
>         ListItemSave->Assign((TPersistent *)ListView1->Items);

Re:ListItems->Assign(...) makes Fault Protection ?


The Owner has nothing to do with it, and EAccessViolation only applies to
NULL pointers if the fault address is FFFFFFFF

Gambit

Quote
"John Blackburn" <john.blackb...@lintonhealy.co.uk> wrote in message

news:3b5163e6_1@dnews...
Quote
> I think it is to do with the fact that you passed a NULL pointer to the
> TListItems constructor as the owner.  EAccessViolation is usually to do
with
> trying to use a NULL pointer.  If you pass the pointer of a genuine
"Owner"
> I'm sure it will work.

Re:ListItems->Assign(...) makes Fault Protection ?


You are right, but to resolve my problem I need to use the contructor NOT
with NULL but with a reference to a ListView component:
TListItems *ListItemSave=new TListItems(ListView1);

Sam

"Remy Lebeau" <gambi...@gte.net> a crit dans le message news:
3b51e51d$4_1@dnews...

Quote
> You don't need to cast to TPersistent, nor should you:

>     ListItemSave->Assign(ListView1->Items);

> Gambit

> "Sam" <skne...@wanadoo.fr> wrote in message news:3b513cb5$1_2@dnews...

> >         ListItemSave->Assign((TPersistent *)ListView1->Items);

Other Threads