Hello
Can anyone please help me with how to concatenate the texts that are currently displayed on two different text entries(say fTe1 and fTe2), and display the concatenated text on another text entry, fTe3, so that fTe3 content will change every time the contents of fTe1 and / or fTe2 change. I was hoping of using AppendText() function but then I have a problem of copying the contents of fTe1 and fTe2.
Cheers
Hi,
Here is an example:
#include "TGClient.h"
#include "TGFrame.h"
#include "TGTextEntry.h"
class MainFrame : public TGMainFrame {
protected:
TGHorizontalFrame *fFrame;
TGTextEntry *fTe1;
TGTextEntry *fTe2;
TGTextEntry *fTe3;
public:
MainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MainFrame();
void TextChanged(char *);
ClassDef(MainFrame, 0)
};
//______________________________________________________________________
MainFrame::~MainFrame()
{
// Clean up main frame...
Cleanup();
}
//______________________________________________________________________
MainFrame::MainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
fFrame = new TGHorizontalFrame(this, 100, 100);
// first text entry
fTe1 = new TGTextEntry(fFrame, new TGTextBuffer(100));
fFrame->AddFrame(fTe1, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 5, 5));
fTe1->Resize(150, fTe1->GetDefaultHeight());
// second text entry
fTe2 = new TGTextEntry(fFrame, new TGTextBuffer(100));
fFrame->AddFrame(fTe2, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 5, 5));
fTe2->Resize(150, fTe2->GetDefaultHeight());
// third text entry
fTe3 = new TGTextEntry(fFrame, new TGTextBuffer(100));
fFrame->AddFrame(fTe3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 5, 5, 5, 5));
fTe3->Resize(150, fTe3->GetDefaultHeight());
// connect to the TextChanged() signal from fTe1 and fTe2 but NOT fTe3!
fTe1->Connect("TextChanged(char*)", "MainFrame", this, "TextChanged(char*)");
fTe2->Connect("TextChanged(char*)", "MainFrame", this, "TextChanged(char*)");
AddFrame(fFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
//********************************
MapSubwindows();
MapWindow();
Layout();
}
//______________________________________________________________________
void MainFrame::TextChanged(char *)
{
// slot method called whenever the content of a text entry changes
TString dsp = fTe1->GetText();
dsp.Append(fTe2->GetText());
fTe3->SetText(dsp.Data());
}
//______________________________________________________________________
void copyentries()
{
new MainFrame(gClient->GetRoot(), 500, 100);
}
Cheers, Bertrand.