Solved

radiobutton bug

Posted on 1997-10-16
6
238 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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).

777 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