Delphi 7 TRichTextEdit Text in a box not displaying correctly

别来无恙 提交于 2019-12-08 02:25:25

问题


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.

Please assist


回答1:


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.



回答2:


Finally got it to work,

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



来源:https://stackoverflow.com/questions/10498332/delphi-7-trichtextedit-text-in-a-box-not-displaying-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!