Solved

radiobutton bug

Posted on 1997-10-16
6
234 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

744 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

11 Experts available now in Live!

Get 1:1 Help Now