?
Solved

radiobutton bug

Posted on 1997-10-16
6
Medium Priority
?
251 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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
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

Independent Software Vendors: 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!

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…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

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