Hi
I have the following macro which is intended to bitwise AND the string of binary numbers in the two text entries, fTe1 and fTe2, and put the result in another text entry, fTe3. Unfortunately I get “out of bounds error”. I have commented the instructions that I used to AND the two strings.
#include <TGClient.h>
#include <TGFrame.h>
#include <TGTextEntry.h>
#include <TGButton.h>
#include <TString.h>
#include <RQ_OBJECT.h>
class MainFrame
{
RQ_OBJECT("MainFrame")
private:
TGMainFrame *fMain;
TGCompositeFrame *f1, *f2;
TGLayoutHints *fL1, *fL2, *fL3;
TGTextEntry *fTe1;
TGTextEntry *fTe2;
TGTextEntry *fTe3;
TGButton *ANDButton;
public:
MainFrame(const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MainFrame();
void AND();
};
MainFrame::MainFrame(const TGWindow *p,UInt_t w,UInt_t h)
{
fMain = new TGMainFrame(p, w, h);
fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
f1 = new TGCompositeFrame(fMain, 60, 20, kVerticalFrame);
f2 = new TGCompositeFrame(fMain, 100, 20, kVerticalFrame | kFixedWidth);
fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 10, 10, 10, 2);
fL2 = new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 5, 10, 0);
fL3 = new TGLayoutHints(kLHintsTop, 5, 5, 60, 5);
fTe1 = new TGTextEntry(f1, new TGTextBuffer(5),1);
f1->AddFrame(fTe1, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
fTe1->Insert("1111001011");
fTe2 = new TGTextEntry(f1, new TGTextBuffer(5),2);
f1->AddFrame(fTe2, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5));
fTe2->Insert("1010110101");
fTe3 = new TGTextEntry(f1, new TGTextBuffer(5),3);
f1->AddFrame(fTe3, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 15, 5));
//AND button on frame f2
ANDButton = new TGTextButton(f2, "&AND", 4);
//ANDButton->Connect("Clicked()","MainFrame",this,"AND()");
f2->AddFrame(ANDButton,fL3);
fMain->AddFrame(f1,fL1);
fMain->AddFrame(f2,fL2);
fMain->SetWindowName("Bitwise ANDing");
fMain->MapSubwindows();
fMain->Resize(400, 200);
fMain->MapWindow();
}
MainFrame::~MainFrame()
{
fMain->Cleanup();
delete fMain;
}
/*void MainFrame::AND()
{
TString str1 = fTe1->GetText();
TString str2 = fTe2->GetText();
TString str3;
for(int i=0;i<10;i++)
{
if((str1[i]=="1") && (str2[i]=="1"))
str3[i] = "1";
else
str3[i] = "0";
}
fTe3->SetText(str3.Data());
}*/
void BitwiseAND()
{
new MainFrame(gClient->GetRoot(), 300, 200);
}
Any suggestions of where I may be going wrong?
Cheers