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 set tabstops in a TRichEdit 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
50
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How can I set the positions for tabstops in general? I mean, they should be active 
when a new TRichEdit is opened or when an open TRichEdit is filled with text via 
LoadFromFile. I tried it with paragraph.tab but it doesn't do what I want.

Answer:

The property is somewhat screwed up, best use the API way directly: The positions 
need to be specified in twips (1/1440 inch) for the EM_SETPARAFORMAT message. The 
following method sets tabstops every 5 average character positions, based on the 
current paragraphs font.
1   
2   procedure TForm1.Button2Click(Sender: TObject);
3   const
4     tabs: array[0..5] of Integer = (5, 10, 15, 20, 25, 30);
5     teststring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
6   var
7     pf: TParaFormat;
8     i: Integer;
9     charwidth: Integer;
10  begin
11    FillChar(pf, sizeof(pf), 0);
12    pf.cbSize := SizeOf(pf);
13    pf.dwmask := PFM_TABSTOPS;
14    pf.cTabCount := 6;
15    Canvas.Font.Assign(richedit1.SelAttributes);
16    {average charwidth in twips}
17    charwidth := (Canvas.TextWidth(teststring) * 1440) div (Screen.PixelsPerInch *
18      Length(teststring));
19    for i := 0 to High(tabs) do
20      pf.rgxTabs[i] := tabs[i] * charwidth;
21    if richedit1.perform(EM_SETPARAFORMAT, 0, Integer(@pf)) = 0 then
22      ShowMessage('Failed');
23  end;


Add the Richedit unit to your Uses clause. If you do this setting on an empty richedit control it will become the default for new text entered. If you read in formatted text you would have to do a selectAll, then set the tabstops,to make them effective for the loaded text.

			
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