Forum > RichMemo
[solved] RichMemo Searching the quickest way for writing - some digits BOLD
Nicole:
There is a text, where some digits shall be written in bold.
You say, this is no problem?
I agree, if you have just a text and some lines.
In Delphi and RichEdit, I could just set the start of the bold text and then the end.
The select of RichMemo seems to be much more complex.
Or is there an easy way?
This is the method, which generate the content of the Richmemo.
Three figures (not lines) of it shall be bold.
I post the whole text-generation process for you to understand.
No, you need not read this. It is just to illustrate my needs.
It would be great just to fill into the string /hb ............ /he for highlight begin and highlight end.
The language which offered me that, - was not fp.
I would be graete to have somer suggestions, how to make it with a minimum of complexity and maintenance in the future.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- RichEdit_Tradeausgabe.Clear; if Abs(EinTrade_.Pos_) > 1 then begin if StaticText_invisible.Caption <> '' then // Leerabfrage deshalb, weil ich uU einen Mehrpositionentrade schon initial importiere RichEdit_Tradeausgabe.Lines.Add(StaticText_invisible.Caption); // da hätte ich sonst einen Zeilenvorschub durch die Leerzeilen, if StaticText_invisbile_Stop1Kontrakt.Caption <> '' then // weil eben die Positonserhöhung nicht erst importiert wird RichEdit_Tradeausgabe.Lines.Add(StaticText_invisbile_Stop1Kontrakt.Caption); if StaticText_invisbile_target1Kontrakt.Caption <> '' then RichEdit_Tradeausgabe.Lines.Add(StaticText_invisbile_target1Kontrakt.Caption); end; s_Ausgabe:=''; s_Ausgabe:=s_Ausgabe + IntToStr(EinTrade_.Pos_) + ' ' ; if EinTrade_.Pos_ > 0 then s_Ausgabe:=s_Ausgabe + ' long ' else s_Ausgabe:=s_Ausgabe + ' short '; s_Ausgabe:=s_Ausgabe + EinTrade_.Kontraktname; RichEdit_Tradeausgabe.Lines.Add(s_Ausgabe); s_Ausgabe:=''; // wird übertragen und neuer Block begonnen s_Ausgabe:=s_Ausgabe + ' Entry: ' + FloatToStr (EinTrade_.EntryPrice); s_Ausgabe:=s_Ausgabe + ' (' + DateToStr (EinTrade_.EntryDate); if EinTrade_.EntryTime <> 0 then // result:=FormatDateTime('" "dddd" am "dd"."mmmm" "yyyy," "hh":"nn" ""Uhr',dat); FormatDateTime('hh:nn', DeinedateTime) s_Ausgabe:=s_Ausgabe + ' um ' + FormatDateTime('hh:nn', EinTrade_.EntryTime); // TimeToStr (EinTrade_.EntryTime, '"hh":"nn"'); wäre mit Sekunden s_Ausgabe:=s_Ausgabe + ')'; RichEdit_Tradeausgabe.Lines.Add(s_Ausgabe); s_Ausgabe:=''; // wird übertragen und neuer Block begonnen s_Ausgabe:=s_Ausgabe + ' Stop: ' + FloatToStr (EinTrade_.stop); // in Klammer Risiko s_Ausgabe:=s_Ausgabe + ' ($ ' + FloatToStr (EinTrade_.valueAtRisk) + ')'; RichEdit_Tradeausgabe.Lines.Add(s_Ausgabe); StaticText_invisbile_Stop1Kontrakt.Caption:='(pro Kontrakt ' + s_Ausgabe+ ')'; // gesichert für Mehr-Kontraktausgabe s_Ausgabe:=''; // wird übertragen und neuer Block begonnen s_Ausgabe:=s_Ausgabe + ' tar: ' + FloatToStr (EinTrade_.target); // in Klammer Chance und PL s_Ausgabe:=s_Ausgabe + ' ($ ' + FloatToStr (EinTrade_.expectedProfit); StaticText_invisbile_target1Kontrakt.Caption:='(pro Kontrakt ' + s_Ausgabe+ ')'; s_Ausgabe:=s_Ausgabe + ', PL=' + FloatToStrF (EinTrade_.PLR,ffNumber,5,2) + ') '+ #13#10; s_Ausgabe:=s_Ausgabe + ' Exit: ' + FloatToStr (EinTrade_.ExitPrice); s_Ausgabe:=s_Ausgabe + ' (' + DateToStr (EinTrade_.ExitDate); if EinTrade_.ExitTime <> 0 then s_Ausgabe:=s_Ausgabe + ' um ' + FormatDateTime('hh:nn', EinTrade_.ExitTime); // TimeToStr (EinTrade_.ExitTime); wäre mit Sekunden s_Ausgabe:=s_Ausgabe + ')'; RichEdit_Tradeausgabe.Lines.Add(s_Ausgabe); RichEdit_Tradeausgabe.Lines.Add('Beute: '+ MaskEdit_Setup.EditText); if (EinTrade_.daily_limit <> 0) then RichEdit_Tradeausgabe.Lines.Add('Limit Move max: '+ FloatToStr(EinTrade_.daily_limit)); s_Ausgabe:=''; if EinTrade_.Ergebnis <> 0 then // das ist blöd, weil mir das Null Ergebnis dann nicht angezeigt wird begin if EinTrade_.Ergebnis >= 0 then s_Ausgabe:=s_Ausgabe + ' Gewinn: ' else s_Ausgabe:=s_Ausgabe + ' Verlust: '; s_Ausgabe:=s_Ausgabe + FloatToStr (EinTrade_.Ergebnis) end; RichEdit_Tradeausgabe.Lines.Add(s_Ausgabe);
KodeZwerg:
First thing that comes into my mind is that you create a method in different variants (overloaded) to accept your needed input types and in your current method just call it to produce a line of text, ready formatted for RE.
And a small seperate method to add linebreaks.
That you just call your custom lineformatter with your given inputs, put linebreaks etc until the end.
Does that make any sense to you?
rvk:
--- Quote from: Nicole on January 31, 2023, 06:03:35 pm ---In Delphi and RichEdit, I could just set the start of the bold text and then the end.
The select of RichMemo seems to be much more complex.
Or is there an easy way?
--- End quote ---
You mention Delphi and TRichEdit. Isn't it in TRichMemo the same way??
From https://wiki.freepascal.org/RichMemo
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---RichMemo1.SetRangeParams ( RichMemo1.SelStart, RichMemo1.SelLength, [tmm_Styles, tmm_Color], // changing Color and Styles only '', // this is font name - it's not used, thus we can leave it empty 0, // this is font size - it's font size, we can leave it empty clGreen, // making all the text in the selected region green color [fsBold, fsItalic], // adding Bold and Italic Styles [] );
And you are still using TRichMemo.Lines.Add().
That's only for adding UNFORMATTED lines.
Also from https://wiki.freepascal.org/RichMemo
--- Quote ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure InsertFontText( const ARichMemo: TCustomRichMemo; const TextUTF8: String; const prms: TFontParams; InsPos : Integer = -1 )InsertFontText inserts the text and applies specified FontParams to it.
You might want to create a class helper to implement these functions as methods for RichMemo. Beware, if you're using Delphi-compatibility helper - you might right into a conflict.
--- End quote ---
So, if you want to add formatted text you should use TRichMemo.InsertFontText.
Of TRichMemo.Lines.Add and apply RichMemo1.SetRangeParams afterwards (which is more difficult because you need to scan for the Start and Length of your text).
Nicole:
Thank you for your reply.
Unfortunately Delphi's RichEdit and fp's RichMemo differ very much in points of formatting.
In Delphi I had a solution for my "bold", which worked fine. But it did not work with RichMemo.
Believe me, re-use was the first, which I tried.
Delphi is left behind and I will never go back to it.
So I do not need any compatible code.
This
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure InsertFontText( const ARichMemo: TCustomRichMemo; const TextUTF8: String; const prms: TFontParams; InsPos : Integer = -1 )
looks great to me.
How to use it?
e.g. I say "InsertFontText(myRichMemo, 'myBoldAttempt' , ...... aeh 1 ...., aeh 2 .....);
aeh 1
Font Params shall be an array, shall it? Like [...., bold...] ?
Do you have an example how to write the parameters correctly?
aeh 2
How to get the insPos?
and how to stop the bold part?
Just by calling the method again, with a "normal" (or however not-bold may be called) ?
Thank you for your help.
rvk:
Here is an example.
https://wiki.freepascal.org/RichMemo/FAQ#Add_text_with_font
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses ... RichUtilsUtils ....var prms : TFontParams;begin prms := GetFontParams(RichMemo1.Font); prms.Color := clBlue; prms.Style := [fsBold]; // this adds the blue and bolded Hello World at the end of the richmemo // it's possible to pass the 4th parameter to the function to specify // where the text should be added. By default - at the end. InsertFontText(RichMemo1,'hello world', prms);end;
Navigation
[0] Message Index
[#] Next page