[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

radiobutton bug

Posted on 1997-10-16
6
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 600 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

650 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