Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ ComboBox & MemoBox Help

Options
  • 10-04-2003 11:00am
    #1
    Closed Accounts Posts: 6


    Hi all,

    What I am trying to do is: I have a ComboBox with 5 field names (<name1>, <name2> etc). I want to display each field at different points in a memo box. The user will be writing a letter in the memobox so I basically need to keep track of the cursor in order to input the field name into position without overwriting the data already entered. Is this possible with a memobox or is there another way of doing it?
    I have tried using a simple set of if statements
    e.g
    if(Form2->ComboBox1->Items->Strings[0] == "<firstname>"{
    Form3->MemoBox1->Text == "<firstname>"
    }
    but this just displays <firstname> and overwrites any data in the memobox.

    I would really appreciate any help
    Clarabell


Comments

  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    [php]if(Form2->ComboBox1->Items->Strings[0] == "<firstname>")
    {
    Form3->MemoBox1->Text == "<firstname>" // this line needs to
    // concat "<firstname>" to Form3->MemoBox1->Text
    }[/php]


  • Registered Users Posts: 2,149 ✭✭✭dazberry


    Originally posted by clarabell
    Hi all,
    [SNIP...]
    if(Form2->ComboBox1->Items->Strings[0] == "<firstname>"{
    Form3->MemoBox1->Text == "<firstname>"
    }
    but this just displays <firstname> and overwrites any data in the memobox.

    This looks very VCL (C++ Builder) so I'll have to comment - sorry if I'm wrong. I'm a Delphite so replace . with -> and := with == etc.

    Firstly Text sets the complete text of the Memo (as it does with a Combo or any other TString / TStringList class or related component).

    The easiest way which may not suit (you'll see when you do this), are the members:
    TMemoBox.SelStart
    TMemoBox.SelText


    (A) IF no selection is made in the memo, SelStart will point to the current cursor position. SelText will be blank.

    (B) If a selection is made, SelStart will point to the start of the select text which may or may not be the current cursor position, and SelText will contain the text of the highlighted selection.

    In you're scenerio:
    if(Form2->ComboBox1->Items->Strings[0] == "<firstname>"{
    Form3->MemoBox1->Text == "<firstname>"


    Change to
    Form3->MemoBox1->SelText == "<firstname>"

    (A)
    Where the cursor is located, the text "<firstname>" is inserted.

    (B)
    Whatever is selected is overwritten with "<firstname>".

    HTH

    D.


  • Closed Accounts Posts: 6 clarabell


    Thanks for your help dazberry, that SelText worked perfect,

    Cheers!


Advertisement