delphi - Richedit and remove all text from a person content -


so got talking 1 of people , there feel idea hash out current chat sent blocked person bit how twitchtv chat works if person blocked remove persons chats , replace ***

now late when taking brain don't work @ 5am :d been thinking more on how guess have string list current incoming chat search persons name , remove text after persons name

chat format so

simon: test message

so after being muted chat out come like

simon: ** **** *******

any 1 ever done @ seams complex

thanks

if i'm understanding correctly want do, should straightforward;

forget trichedit moment, because solution problem data structures, , richedit merely way of surfacing want in gui.

suppose have tstringlist, chatmessages, append user's name , they've typed, , tstringlist, users, contains list of names.

then, achieve functionality want, need keep track of "who said what", , objects property of chatmessages tstringlist can used that.

so, might have couple of methods this:

function tform1.getuserid(const username : string) : integer; begin   result := users.indexof(username) + 1;   if result = 0 begin     users.add(username);     result := users.indexof(username) + 1;   end;   assert(result > 0); end;  procedure tform1.addchatmsg(username, msg : string); var   userid : integer; begin   userid := getuserid(username);   chatmessages.add('');   chatmessages.addobject(username + ': ' + msg, tobject(userid)); end; 

and procedure periodically update richedit's contents chatmessages.

then, when want "twit" user, can search through chatmessage's objects looking id number. can replace follows in name-tag lines asterisks, likewise in following lines until find user's user-id in objects or reach end of chatmessages. coding of left exercise reader.

it doesn't matter whether asterisks in chatmessage text, or copy text richedit, except on course if in richedit can "untwit" user later refreshing chatmessages without asterisk substitution.

note getuserid above bases user's id on index in users list (plus 1 avoid user having userid of zero, clash lines addobject not used). because of important existing user's indexes don't change when user added list. so, not want users list sorted (or, if need that, you'd need derive userid in different way).

also, i've stored numbers in stringlist's objects property purely make code simple possible illustration purposes. in real-world solution, want use "cleaner" way this, , obvious way have tuser class properties such name, userid , "twit" flag , kind of user-container class, etc, implementational details of in way if included here. once have tuser class, of course, thing store user's tuser instance in stringlist's objects property.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -