2

Using delphi 7 TRichEdit component, RTF data is being imported from a msword document through copy and paste, but if data is contained in a box, it is not displaying correctly i.e.

enter image description here

Please assist

TLama
  • 75,147
  • 17
  • 214
  • 392
KE50
  • 546
  • 1
  • 7
  • 17
  • If you paste it to WordPad, does it display it correctly? – Sertac Akyuz May 08 '12 at 12:22
  • Yes it appears well but using the RTF editors from RX and from Delphi,the layout changes. – KE50 May 08 '12 at 12:33
  • 2
    That's got to do something with the version of the richedit control used by the VCL. I'm sure someone will remember the details.. – Sertac Akyuz May 08 '12 at 12:35
  • 2
    I think Sertac is right, maybe you can try to *upgrade* to a newer version like [`François`](http://stackoverflow.com/users/9842/francois) described on [`his blog`](http://fgaillard.com/2010/09/using-richedit-4-1-with-d2010/). – TLama May 08 '12 at 12:53
  • SertacAkyuz and TLama thanks for the prompt replies i think this is the way to go, only problem is the fix by Francois is for delphi 10. – KE50 May 08 '12 at 13:20

2 Answers2

3

Try to use the following, it should subclass the TRichEdit class to version 4.1. However I don't know if Delphi 7 supports interposed classes, so just try to paste the following code and try to build the project.
If it compiles then if you put a TRichEdit component and run the project you should get RichEdit 4.1.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, RichEdit;

type
  TRichEdit = class(ComCtrls.TRichEdit)
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  end;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  FRichEditModule: THandle;

implementation

{$R *.dfm}

{ TRichEdit }

procedure TRichEdit.CreateParams(var Params: TCreateParams);
const
  RichEditClassName = 'RICHEDIT50A';
  RichEditModuleName = 'MSFTEDIT.DLL';
  HideScrollBarsStyle: array[Boolean] of DWORD = (ES_DISABLENOSCROLL, 0);
  HideSelectionsStyle: array[Boolean] of DWORD = (ES_NOHIDESEL, 0);
begin
  if FRichEditModule = 0 then
  begin
    FRichEditModule := LoadLibrary(RichEditModuleName);
    if FRichEditModule <= HINSTANCE_ERROR then
      FRichEditModule := 0;
  end;
  inherited CreateParams(Params);    
  CreateSubClass(Params, RichEditClassName);
  Params.Style := Params.Style or HideScrollBarsStyle[HideScrollBars] or
    HideSelectionsStyle[HideSelection];
  Params.WindowClass.style := Params.WindowClass.style and
    not (CS_HREDRAW or CS_VREDRAW);
end;

initialization

finalization
  if FRichEditModule <> 0 then
    FreeLibrary(FRichEditModule);

end.
TLama
  • 75,147
  • 17
  • 214
  • 392
  • 1
    IIRC the RxRichEdit already used RICHED20.DLL. If it doesn't display the box correctly OP should perhaps aim for 'RICHEDIT50W' (or perhaps 'RICHEDIT50A' if it has got an Ansi counterpart) as you've mentioned in your comment to the question. – Sertac Akyuz May 08 '12 at 14:12
  • @Sertac, there is already version 5.0 ? Never noticed that (I'm not an advanced rich edit user, I've been just satisfied with 2.0 :-) And I really lost an overview what's in Delphi 7 (I was thinking about v.1.0). – TLama May 08 '12 at 14:20
  • it gives a 'RichEdit Line Insertion' error after adding a TRichEdit component – KE50 May 08 '12 at 14:22
  • 1
    @TLama - Well, I was reading the blog you mentioned. AFAIU that's the class name for the 4.1 version. Confusing.. – Sertac Akyuz May 08 '12 at 14:23
  • @Sertac, they're thinking of the future :-) K-E, I'm afraid I can't help you more with it. Without Delphi 7 it's just guessing from my side. I've made an update to reflect the RichEdit 4.1 version (5.0 class version), but I can't test it anywhere. – TLama May 08 '12 at 14:30
  • Have tested it, it still wont work. Thanks alot, though will have to find another way round it, BUT, it did compile and I was able to add a Rich Edit on the form created only problem it still could not address the formatting issue. – KE50 May 08 '12 at 14:34
  • 1
    I confirm the modified answer works in D7. However I cannot confirm it will help or not, since when I paste a text box from Word to WordPad there's no box at all. – Sertac Akyuz May 08 '12 at 14:34
2

Finally got it to work,

It was as simple as adding the Riched20.dll (Latest version) to the application folder

KE50
  • 546
  • 1
  • 7
  • 17