Solved

radiobutton bug

Posted on 1997-10-16
6
235 Views
Last Modified: 2013-12-26
I am using Borland C++ 5.02 with Windows 95.

My computer is a 486 66MHz with 20MB of RAM

The enclosed code uses three radio buttons. Each radio button when pressed causes a number to be displayed in the client window i.e., 1,2,3.

This program runs beautifully with C++ 4.5 (running on a 75MHz Pentium 32MB of RAM with Windows 3.1) but on my computer with C++ 5.02 the first button writes '1' (this is correct), the second button fails to write anything (should write '2') and the third button writes '2' (should write 3).

I am at a loss to understand why a program that runs fine in C++ 4.5 will not run correctly under C++ 5.02. The only thing I can think is that my computer lacks sufficient resources to run C++ 5.02.

Any help is most appreciated

regards

Richard

 //ices.h  - header file

const UINT MaxEdit = 30;



struct TCoreCompetenceBuffer
{
uint rnd1,rnd2,rnd3; //radio button variables
};


class TCoreCompetence : public TDialog
{
public:
      TCoreCompetence( TWindow *parent,
                                    TCoreCompetenceBuffer* c_c,
                                    TModule* module = 0);

};

class TMyWindow : public TFrameWindow
{
public:
      TMyWindow(TWindow* parent, const char far *title);
      

protected:

      void CmDialog();
        void RnDOne();
      void RnDTwo();
      void RnDThree();


private:
      TCoreCompetenceBuffer c_c;

      
      BOOL merged;

      DECLARE_RESPONSE_TABLE(TMyWindow);
};

//ices.cpp  - main source code


#include <cstring.h>
#include <windows.h>
#include <owl\applicat.h>
#include <owl\checkbox.h>
#include <owl\dialog.h>
#include <owl\edit.h>
#include <owl\framewin.h>
#include <owl\radiobut.h>
#include <owl\dc.h>
#include <stdio.h>
#include <fstream.h>
#include <mem.h>
#include "ices.rh"
#include "ices.h"

DEFINE_RESPONSE_TABLE1(TMyWindow, TWindow)

      EV_COMMAND(CM_CORECOMPETENCES, CmDialog),

END_RESPONSE_TABLE;



TMyWindow::TMyWindow(TWindow* parent, const char far *title)
      : TFrameWindow(parent, title),
        TWindow(parent,title)
{
      merged = FALSE;
      memset(&c_c, 0, sizeof(c_c));
      c_c.rnd1=BF_UNCHECKED;
      c_c.rnd2=BF_UNCHECKED;
      c_c.rnd3=BF_UNCHECKED;
}


TCoreCompetence::TCoreCompetence( TWindow* parent,
                                                            TCoreCompetenceBuffer* c_c,
                                                            TModule *module)
      : TDialog(parent, "Core_competence", module)
{

      new TRadioButton(this, IDC_RADIOBUTTON1);
      new TRadioButton(this, IDC_RADIOBUTTON2);
      new TRadioButton(this, IDC_RADIOBUTTON3);
      SetTransferBuffer(c_c);
}


void TMyWindow::CmDialog()
{
      if(TCoreCompetence(this, &c_c).Execute() == IDOK)
      {
            if(c_c.rnd1==BF_CHECKED)
            {
            RnDOne();
            }
            if(c_c.rnd2==BF_CHECKED)
            {
            RnDTwo();
            }
            if(c_c.rnd3==BF_CHECKED)
            {
            RnDThree();
            }

      }
}

void TMyWindow::RnDOne() //R&D Level 1
{
char s[1];
int i = 1;
            sprintf(s,"%d",i);
            TClientDC dc(*this);
             dc.TextOut(0,0,s);
}

void TMyWindow::RnDTwo() //R&D LEVEL 2
{
char s[1];
int i = 2;
            sprintf(s,"%d",i);
            TClientDC dc(*this);
             dc.TextOut(0,0,s);
}

void TMyWindow::RnDThree() //R&D Level 3
{
char s[1];
int i = 3;
            sprintf(s,"%d",i);
            TClientDC dc(*this);
             dc.TextOut(0,0,s);
}


class TDialogApp : public TApplication
{
public:
      TDialogApp(const char far *name)
            : TApplication(name){};
      void InitMainWindow();
};

void TDialogApp::InitMainWindow()
{
      TMyWindow *win = new TMyWindow(0, "ICES");
      SetMainWindow(win);
      GetMainWindow()->
      SetMenuDescr(TMenuDescr(ID_MENU1,1,0,0,3,0,2));
};

int OwlMain(int argc, char *argv[])
{
      TDialogApp app("Prototype");
      return app.Run();

}










0
Comment
Question by:aa941438
6 Comments
 

Author Comment

by:aa941438
ID: 1299437
Edited text of question
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1299438
Have you tried expanding the size of s to something bigger?

I would try using char s[10]; just to see what happens. That's the only thing that looks suspect.
0
 

Author Comment

by:aa941438
ID: 1299439
Thui,

Thanks for your help but unfortunately increasing the array size doesn't make any difference.

regards

Richard
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1299440
I see nothing strange here...
Please also post your resource file, and I will try it on my system.
.luc.
0
 
LVL 3

Accepted Solution

by:
JPM earned 200 total points
ID: 1299441
It's always difficult to find out why a program running well ( or supposed to) changes its way.
At first, It looks like you have an overflow.

You don't say what you 've done trying to solve the pb,so excuse me if I don't give you good advise.
What about your RC file ?

What I could suggest ?

 --  moving initialisation of c_c in a TMyWindow::SetupWindow

 --  writing the struct like that   ( I remember having pb ....)
  struct TCoreCompetenceBuffer
       {
        uint rnd1;
        uint rnd2;
        uint rnd3;  
       };
  -- using wsprintf instead of sprintf


Because I hate the TransferBuffer mechanism , I don't proceed like you did
I use class to store data with members and a constructor for initialising
and above all just one   uint data for  buttons of a groupbox  
It's more robust and more flexible.......but less elegant than the TransferBuffer mechanism!

0
 

Author Comment

by:aa941438
ID: 1299442
Thanks for your reply.

Since I posted the question I have over come my problem by not using the transferbuffer mechanism. I shall examine your ideas at a later date when I am a little less busy.

regards

Richard
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now