Board index » delphi » Problem with ListView ... Access Violation

Problem with ListView ... Access Violation

I am getting an access violation when the user does not click on one of
the items in the list.  Basically the code is a case statement similar
to the following.
  case MyListView.Selected.Index of
    0 : begin  {New Customer}
          MyCustomerDialog.NewCustomer;
        end;
    1 : begin  {New Task}
          MyTaskDialog.NewTask;
        end;
  .....etc.....
end;

The error is Access Violation at address{hex address}in module
VCL30.DPL. Read of address FFFFFFFFFFF.

What is the best method to handle this error? Try Except?

Am I doing something wrong with using this component?

thanks for your help and wisdom.

 

Re:Problem with ListView ... Access Violation


Hi.

You could try something like this:

if MyListView.Selected <> nil then
case MyListView.Selected.Index of
    0 : begin  {New Customer}
          MyCustomerDialog.NewCustomer;
        end;
    1 : begin  {New Task}
          MyTaskDialog.NewTask;
        end;
  .....etc.....
end;

Good luck,
Jon.

Re:Problem with ListView ... Access Violation


Try

If MyListView.SelCount = 0 then Begin
 Messagedlg('Hey, Select something first...',mterror,[mbok],0);
 Abort;
End;

Hope it helps

Erik S. Peterson
ESP Software

Barb <da...@goodnet.com> wrote in article
<34901F40.7DB41...@goodnet.com>...

Quote
> I am getting an access violation when the user does not click on one of
> the items in the list.  Basically the code is a case statement similar
> to the following.
>   case MyListView.Selected.Index of
>     0 : begin  {New Customer}
>           MyCustomerDialog.NewCustomer;
>         end;
>     1 : begin  {New Task}
>           MyTaskDialog.NewTask;
>         end;
>   .....etc.....
> end;

> The error is Access Violation at address{hex address}in module
> VCL30.DPL. Read of address FFFFFFFFFFF.

> What is the best method to handle this error? Try Except?

> Am I doing something wrong with using this component?

> thanks for your help and wisdom.

Re:Problem with ListView ... Access Violation


Thanks for the quick responses.

I go my little irritating problem fixed now.  I think I am
going to rework this component to put in a standard message
if the no icon is selected.

thanks again

Barb ;)

Quote
Erik Peterson wrote:
> Try

> If MyListView.SelCount = 0 then Begin
>  Messagedlg('Hey, Select something
> first...',mterror,[mbok],0);
>  Abort;
> End;

> Hope it helps

> Erik S. Peterson
> ESP Software

> Barb <da...@goodnet.com> wrote in article
> <34901F40.7DB41...@goodnet.com>...
> > I am getting an access violation when the user does not
> click on one of
> > the items in the list.  Basically the code is a case
> statement similar
> > to the following.
> >   case MyListView.Selected.Index of
> >     0 : begin  {New Customer}
> >           MyCustomerDialog.NewCustomer;
> >         end;
> >     1 : begin  {New Task}
> >           MyTaskDialog.NewTask;
> >         end;
> >   .....etc.....
> > end;

> > The error is Access Violation at address{hex address}in
> module
> > VCL30.DPL. Read of address FFFFFFFFFFF.

> > What is the best method to handle this error? Try
> Except?

> > Am I doing something wrong with using this component?

> > thanks for your help and wisdom.

Other Threads