{-- SetTabstops -------------------------------------------------------}
{: Set tabstops at the indicated positions in the current paragraph
@Param re is the richedit control to modify
@Param TabPositions is an array of positions to set. The unit used
are inches and the array needs to be sorted.
@Precondition re <> nil
@Desc Note: if the TabPositions array contains more than MAX_TAB_STOPS
entries the extras will not be used.
}{ Created 2004-04-15 by P. Below
-----------------------------------------------------------------------}
procedure SetTabstops( re: TRichedit; TabPositions:
array of single );
Var
pf: TParaFormat;
i : Integer;
charwidth : Integer;
begin
Assert( Assigned( re ), '
SetTabstops: re cannot be nil' );
FillChar( pf, sizeof(pf), 0);
pf.cbSize := Sizeof( pf );
pf.dwmask := PFM_TABSTOPS;
if High(TabPositions) >= MAX_TAB_STOPS
then
pf.cTabCount := MAX_TAB_STOPS
else
pf.cTabCount := High(TabPositions)+1;
For i:= 0
To pf.cTabCount-1
Do
pf.rgxTabs[i] := Trunc(TabPositions[i] * 1440);
re.perform( EM_SETPARAFORMAT, 0, Integer( @pf ));
end;
{ SetTabstops }
procedure TForm1.Button1Click(Sender: TObject);
begin
with RichEdit1
do
begin
Clear;
SelStart := GetTextLen;
// position caret at end
SelAttributes.Style := [];
SelAttributes.Color := clBlack;
SetTabstops( richedit1, [0.5, 1.0, 1.5, 2.5] );
SelText := '
STRING1'+#9+'
STRING2'+#9+'
STRING3'+#13#10+
'
A'#9'
B'#9'
C'#9'
D'#9'
E';
end;
end;