Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get TRichEdit to use the RichEd20.dll Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
18
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is there any easy way to get TRichEdit to use RichEd20.dll? We need to use the 
latest RTF v3, not the 1.0 currently supported by TRichEdit.

Answer:

It's better to use a third-party wrapper, but you can try to trick the standard 
TRichEdit. Override CreateParams and call CreateSubClass(Params, RICHEDIT_CLASS) 
there. The RICHEDIT_CLASS constant designates a Rich Edit version 2.0 and higher 
control. Also, you should call the LoadLibrary('RICHED20.DLL') function to verify 
which version of Rich Edit is installed. Check the code listed below for details. 
There is additional code to suppress exceptions, which the RichEdit strings object 
generates, after the new string was inserted.

1   { ... }
2   type
3     TMyRichEdit20 = class(TRichEdit)
4     protected
5       FMax: integer;
6       FSelection: TCharRange;
7       procedure EMExSetSel(var message: TMessage); message EM_EXSETSEL;
8       procedure EMReplaceSel(var message: TMessage); message EM_REPLACESEL;
9       function GetSelStart: integer; override;
10      procedure CreateParams(var Params: TCreateParams); override;
11    public
12      constructor Create(AOwner: TComponent); override;
13    end;
14  
15    { ... }
16  
17  constructor TMyRichEdit20.Create(AOwner: TComponent);
18  begin
19    inherited Create(AOwner);
20    FMax := 0;
21    FSelection.cpMin := 0;
22    FSelection.cpMax := 0;
23  end;
24  
25  procedure TMyRichEdit20.EMExSetSel(var message: TMessage);
26  var
27    ISel: integer;
28    XSel: ^TCharRange absolute ISel;
29  begin
30    inherited;
31    ISel := message.LParam;
32    FSelection := XSel^;
33  end;
34  
35  procedure TMyRichEdit20.EMReplaceSel(var message: TMessage);
36  begin
37    inherited;
38    FMax := FSelection.cpMax + length(PChar(message.LParam));
39  end;
40  
41  function TMyRichEdit20.GetSelStart: Integer;
42  begin
43    if FMax = 0 then
44      Result := inherited GetSelStart
45    else
46    begin
47      Result := FMax;
48      FMax := 0;
49    end;
50  end;
51  
52  var
53    FRichEditModule: THandle;
54  
55  procedure TMyRichEdit20.CreateParams(var Params: TCreateParams);
56  begin
57    if FRichEditModule = 0 then
58    begin
59      FRichEditModule := LoadLibrary('RICHED20.DLL');
60      if FRichEditModule <= HINSTANCE_ERROR then
61        FRichEditModule := 0;
62    end;
63    inherited CreateParams(Params);
64    CreateSubClass(Params, RICHEDIT_CLASS);
65  end;
66  
67  { ... }
68  
69  initialization
70  
71  finalization
72    if FRichEditModule <> 0 then
73      FreeLibrary(FRichEditModule);
74  
75  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC