Forum > RichMemo
[Solved] How to convert this Delphi code to FPC - Lazarus?
(1/1)
lainz:
How to convert this Delphi code to FPC - Lazarus?
I'm using TRichMemo downloaded with OPM, and it doesn't have some of the properties...
--- 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 InterpretESCPOS(const Data: String; ATarget: TRichMemo);var Bold, Underline: Boolean; FontSize: Integer; Alignment: TAlignment; I: Integer; C: Char; S: String;begin Bold := False; Underline := False; FontSize := 10; // default font size Alignment := taLeftJustify; // default alignment S := ''; I := 1; while I <= Length(Data) do begin C := Data[I]; Inc(I); if C = #27 then // ESC begin if I > Length(Data) then Break; C := Data[I]; Inc(I); case C of 'E': // Bold begin Bold := True; ATarget.SelAttributes.Style := [fsBold]; end; 'F': // Not bold begin Bold := False; ATarget.SelAttributes.Style := []; end; '-': // Underline begin if I > Length(Data) then Break; C := Data[I]; Inc(I); case C of #0: Underline := False; #1: Underline := True; end; if Underline then ATarget.SelAttributes.Style := ATarget.SelAttributes.Style + [fsUnderline] else ATarget.SelAttributes.Style := ATarget.SelAttributes.Style - [fsUnderline]; end; 'a': // Alignment begin if I > Length(Data) then Break; C := Data[I]; Inc(I); case C of #0: Alignment := taLeftJustify; #1: Alignment := taCenter; #2: Alignment := taRightJustify; end; ATarget.Paragraph.Alignment := Alignment; end; end; end else if C = #29 then // GS begin if I > Length(Data) then Break; C := Data[I]; Inc(I); case C of '!': // Font size begin if I > Length(Data) then Break; C := Data[I]; Inc(I); case C of #0: FontSize := 10; // replace with your desired sizes #1: FontSize := 15; #2: FontSize := 20; end; ATarget.SelAttributes.Size := FontSize; end; end; end else begin S := S + C; end; end; ATarget.Lines.Add(S);end;
rvk:
There are helpers for access to SelAttributes.
https://wiki.freepascal.org/RichMemo#TRichEditForMemo
--- Quote ---TRichEditForMemo
The class helper that implements RichEdit programmatic interface. The helper is declared at RichEditHelpers unit, so you have to add it to the uses section. Helpers are available in FPC 2.6.0 or later.
--- End quote ---
So, just include RichEditHelpers in your uses.
(You'll need to be on the latest Laz 2.6.0)
lainz:
--- Quote from: rvk on May 11, 2023, 05:32:37 pm ---There are helpers for access to SelAttributes.
https://wiki.freepascal.org/RichMemo#TRichEditForMemo
--- Quote ---TRichEditForMemo
The class helper that implements RichEdit programmatic interface. The helper is declared at RichEditHelpers unit, so you have to add it to the uses section. Helpers are available in FPC 2.6.0 or later.
--- End quote ---
So, just include RichEditHelpers in your uses.
(You'll need to be on the latest Laz 2.6.0)
--- End quote ---
Many thanks
lainz:
Solved, notice that the name of the unit is RichMemoHelpers and not RichEditHelpers.
And the code I posted has a bug, please if you need to use it replace this line:
--- 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";}};} ---Alignment: TAlignment;
With this line:
--- 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";}};} ---Alignment: TRichEditAlignment;
Navigation
[0] Message Index