aa941438
asked on
radiobutton bug
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(TMy Window);
};
//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(TMy Window, TWindow)
EV_COMMAND(CM_CORECOMPETEN CES, CmDialog),
END_RESPONSE_TABLE;
TMyWindow::TMyWindow(TWind ow* 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::TCoreComp etence( 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();
}
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(TMy
};
//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(TMy
EV_COMMAND(CM_CORECOMPETEN
END_RESPONSE_TABLE;
TMyWindow::TMyWindow(TWind
: 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::TCoreComp
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
};
int OwlMain(int argc, char *argv[])
{
TDialogApp app("Prototype");
return app.Run();
}
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.
I would try using char s[10]; just to see what happens. That's the only thing that looks suspect.
ASKER
Thui,
Thanks for your help but unfortunately increasing the array size doesn't make any difference.
regards
Richard
Thanks for your help but unfortunately increasing the array size doesn't make any difference.
regards
Richard
I see nothing strange here...
Please also post your resource file, and I will try it on my system.
.luc.
Please also post your resource file, and I will try it on my system.
.luc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER