Thread View: comp.os.ms-windows.programmer.tools
2 messages
2 total messages
Started by Martin Hagelin
Mon, 14 Dec 1992 13:10
OWL & transfer to Combobox
Author: Martin Hagelin
Date: Mon, 14 Dec 1992 13:10
Date: Mon, 14 Dec 1992 13:10
79 lines
2376 bytes
2376 bytes
Hello everybody !
I have a problem with OWL and transfer to/from Comboboxes in a dialog.
I try to display a combobox in a dialog and fill it with information
but somehow the Gods aren't with me. I'm running BC++ v3.1 with OWL.
The code looks like this:
struct TMyTransferStruct {
...
PTComboBoxData pcbxdata;
...
};
class TMyWindow : public TWindow
{
...
TMyTransferStruct MyTransferStruct;
...
};
TMyWindow::DoTheBox()
{
MyTransferStruct.pcbxdata = new TComboBoxData();
// Fill the list
MyTransferStruct.pcbxdata->AddString("bla bla");
...
// Create the dialog and it's components
PTDialog MyDialog = new TDialog(this, ID_MYDIALOG);
...
new TComboBox(MyDialog, ID_MYCOMBOBOX);
...
// Set the TransferBuffer to my transferstruct
MyDialog->SetTransferBuffer(&MyTransferStruct);
// Do the dialog
if ( GetApplication()->ExecDialog(MyDialog) == MB_OK ) {
strcpy(answer, MyTransferStruct.pcbxdata->Selection);
...
}
// problem statement
delete MyTransferStruct.pcbxdata;
}
Because I create a TComboBoxData with new, I must delete it
afterwards. But if I do this, everything crashes the second time I run
DoTheBox(), and if I omit the delete statement everything works fine
for maybe 10 or 20 times then it crashes (probably because more and
memory is taken by the TComboBoxData:s).
The manual is not very informative about transfering and especially
not to/from comboboxes. Am I doing this totally backwards ?
From what I believe (not that I havn't studied the manuals), manages
the ExecDialog() the deletion of the dialogbox and it's children when
the routine is finished.
I'd sure appriciate some help on this subject, or some other solutions
on how to get your transfer to/from dialog boxes to work.
/Martin
--
--------
Martin Hagelin
hagelin@elixir.e.kth.se
Re: OWL & transfer to Combobox
Author: Malinen Semi
Date: Tue, 15 Dec 1992 14:29
Date: Tue, 15 Dec 1992 14:29
85 lines
3715 bytes
3715 bytes
In <HAGELIN.92Dec14141029@elixir.elixir.e.kth.se> hagelin@elixir.e.kth.se (Martin Hagelin) writes: >I have a problem with OWL and transfer to/from Comboboxes in a dialog. >I try to display a combobox in a dialog and fill it with information >but somehow the Gods aren't with me. I'm running BC++ v3.1 with OWL. >The code looks like this: (Code deleted) >Because I create a TComboBoxData with new, I must delete it >afterwards. But if I do this, everything crashes the second time I run >DoTheBox(), and if I omit the delete statement everything works fine >for maybe 10 or 20 times then it crashes (probably because more and >memory is taken by the TComboBoxData:s). >The manual is not very informative about transfering and especially >not to/from comboboxes. Am I doing this totally backwards ? No, you are doing it just right. I can't see anything wrong with your code. I also had a very similar problem with a program I am currently writing. Fortunately I managed to be able to fix it after some research. As it turns out there seems to be a bug in OWL's code that handles transfer to and from comboboxes. If you are using the same subversion of BC++ 3.1 as I am then you can fix the problem by patching file COMBOBOX.CPP in .../OWL/SOURCE directory and recompiling OWL. You can find the bug on lines 151 to 153 in COMBOBOX.CPP. On line 151 (in Transfer method of TComboBox) OWL asks for the length of the currently selected string by sending the combobox a CB_GETLBTEXTLEN message. The value is placed into a variable called StringSize. New is then used to allocate StringSize bytes for the selection string on line 152. On line 153 the selection string is copied from the combobox to the newly allocated vector. Copying is done by sending the combobox a CB_GETLBTEXT message with the address of the buffer as lParam. The problem is that the terminating zero of the selection string is written past the string over some valuable data. According to the manuals message CB_GETLBTEXTLEN returns the length of the selection string, in bytes, *excluding* the terminating zero. When OWL allocates space for the selection string it does not take the terminating zero into account. Again according to the manuals the message CB_GETLBTEXT causes the string, *including* the terminating zero, to be copied to the address pointed by lParam. What happens is that the terminating zero is probably written over some bookkeeping information that new and delete use. I had to recompile OWL with debugging information included and run my program with debugger before I could convince myself that Borland had left such a trivial error in their code. It seems to me that Borland has not tested OWL very well, because this bug is something that you *will* run into if you use TComboBox class for anything serious. You can kill the bug by simply increasing StringSize by one before it is used. I just made the line 152 of COMBOBOX.CPP to read: ComboBoxData->Selection = new char[StringSize+1]; After recompiling OWL and relinking my program the problem disappeared and my dialog box ran fine. Hope this helps! >/Martin >-- >-------- >Martin Hagelin >hagelin@elixir.e.kth.se Semi semi@cc.tut.fi
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads