It is currently Thu May 23, 2013 7:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 12:51 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
I'm using code I don't quite understand (Pointers throw me) and a particular line is throwing a "Pointer is Null" error at me and I don't understand why.

It happens when I click ont he column header of a ListIconGadget but the item does in fact have items to be sorted so should it be not null?.

Code:
Procedure CompareFunc(*item1.PB_ListIconItem, *item2.PB_ListIconItem, lParamSort)

  Protected result = 0

  lvi\iSubItem    = lParamSort
  lvi\pszText     = Buffer1
  lvi\cchTextMax  = 512
  lvi\Mask = #LVIF_TEXT

  SendMessage_(GadgetID(#Gadget_items), #LVM_GETITEMTEXT, *item1\UserData, @lvi)

  lvi\pszText = Buffer2
 
  SendMessage_(GadgetID(#Gadget_items), #LVM_GETITEMTEXT, *item2\UserData, @lvi)  ; Pointer is null error at this line

  Protected Seeker1 = Buffer1
  Protected Seeker2 = Buffer2
  Protected done = 0

  While done = 0
    Protected char1 = Asc(UCase(Chr(PeekB(Seeker1))))
    Protected char2 = Asc(UCase(Chr(PeekB(Seeker2))))
    result = (char1 - char2) * updown
    If result <> 0 Or (Seeker1 - Buffer1) > 511
      done = 1
    EndIf
    Seeker1 + 1
    Seeker2 + 1
  Wend
 
  ProcedureReturn result
 
EndProcedure

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 12:59 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
At first: Don't declare a variable in a Loop:
Code:
Procedure CompareFunc(*item1.PB_ListIconItem, *item2.PB_ListIconItem, lParamSort)

  Protected result = 0

  lvi\iSubItem    = lParamSort
  lvi\pszText     = Buffer1
  lvi\cchTextMax  = 512
  lvi\Mask = #LVIF_TEXT

  SendMessage_(GadgetID(#Gadget_items), #LVM_GETITEMTEXT, *item1\UserData, @lvi)

  lvi\pszText = Buffer2
 
  SendMessage_(GadgetID(#Gadget_items), #LVM_GETITEMTEXT, *item2\UserData, @lvi)  ; Pointer is null error at this line

  Protected Seeker1 = Buffer1
  Protected Seeker2 = Buffer2
  Protected done = 0
  Protected char1 ; < --
  Protected char2 ; <--
 
  While done = 0
    char1 = Asc(UCase(Chr(PeekB(Seeker1)))) ; not here
    char2 = Asc(UCase(Chr(PeekB(Seeker2)))) ; not here
    result = (char1 - char2) * updown
    If result <> 0 Or (Seeker1 - Buffer1) > 511
      done = 1
    EndIf
    Seeker1 + 1
    Seeker2 + 1
  Wend
 
  ProcedureReturn result
 
EndProcedure

for the rest is more and executable source required.
For example, i can't see the structure PB_ListIconItem

Greetings - Thomas

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 1:19 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4231
Location: Strasbourg / France
Fangbeast wrote:
I'm using code I don't quite understand (Pointers throw me) and a particular line is throwing a "Pointer is Null" error at me and I don't understand why.

It happens when I click ont he column header of a ListIconGadget but the item does in fact have items to be sorted so should it be not null?.
Like ts-soft wrote, we are missing some code.
But adding a little check in your source would not hurt :
Code:
Procedure CompareFunc(*item1.PB_ListIconItem, *item2.PB_ListIconItem, lParamSort)

 If *item1 And *item2

  Protected result = 0

  lvi\iSubItem    = lParamSort
  lvi\pszText     = Buffer1
  lvi\cchTextMax  = 512
  lvi\Mask = #LVIF_TEXT

  SendMessage_(GadgetID(#Gadget_items), #LVM_GETITEMTEXT, *item1\UserData, @lvi)

  lvi\pszText = Buffer2
 
  SendMessage_(GadgetID(#Gadget_items), #LVM_GETITEMTEXT, *item2\UserData, @lvi)  ; Pointer is null error at this line

  Protected Seeker1 = Buffer1
  Protected Seeker2 = Buffer2
  Protected done = 0
  Protected char1
  Protected char2
 
  While done = 0
    char1 = Asc(UCase(Chr(PeekB(Seeker1))))
    char2 = Asc(UCase(Chr(PeekB(Seeker2))))
    result = (char1 - char2) * updown
    If result <> 0 Or (Seeker1 - Buffer1) > 511
      done = 1
    EndIf
    Seeker1 + 1
    Seeker2 + 1
  Wend
 
 EndIf
 
 ProcedureReturn result
 
EndProcedure

_________________
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 1:40 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
@Thomas I copied the copied the code exactly as I found it a year ago and didn't know any better what to do. Thanks for the suggestion.

@Gnozal I was going to post more code (the globals, UpdatelParam etc) but that suggestion of yours fixed the problem immediately.

It's funny, I wrote this program 2 years ago and only just got around to fixing this bug as I'd never clicked on the header to sort anything before.

Show how popular my software wasn't!! (Nobody else told me I had bugs).

Thanks for the help blokes.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 2:03 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
The check by Gnozal is good, but it is only a check to become no IMA, but does not
solve the problem!

It is better you write a small, executable source, to see the real problem.

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 7:12 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2401
Location: Utah, USA
ts-soft wrote:
At first: Don't declare a variable in a Loop:


@ts-soft: Why would this cause a problem? It seems to be only a matter of style.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Fri Mar 16, 2012 7:29 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
Demivec wrote:
@ts-soft: Why would this cause a problem? It seems to be only a matter of style.

Is a ugly Style not a problem? :mrgreen:

The best is to declare on the top of main or procedure.

_________________
PureBasic 5.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: Pointer is Null error on Sort on Column Click
PostPosted: Sat Mar 17, 2012 5:19 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
When you've survived cancer (for now), you don't care about ugly style, only so many hours in the day:):):)

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye