1. [WIN32Lib] TreeView pblm: erase, addTVItem, & getTVSelectedText cause crash
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Oct 15, 2001
- 454 views
Derek is already looking into this for me, but I thought I'd see if anyone else had any ideas about it too. I'm having a problem in using TreeView, whereby if I erase and repopulate a TV, *after* I have selected an item in the TV, my program crashes. If I remove the "erase" function for the items that I have before the repopulate, no crash (but dupl stuff in TV). Program apparently crashes *while* it's repopulating the TV, but inside a *separate* "onChange" routine, involving getTVSelectedText, as if two unexpected things are occurring: 1. maybe the index of "selected item" isn't being reset by the "erase" function; 2. and maybe "onChange" is being activated during the "addTVItem"? Here's what I have: 1. a button which opens a file, reads it in, puts stuff from it into TV; 2. an "onChangeTV" routine, which copies item selected from TV into clipboard. CRASH occurs if I: 1. open & read file, populate TV, 2. select an item in TV, 3. open new file, read & populate TV (this is *when* the crash occurs) but the failure is indicated as happening in the *"onChangeTV"* routine, in the function "getTVText", as if the act of repopulating the TV is triggering an "onChange" event, AND even though I put in a test for TV content (really test for item selection) in the "onChange" routine, just to be careful. There is no problem if I just repeat opening files & populating the TV, as long as I don't ever *select* anything from the TV; but if I select anything and *then* open a file & read data from it into the TV, crash. ----------------------------------- Here's some relevant code: -- already read in file; now put items in var "AllRoutines" into TV: --<snip beginning> eraseItems(TreeView5) -- <== removing this makes not crash, but dupls items for n = 1 to length(AllRoutines) do folders &= addTVItem ( TreeView5, 0, 0, AllRoutines[n][1], 0 )-- section names for m = 1 to length(AllRoutines[n][2]) -- routine names dummy &= addTVItem ( TreeView5, 0, 0, AllRoutines[n][2][m], folders[n] ) end for end for current = getTVIndex( TreeView5 ) if current > 0 then -- if anything in TreeView (anything selected): if ( (match("procedure", getTVSelectedText ( TreeView5 ))= 1) --<== fails here or (match("function", getTVSelectedText ( TreeView5 ))= 1)) And here's the first portion of the error message: C:\Euphoria\Win32Lib\Win32lib.ew:6213 in function getTVText() subscript value 41 is out of bounds, reading from a sequence of length 0 iItem = 41')' ... called from C:\Euphoria\Win32Lib\Win32lib.ew:6222 in function getTVSelectedText() id = 8 sel = 41')' ... called from C:\Euphoria\Win32Lib\Rdx2e9xa.exw:274 in procedure TreeView5_onChange() current = 41')' void = 1 dummy = <no value> Anyone have any thoughts?? Dan Moyer (Topica yuck!)
2. Re: [WIN32Lib] TreeView pblm: erase, addTVItem, & getTVSelectedText cause crash
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Oct 16, 2001
- 422 views
Matt, Ok, my version of Win32Lib deleteItem() *is* different, but it's the last official (stamped) release at RDS, Version: 0.55.1 19/Dec/2000. I'll see if your code fixes my problem, thanks. ver 0.55.1 (for the "erase all" portion of deleteItem for LV) is: elsif window_type[ id ] = ListView then if pos = -1 then msg = LVM_DELETEALLITEMS iItem = length( lvitem_owner ) while iItem do removeLVItem( iItem ) iItem = length( lvitem_owner ) end while Thanks again, Dan Moyer ----- Original Message ----- From: "Matthew Lewis" <matthewwalkerlewis at YAHOO.COM> To: "EUforum" <EUforum at topica.com> Sent: Tuesday, October 16, 2001 4:51 AM Subject: RE: [WIN32Lib] TreeView pblm: erase, addTVItem, & getTVSelectedText cause crash > > > > -----Original Message----- > > From: Dan Moyer [mailto:DANIELMOYER at prodigy.net] > > > > I'm having a problem in using TreeView, whereby if I erase > > and repopulate a > > TV, *after* I have selected an item in the TV, my program > > crashes. If I > > remove the "erase" function for the items that I have before > > the repopulate, > > no crash (but dupl stuff in TV). > > > > Dan, first thing you should do is check deleteItem() in win32lib. There was > a (read: my) bug in there with regard to both list and treeviews. > Essentially, some internal bookkeeping wasn't done correctly, and when > windows checked on an item (text is stored by win32lib), it wasn't there, > causing a crash. > > Make sure your copy looks like this (for ListView & TreeView): > > > elsif window_type[ id ] = ListView then > if pos = -1 then > msg = LVM_DELETEALLITEMS > > iItem = 1 > > while iItem <= length( lvitem_owner ) do > if lvitem_owner[iItem] = id then > removeLVItem( iItem ) > if iItem < length(lvitem_owner) then > iItem += 1 > end if > else > iItem += 1 > end if > > end while > > else > > LV_FINDINFO = struct_LVFINDINFO( LVFI_PARAM, "", pos, 0, 0, 0) > > iItem = sendMessage( id, LVM_FINDITEM, -1, LV_FINDINFO ) + 1 > > release_mem(LV_FINDINFO) > > if not iItem then > return 0 > end if > > msg = sendMessage( id, LVM_DELETEITEM, iItem-1, lParam ) > if msg then > removeLVItem( pos ) > end if > > return msg > > elsif window_type[ id ] = TreeView then > msg = TVM_DELETEITEM > if pos = -1 then > lParam = TVI_ROOT > > -- changed to only delete items in the treeview specified > iItem = 1 > > while iItem <= length( tvitem_owner ) do > if tvitem_owner[iItem] = id then > removeTVItem( iItem ) > if iItem < length(tvitem_owner) then > iItem += 1 > end if > else > iItem += 1 > end if > > end while > else > > > >
3. Re: [WIN32Lib] TreeView pblm: erase, addTVItem, & getTVSelectedText cause crash
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Oct 16, 2001
- 435 views
Matt, I tried your revised code, but it still failed, but because Win32Lib was no longer stamped, I don't know the nature of the crash. Oh, I had to add a "end if" between > return msg and > elsif window_type[ id ] = TreeView then Dan ----- Original Message ----- From: "Matthew Lewis" <matthewwalkerlewis at YAHOO.COM> To: "EUforum" <EUforum at topica.com> Sent: Tuesday, October 16, 2001 4:51 AM Subject: RE: [WIN32Lib] TreeView pblm: erase, addTVItem, & getTVSelectedText cause crash > > > > -----Original Message----- > > From: Dan Moyer [mailto:DANIELMOYER at prodigy.net] > > > > I'm having a problem in using TreeView, whereby if I erase > > and repopulate a > > TV, *after* I have selected an item in the TV, my program > > crashes. If I > > remove the "erase" function for the items that I have before > > the repopulate, > > no crash (but dupl stuff in TV). > > > > Dan, first thing you should do is check deleteItem() in win32lib. There was > a (read: my) bug in there with regard to both list and treeviews. > Essentially, some internal bookkeeping wasn't done correctly, and when > windows checked on an item (text is stored by win32lib), it wasn't there, > causing a crash. > > Make sure your copy looks like this (for ListView & TreeView): > > > elsif window_type[ id ] = ListView then > if pos = -1 then > msg = LVM_DELETEALLITEMS > > iItem = 1 > > while iItem <= length( lvitem_owner ) do > if lvitem_owner[iItem] = id then > removeLVItem( iItem ) > if iItem < length(lvitem_owner) then > iItem += 1 > end if > else > iItem += 1 > end if > > end while > > else > > LV_FINDINFO = struct_LVFINDINFO( LVFI_PARAM, "", pos, 0, 0, 0) > > iItem = sendMessage( id, LVM_FINDITEM, -1, LV_FINDINFO ) + 1 > > release_mem(LV_FINDINFO) > > if not iItem then > return 0 > end if > > msg = sendMessage( id, LVM_DELETEITEM, iItem-1, lParam ) > if msg then > removeLVItem( pos ) > end if > > return msg > > elsif window_type[ id ] = TreeView then > msg = TVM_DELETEITEM > if pos = -1 then > lParam = TVI_ROOT > > -- changed to only delete items in the treeview specified > iItem = 1 > > while iItem <= length( tvitem_owner ) do > if tvitem_owner[iItem] = id then > removeTVItem( iItem ) > if iItem < length(tvitem_owner) then > iItem += 1 > end if > else > iItem += 1 > end if > > end while > else > > > >