多谢Pipi,但如果我想写一个控件,具有Tabstop属性,并且一开始就设置其初始值为两个字符宽度,结果始终它默认为8个字符宽度,问怎么解决?以下是我写的控件代码:
unit ERichEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, ComCtrls;
type
TERichEdit = class(TRichEdit)
private
FTabStops:Integer;
procedure SetTabStops(Value:Integer);
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
function FindText(const SearchStr:string;StartPos,Leng:Integer;Options:TSearchTypes;Down:Boolean):Integer;overload;
published
property TabStops:Integer read FTabStops write SetTabStops;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('woodmud', [TERichEdit]);
end;
{ TERichEdit }
constructor TERichEdit.Create(AOwner: TComponent);
begin
inherited;
Font.Name:='Courier New';
Font.Size:=10;
FTabStops:=32;
end;
function TERichEdit.FindText(const SearchStr: string; StartPos,
Leng: Integer; Options: TSearchTypes; Down: Boolean): Integer;
var
SPos,Len,FoundAt,LenStr,ToEnd:Integer;
begin
if Down then
FoundAt:=FindText(SearchStr,StartPos,Leng,Options)
else
begin
SPos:=StartPos;
LenStr:=Length(SearchStr);
ToEnd:=StartPos+Leng;
repeat
FoundAt:=SPos-LenStr;
Len:=ToEnd-SPos;
SPos:=FindText(SearchStr,SPos,Len,Options)+LenStr;
until SPos=LenStr-1;
if FoundAt=StartPos-LenStr then FoundAt:=-1;
end;
Result:=FoundAt;
end;
procedure TERichEdit.SetTabStops(Value: Integer);
begin
if FTabStops<>Value then
begin
FTabStops:=Value;
Perform(EM_SETTABSTOPS,1,Integer(@Value));
end;
end;
end.