Recent

Author Topic: [solved] TRichEdit - what to use in Lazarus?  (Read 1429 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
[solved] TRichEdit - what to use in Lazarus?
« on: July 11, 2022, 04:34:54 pm »
Delphi:

var myRichEdit: TRichEdit;

begin
  myRichEdit.SaveToFile('myFile');
end;
________________________
Lazarus:

Var mySomething: TSomething;

begin
  mySomething.LoadFromFile('myfile');
end;
___________________

► What is a good idea to use as "Something" in Lazarus?

Thanks

PS: about lzRichEdit: I gave it a try, but it did not work, because of too many compilation errors.
« Last Edit: July 14, 2022, 06:00:26 pm by Nicole »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: TRichEdit - what to use in Lazarus?
« Reply #1 on: July 11, 2022, 04:54:21 pm »
PS: about lzRichEdit: I gave it a try, but it did not work, because of too many compilation errors.
Where did you get lzTichEdit from?
What version of Lazarus and which OS are you using?

You can try RichMemo in the Online Packagemanager.
« Last Edit: July 11, 2022, 04:57:39 pm by rvk »

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: TRichEdit - what to use in Lazarus?
« Reply #2 on: July 11, 2022, 05:00:09 pm »
Thank you for your answer.

Version 2.2.2
I heard about Richmemo.
But I cannot see it anywhere.

you said: "in the Online Packagemanager" - pls slowly for stupid.
Where can I find a TRichMemo package?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: TRichEdit - what to use in Lazarus?
« Reply #3 on: July 11, 2022, 05:05:10 pm »
you said: "in the Online Packagemanager" - pls slowly for stupid.
Where can I find a TRichMemo package?
In lazarus click Package (in the menu) and choose Online Package Manager.
Type rich in the searchbar.
Now you will get the packages which support rtf.
Check RichMenu and press Install.
Let it download, compile and restart.

Now there is a TRichMemo under the Common Controls (at the end).
This one should be largely compatible with TRichEdit.

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: TRichEdit - what to use in Lazarus?
« Reply #4 on: July 11, 2022, 05:11:59 pm »
You can install RichEdit by using Online Package Manager:
Lazarus main menu > Package > Online Package Manager > enable the checkbox of RichMemo > Install

Wait until it finishes downloading all necessary files and answer yes if it asks to rebuild the IDE.

If you fails to install RichEdit using Online Package Manager, read here:
https://forum.lazarus.freepascal.org/index.php/topic,59567.msg444097.html#msg444097

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: TRichEdit - what to use in Lazarus?
« Reply #5 on: July 11, 2022, 05:18:20 pm »
O, BTW, I said it was largely compatible but there isn't a LoadFromFile.
And TRichMemo.Lines.LoadFromFile doesn't work for TRichMemo.
At least, not that I could find in the 30 seconds I searched  ;)

There is LoadFromText (from stream) but you could easily create a helper function for LoadFromFile.

Code: Pascal  [Select][+][-]
  1. type
  2.   TRichMemoHelper = class helper for TRichMemo
  3.   public
  4.     procedure LoadRTFFromFile(const FileName: string);
  5.   end;
  6.  
  7.   procedure TRichMemoHelper.LoadRTFFromFile(const FileName: string);
  8.   var
  9.     Stream: TStream;
  10.   begin
  11.     Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  12.     try
  13.       Self.LoadRichText(Stream);
  14.     finally
  15.       Stream.Free;
  16.     end;
  17.   end;
  18.  
  19. procedure TForm1.Button1Click(Sender: TObject);
  20. begin
  21.   // RichMemo1.Lines.LoadFromFile('c:\temp\test.rtf'); // doesn't work
  22.   RichMemo1.LoadRTFFromFile('c:\temp\test.rtf');
  23. end;

(took me another 30 seconds to write  :) )

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: [solved] TRichEdit - what to use in Lazarus?
« Reply #6 on: September 21, 2022, 08:54:53 am »
I get an error on Line 2 - unit1.pas(17,3) Error: An interface, helper or Objective-C protocol or category cannot contain fields
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: [solved] TRichEdit - what to use in Lazarus?
« Reply #7 on: September 21, 2022, 09:02:51 am »
I get an error on Line 2 - unit1.pas(17,3) Error: An interface, helper or Objective-C protocol or category cannot contain fields
Show your code because for me this worked.

You'll need to put this code inside your own unit, it isn't a complete standalone unit.
Otherwise you could use the LoadRTFFile from the RichMemoUtils unit.

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: [solved] TRichEdit - what to use in Lazarus?
« Reply #8 on: September 21, 2022, 11:40:49 pm »
Oh yes, it does.
You must know the trick, which was told me by a good guy in this forum some weeks ago.

It reads:
Code: Pascal  [Select][+][-]
  1. LoadRTFFile(RichMemo1, RichEdit_yourFileToLoad);

if you would load from plain text, you have to use
Code: Pascal  [Select][+][-]
  1. RichMemo.Lines.LoadFromFile (yourFileToLoad);

 

TinyPortal © 2005-2018