Board index » cppbuilder » Add character to Memo field

Add character to Memo field

How can I add a character to a memo field one character at a time instead of
one line at a time?

Thanks,
Terry

 

Re:Add character to Memo field


Quote
Terry Neckar <terry> wrote in message news:3b98f749$1_1@dnews...
> How can I add a character to a memo field one character at a time
instead of
> one line at a time?

Try this:

Memo1->Lines->Strings[3]=Memo1->Lines->Strings[3]+String("a");

Note that there's a lot of jargon here; You can't say += because Lines
is a BCB "Property". You can't say 'a' because the constructor for
AnsiString will create the string "97".  String [3] (Line 4) of the
Memo must exist, or you'll get an index out of range error.  See
AnsiString::StringOfChar if you need a char variable as input.
-------
Timothy H. Buchman
========================================
City Center Theater, New York NY
mail address tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland message archive on http://www.mers.com/searchsite.html

Re:Add character to Memo field


Quote
"Terry Neckar" <te...@microcoders.com> wrote in message

news:3b98f749$1_1@dnews...

Quote
> How can I add a character to a memo field one character at a time instead
of
> one line at a time?

Try this:

vod __fastcall Tform1::Button1Click(TObject *Sender)
{
    // to type the string "Hello World" one character at a time
    AnsiString str = "Hello World";

    for(int x = 1; x < str.Length(); x++)
        Type(str[x]);

    Scroll();

Quote
}

void __fastcall TForm1::Type(char c)
{
    if(c == VK_BACK)
    {
        SendMessage(Memo1->Handle, WM_KEYDOWN, (WPARAM)c, MAKELONG(14, 1));
        SendMessage(Memo1->Handle, WM_KEYUP, (WPARAM)c, MAKELONG(49166, 1));
    }
    else
        SendMessage(Memo1->Handle, WM_CHAR, (WPARAM)c, 0);
    }

Quote
}

void __fastcall TForm1::Scroll(void)
{
    Memo1->SelStart = Edit->GetTextLen();
    SendMessage(Memo1->Handle, EM_SCROLLCARET, 0, 0);

Quote
}

Gambit

Re:Add character to Memo field


Yes, you can.  Just make sure you're using the constructor that takes a char
instead of the one that takes an int.

Gambit

"Timothy H. Buchman" <tbuch...@citycenter.org> wrote in message
news:3b990007_2@dnews...

Quote
> You can't say 'a' because the constructor for AnsiString will create the

string "97".

Other Threads