Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to set tab stops in a TMemo 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
Reporting /Printing
Delphi All Versions
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Jonas Bilinkevicius

How to set tab stops in a TMemo


Solve 1:

To change the tab stops for a multiline edit control (i.e. a TMemo), send the 
EM_SetTabStops message to the component. The Tabs array indicates where the tab 
stops will be located. Since the WParam parameter to SendMessage is 1, then all tab 
stops will be set to the value passed in the Tabs array. Remember to set the 
WantTabs property of TMemo to True to enable the tabs.

1   procedure TForm1.FormCreate(Sender: TObject);
2   const
3     TabInc: LongInt = 10;
4   begin
5     SendMessage(Memo1.Handle, EM_SetTabStops, 1, Longint(@TabInc));
6   end;

Solve 2:

For a memo you use the EM_SETTABSTOPS message. Setting decimal tab stops in a memo 
8   procedure TScratchMain.SpeedButton2Click(Sender: TObject);
9   var
10    tabs: array[0..2] of Integer;
11  begin
12    {set first tabstop at 12, second at 24, third at 44 character position, using the
13    average width as base, converted to dialog units.4 dialog units make
14  	one average char width.}
15    tabs[0] := 12 * 4;
16    tabs[1] := 24 * 4;
17    tabs[2] := 44 * 4;
18    Memo1.Clear;
19    Memo1.Lines.Add('01234567890123456789012345678901234567890123456789');
20    Memo1.Lines.Add('Start'#9'One'#9'Two'#9'Three');
21    Memo1.Perform(EM_SETTABSTOPS, 3, LongInt(@tabs));
22    Memo1.Refresh;
23  end;

Note that the message expects the position in an arcane unit called "dialog unit", 4 of which should theoretically equal the average character width of the memos font. But using div 4 does not give the correct positioning, while using div 2 does. Don't ask me why, dialog units are really only sensible in dialogs (which are based on a dialog resource) and are relative to the font used for the dialog itself, not the controls on it.

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


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC