🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17150

Re: How to get assuring value of SelStart

#17150
From: Remy Lebeau (TeamB)
Date: Mon, 07 Apr 2003 17:27
35 lines
2100 bytes
"Sky" <akeehuang@163.net> wrote in message
news:3e919b72$1@newsgroups.borland.com...

>     if (!ActiveControl->ClassNameIs("TEdit")) return;
>
>     TEdit *edit = dynamic_cast<TEdit *>(ActiveControl);

Since you're doing the dynamic_cast anyway, then the call to ClassNameIs()
is redundant and aonly adds extra runtime overhead.  Do this instead:

    void __fastcall TMainForm::Input_Symbol(AnsiString szSymbol)
    {
        TEdit *edit = dynamic_cast<TEdit *>(ActiveControl);
        if( !edit ) return;

>         int t = edit->SelStart;
>         AnsiString szText = edit->Text;
>         szText.Insert(szSymbol, t + 1);
>         edit->Text = szText;
>         edit->SelStart = t + szSymbol.Length();

You could use just the SelStart, SelLength, and SelText properties to
simplify that, then you don't need the temporary AnsiString at all:

    int t = edit->SelStart;
    edit->SelLength = 0;
    edit->SelText = szSymbol;
    edit->SelStart = t + szSymbol.Length();

When SelLength is 0, SelText inserts the new text into the edit control at
the position where SelStart is.


Gambit
Technical Details
Message-ID: <3e91b517$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!ken-transit.news.telstra.net!news.telstra.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3e919b72$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e296741773c2fdfb
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-07 10:32:06 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e919b72$1@newsgroups.borland.com>
Subject: Re: How to get assuring value of SelStart
Date: Mon, 7 Apr 2003 10:27:30 -0700
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3e91b517$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049736471 207.175.226.26 (7 Apr 2003 10:27:51 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!ken-transit.news.telstra.net!news.telstra.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail