variable over write problem with Dialog Boxes (OWL)

variable over write problem with Dialog Boxes (OWL)

Post by Gary Pickre » Thu, 09 Feb 1995 06:21:39



I'm having trouble with the following code.  The basic idea is to create
a function that will display a dialog box with 1-10 different edit boxes
and prompt text in front of them.  My .rc file has the dialog boxes defined
in it.  My approch was to use Borlands TEdit class for the edit field and
TStatic for the text prompt.  I created a transfer buffer for the edit fields
and the text prompts.  I called initialized the transfer buffer, and the
called EnableTransfer() for the TStatic members.  Then I called
SetTransferBuffer() for the TDialog member and run the Dialog box.

Everything works fine, except that when I run the Dialog box, it sometimes
modifies some global variables that aren't being used by this function.  I've
used the De* to tract down exactly where this happens.

At first I suspected a stack overflow.  I check that I have stack overflow
checking on.  After that I compacted the number of local vars, which should
strink the stack space.  This made no difference.  Next I suspected a
memory over right, but I've used this function sucessfully without a GPF
about 100 times so I ruled this out.  Now I'm wondering if I'm doing
something wrong in setting the window up.

Any help, or pointers out be useful.  I don't have a clear idea of what I'm
doing wrong here =-(

This code is written in OWL1, but it should be virtually the same for OWL2.

//EditType is one TEdit and a matching TStatic.  The TStatic is the prompt
//for the TEdit
class EditType
{
public:
  double *orig_float; // This is a copy of the original variable
  void set(double *value){orig_float=value;}; // store the original variable
  TEdit *EditWind;     // This is used to edit orig_float
  TStatic *EditPrompt; // This is the prompt

  void CreateEdit(class TDialog *Pass, struct BufferType *buff,
                  int count); //This initializes the EditWindow
  void CreatePrompt(class TDialog *pass, struct BufferType *buff,
                    int count ,char *prompt); //This initailizes EditPrompt

Quote:};

#define GWIN_STRING_LENGTH 30
#define GWIN_PROMPT_LENGTH 20

//This is the buffer structure created to be used with SetTransferBuffer
struct BufferType
  {
  char edit[GWIN_STRING_LENGTH]; //room for the edit string
  char prompt[GWIN_PROMPT_LENGTH]; //room for the prompt line
  };

//Initialize the TEdit type and the corrisponding transfer buffer
void EditType::CreateEdit(class TDialog *pass, struct BufferType *buff,
                          int count)
  {
  //Create the Edit Window
  EditWind=new TEdit(pass, ID_EDIT1+count,GWIN_STRING_LENGTH);
  //Initialize the Tranfer Buffer
  sprintf(buff[count].edit,"%f",*orig_float);
  return;
  }

void EditType::CreatePrompt(class GwinTDialog *pass, struct BufferType *buff,
                           int count,char *prompt)
  {
  //Create the Prompt
  EditPrompt=new TStatic(pass, ID_PROMPT1+count,GWIN_PROMPT_LENGTH);
  //Enable the Tranfer of the TStatic, so it will change its text from what
  //is deffined in the .rc file
  EditPrompt->EnableTransfer();
  //Change the TStatics text to what was passed by prompt
  sprintf(buff[count].prompt,"%s",prompt);
  return;
  }

int MyWindow(TWindowsObject *AParent, LPSTR szName, char *prompts[],
             double *var[], int ItemCount)
  {
  //Create the Dialog Window to be used
  TDialog *DialogBox= new TDialog(AParent,szName);

  //Create a transfer buffer of the correct length
  BufferType *buffer=new BufferType[ItemCount];
  //Create the Structure for each edit box
  EditType *Data=new EditType[ItemCount];

  //Loop through each item
  for (item_count=0; item_count<ItemCount; item_count++)
    {
    //store the passed float
    Data[item_count].set(var[item_count]);
    //Create and Initialize the TEdit window
    Data[item_count].CreateEdit(DialogBox, buffer, item_count);
    //Create and Initialize the TStatic window
    Data[item_count].CreatePrompt(DialogBox, buffer, item_count,
                                  prompts[item_count]);
    }

  //Make sure that the Window uses the created Transfer Buffer
  DialogBox->SetTransferBuffer(buffer);
  //Run the Window.  This is where the global variable gets changed!
  if (AParent->GetApplication()->ExecDialog(DialogBox)==IDOK)
    {
    //Not included because things have already gone wrong
    }
  else
    {
    //Not included because things have already gone wrong
    }
  //Not included because things have already gone wrong
  }

Thanks!  
        -Gary

 
 
 

1. Strange problem with A Dialog Box in OWL 2.0

Hi,

I am writing an application in BC++ 4.0 using OWL 2.0. There is a simple
dialog box with three radio buttons which is invoked inside a function MyFunc
which belongs to MyMDIClient. MyFunc has a float array defined in it. If
I increase the size of the array, the dialog box gets half drawn. If I make it
small, it gets drawn properly. There is also a size of the array, where the
dialog box does not get drawn at all!

Could somebody please tell me what the problem might be?

Thanks a lot.

2. Assempro

3. OWL DIALOG BOX/EDIT BOX

4. Why can't I set accurate breakpoints when debugging?

5. Dialog box from a Dialog Box

6. Getting a file's Icon in Applescript

7. HELP! Dialog Boxes within Dialog Boxes!

8. making asynchronous db calls

9. Dialog Box from Dialog Box

10. Dialog boxes from dialog boxes?

11. Dialog boxes from Dialog Boxes

12. Displaying a second DIALOG BOX from another DIALOG BOX????

13. Calling a modeless dialog box from a modal dialog box