home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / tools / 1710 < prev    next >
Encoding:
Text File  |  1992-12-15  |  3.5 KB  |  98 lines

  1. Newsgroups: comp.os.ms-windows.programmer.tools
  2. Path: sparky!uunet!mcsun!news.funet.fi!news.cc.tut.fi!semi
  3. From: semi@cc.tut.fi (Malinen Semi)
  4. Subject: Re: OWL & transfer to Combobox
  5. Message-ID: <1992Dec15.142956.24823@cc.tut.fi>
  6. Organization: Tampere University of Technology, Finland
  7. References: <HAGELIN.92Dec14141029@elixir.elixir.e.kth.se>
  8. Distribution: comp
  9. Date: Tue, 15 Dec 92 14:29:56 GMT
  10. Lines: 85
  11.  
  12.  
  13. In <HAGELIN.92Dec14141029@elixir.elixir.e.kth.se> hagelin@elixir.e.kth.se (Martin Hagelin) writes:
  14.  
  15.  
  16.  
  17. >I have a problem with OWL and transfer to/from Comboboxes in a dialog.
  18. >I try to display a combobox in a dialog and fill it with information
  19. >but somehow the Gods aren't with me. I'm running BC++ v3.1 with OWL.
  20.  
  21.  
  22.  
  23. >The code looks like this:
  24.  
  25.     (Code deleted)
  26.  
  27. >Because I create a TComboBoxData with new, I must delete it
  28. >afterwards. But if I do this, everything crashes the second time I run
  29. >DoTheBox(), and if I omit the delete statement everything works fine
  30. >for maybe 10 or 20 times then it crashes (probably because more and
  31. >memory is taken by the TComboBoxData:s).
  32.  
  33. >The manual is not very informative about transfering and especially
  34. >not to/from comboboxes. Am I doing this totally backwards ?
  35.  
  36. No, you are doing it just right.
  37.  
  38. I can't see anything wrong with your code. I also had a very
  39. similar problem with a program I am currently writing. Fortunately
  40. I managed to be able to fix it after some research.
  41.  
  42. As it turns out there seems to be a bug in OWL's code that
  43. handles transfer to and from comboboxes. If you are using the same
  44. subversion of BC++ 3.1 as I am then you can fix the problem by
  45. patching file COMBOBOX.CPP in .../OWL/SOURCE directory and recompiling
  46. OWL.
  47.  
  48. You can find the bug on lines 151 to 153 in COMBOBOX.CPP. On line
  49. 151 (in Transfer method of TComboBox) OWL asks for the length of the
  50. currently selected string by sending the combobox a CB_GETLBTEXTLEN
  51. message. The value is placed into a variable called StringSize.
  52. New is then used to allocate StringSize bytes for the selection
  53. string on line 152. On line 153 the selection string is copied from
  54. the combobox to the newly allocated vector. Copying is done by sending
  55. the combobox a CB_GETLBTEXT message with the address of the buffer as
  56. lParam.
  57.  
  58. The problem is that the terminating zero of the selection string is
  59. written past the string over some valuable data. 
  60.  
  61. According to the manuals message CB_GETLBTEXTLEN returns the length
  62. of the selection string, in bytes, *excluding* the terminating zero.
  63. When OWL allocates space for the selection string it does not take
  64. the terminating zero into account. Again according to the manuals
  65. the message CB_GETLBTEXT causes the string, *including* the terminating
  66. zero, to be copied to the address pointed by lParam. What happens is
  67. that the terminating zero is probably written over some bookkeeping
  68. information that new and delete use.
  69.  
  70. I had to recompile OWL with debugging information included and run my
  71. program with debugger before I could convince myself that Borland
  72. had left such a trivial error in their code. It seems to me that
  73. Borland has not tested OWL very well, because this bug is something
  74. that you *will* run into if you use TComboBox class for anything
  75. serious.
  76.  
  77. You can kill the bug by simply increasing StringSize by one before
  78. it is used. I just made the line 152 of COMBOBOX.CPP to read:
  79.  
  80.     ComboBoxData->Selection = new char[StringSize+1];
  81.  
  82. After recompiling OWL and relinking my program the problem disappeared
  83. and my dialog box ran fine.
  84.  
  85. Hope this helps!
  86.  
  87. >/Martin
  88.  
  89. >--
  90. >--------
  91. >Martin Hagelin
  92. >hagelin@elixir.e.kth.se
  93.  
  94.  
  95.         Semi
  96.         semi@cc.tut.fi
  97.  
  98.