Recent

Author Topic: Anyone using lzrichedit or trichmemo for a chat type app?  (Read 16585 times)

snorkel

  • Hero Member
  • *****
  • Posts: 817
Anyone using lzrichedit or trichmemo for a chat type app?
« on: August 18, 2014, 08:28:22 pm »
I am trying to convert some delphi code that does stuff like this:

re1.SelAttributes.Color:=clred;
re1.SelText:='word 1';   //word 1 is red
re1.SelAttributes.Color:=clnavy;
re1.SelText:='word 2'  //word 2 is navy

This does not work at all(it just puts in plain text instead of coloured) in LzRichedit.




« Last Edit: August 18, 2014, 08:31:05 pm by snorkel »
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #1 on: August 18, 2014, 08:58:48 pm »
SelAtrributes property is read only.

Code: [Select]
property SelAttributes: TTextAttributes read FSelAttributes;

RichBox.pas, line 126 on my installation.

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #2 on: August 18, 2014, 09:06:21 pm »
it's not read only in LzRichEdit, trichmemo it is.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #3 on: August 18, 2014, 09:09:08 pm »
lzRichEdit.

My installation is not up to date.

So why it does not work?

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #4 on: August 18, 2014, 09:13:14 pm »
lzRichEdit.

My installation is not up to date.

So why it does not work?

oops sorry you are correct it is read only but properties it contains are read/write like style and color.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #5 on: August 18, 2014, 09:15:22 pm »
Sure, it should not be so. Not implemented yet.

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #6 on: August 18, 2014, 09:19:45 pm »
this works in the demo that's included with lzrichedit:

lzRichEdit1.SelAttributes.Color:=

Typo, are you the author of LzRichEdit?  Just wondering.
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #7 on: August 18, 2014, 09:23:00 pm »
No.

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #8 on: August 18, 2014, 11:08:29 pm »
The problem I am having with lzrichedit is setting the text attributes in code.
for example if a new chat message comes in i want the the datetime in say clred, the username in clnavy and bold etc
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #9 on: August 18, 2014, 11:50:44 pm »
This works, don't ask why:

Code: [Select]
  re.SelText:='word 1';   //word 1 is red
  re.setfocus;
  re.selstart := re.selstart - length('word 1');
  re.SelLength := length('word 1');
  re.setfocus;
  re.SelAttributes.Color:=clred;
  re.sellength := 0;
  re.selstart := re.selstart + length('word 1');

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #10 on: August 19, 2014, 12:39:28 am »
how about setting the attribute after a valid selection is made, ee add the new text select it and then set the color or other attributes moving the caret to end of the selection after everything is done to avoid replacing the selected text in the next iteration.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #11 on: August 19, 2014, 12:46:46 am »
Code: [Select]
  // Insert the unformatted text
  re.SelText:='word 1';   //word 1 is red
  re.setfocus;

  // Select the inserted text
  re.selstart := re.selstart - length('word 1');
  re.SelLength := length('word 1');
  re.setfocus;

  // Set attributes
  re.SelAttributes.Color:=clred;

  //  Unselect
  re.sellength := 0;
  re.selstart := re.selstart + length('word 1');

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #12 on: August 19, 2014, 09:27:41 pm »
I came up with this using trichmemo:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
 fp:TFontParams;
 current_user:string;
begin
     current_user:='Joe User';
     send_memo.Lines.BeginUpdate;
     try
        //get the send text
        send_memo.SelectAll;
        send_memo.CutToClipboard;
        //insert time to receive_memo;
        receive_memo.selText:=FormatDateTime('(hh:mm:ss AM/PM) ',now);
        //set time color
        fp.Color:=clnavy;
        fp.Style:=[];
        receive_memo.SetTextAttributes(receive_memo.SelStart,receive_memo.SelLength,fp);
        receive_memo.SelStart:=receive_memo.GetTextLen;
        //Add username
        fp.Style:=[fsbold];
        receive_memo.SelText:=format('%s ',[current_user]);
        receive_memo.SetTextAttributes(receive_memo.SelStart,receive_memo.SelLength,fp);
        receive_memo.SelStart:=receive_memo.GetTextLen;
        //add the send text to receive memo
        receive_memo.PasteFromClipboard;
        receive_memo.Lines.Append('');
        receive_memo.Lines.Delete(receive_memo.Lines.Count-1);
        fp.Style:=[];
        fp.Color:=clDefault;
     finally
            send_memo.Lines.endUpdate;
     end;
end;
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #13 on: August 19, 2014, 10:29:06 pm »
in case anyone is interested this works in trichmemo and probably lzrichedit in win32/win64

http://www.swissdelphicenter.ch/en/showcode.php?id=1147
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: Anyone using lzrichedit or trichmemo for a chat type app?
« Reply #14 on: November 19, 2014, 10:23:23 pm »
In a translating system i need ... 

Editor.SelAttributes.BackColor := ...   Set background color of a selected text.
Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

 

TinyPortal © 2005-2018