Lazarus
Programming => Packages and Libraries => RichMemo => Topic started by: snorkel 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.
-
SelAtrributes property is read only.
property SelAttributes: TTextAttributes read FSelAttributes;
RichBox.pas, line 126 on my installation.
-
it's not read only in LzRichEdit, trichmemo it is.
-
lzRichEdit.
My installation is not up to date.
So why it does not work?
-
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.
-
Sure, it should not be so. Not implemented yet.
-
this works in the demo that's included with lzrichedit:
lzRichEdit1.SelAttributes.Color:=
Typo, are you the author of LzRichEdit? Just wondering.
-
No.
-
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
-
This works, don't ask why:
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');
-
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.
-
// 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');
-
I came up with this using trichmemo:
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;
-
in case anyone is interested this works in trichmemo and probably lzrichedit in win32/win64
http://www.swissdelphicenter.ch/en/showcode.php?id=1147
-
In a translating system i need ...
Editor.SelAttributes.BackColor := ... Set background color of a selected text.
-
Just added. You can download it from here:
http://wiki.freepascal.org/lzRichEdit#Download
-
If you need mixed coloring then this is an example that will add a new line with several different colored words to TRichMemo:
Example:
Black, Green, Blue, Red
Black, Green, Blue, Red
Black, Green, Blue, Red
Since none of forum examples worked for me, I found this working on Windows:
procedure TForm1.Button1Click(Sender: TObject);
procedure AddColorStr(s: string; const col: TColor = clBlack; const NewLine: boolean = true);
begin
with RichMemo1 do
begin
if NewLine then
begin
Lines.Add('');
Lines.Delete(Lines.Count - 1); // avoid double line spacing
end;
SelStart := Length(Text);
SelText := s;
SelLength := Length(s);
SetRangeColor(SelStart, SelLength, col);
// deselect inserted string and position cursor at the end of the text
SelStart := Length(Text);
SelText := '';
end;
end;
begin
AddColorStr('Black, ');
AddColorStr('Green, ', clGReen, false);
AddColorStr('Blue, ', clBlue, false);
AddColorStr('Red', clRed, false);
end;
Hopefully someone having the same problem will find it, or decide to extend TRichMemo with a method that appends colored text... ;)
Here is step by step tutorial: http://lazplanet.blogspot.com/2013/12/create-rich-text-editor-for-yourself.html
UPDATE1: I have just updated the Wiki. It would be nice if someone could test if this works on any other OS.
UPDATE2: Two more examples added: http://wiki.freepascal.org/RichMemo#Append_mixed_color_text_at_the_end_of_the_RichMemo
UPDATE3: Fixed scrolling error by changing example. Added link to blog tutorial.
-
I'm using TIpHTMLPanel or THTMLPort for chat type app. You can then do whatever you want with text formatting and also add emoticons inside text
-
I try to use richmemo for save in database but when i restore the rtc text the image gone only text show me i don't know what kind of image is support for richmemo i try jpg, also i dont know is save rtf in sqlite works or not bur for now i don't get its works for me.
-
This don't works on trichmemo i tested if you tested can you put your code pls.
-
lzRichEdit example attached.
-
I'm using TIpHTMLPanel or THTMLPort for chat type app. You can then do whatever you want with text formatting and also add emoticons inside text
Hi there Dibo. Would you mind showing me how you did that?
Thanks,
JD