读书人

不好意思再问一个组件编程有关问题

发布时间: 2012-02-28 13:06:35 作者: rapoo

不好意思再问一个组件编程问题!
我想编一个控件,继承自Tedit控件,所做的唯一改变就是,增加一个新属性RowText,
需要满足的条件是:
RowText是string型,而且它的值随着edit.text值的改变而改变,也就是说它的值与edit.text的值同步,我编写了如下的代码,可是好象程序进入死循环,最后总是益出,请指教!谢谢!


unit TextEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
TTextEdit = class(TCustomMemo)
private
{ Private declarations }
FRawText : string;
FText : string;
Flabel : Tlabel;
Fuseable : Boolean;
procedure Setuseable(AA: Boolean);
procedure Setlabel(Lb: Tlabel);
function GetRawText: String;
Procedure SetRawText(BB: string);
function GetText: String;
Procedure SetText(CC: string);
protected

public
constructor Create(AOwner: TComponent); override;
property RawText:string Read GetRawText write SetRawText;
published
{ Published declarations }
property Alignment default taLeftJustify;
property BorderStyle;
property CharCase;
property Color;
property Ctl3D;
property Font;
property visible;
property Text:string read GetText write SetText;
property MaxLength;
property PasswordChar;
property HideSelection;
property ImeMode;
property ImeName;
property ShowHint;
property TabOrder;
property TabStop;
property Title :Tlabel read Flabel write Setlabel;
property Useable: Boolean read Fuseable write Setuseable;
property ReadOnly;

property OnChange;
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;


property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;

procedure Register;

implementation
constructor TTextEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height := 22; Width := 121;
WordWrap := False; WantReturns := False;
Useable := True;
end;


procedure TTextEdit.Setlabel(Lb: Tlabel);
begin
if Flabel <> Lb then
Flabel:=Lb;
end;

procedure TTextEdit.SetRawText(BB: string);
begin
if Text <> BB then
Text:=BB;
end;

function TTextEdit.GetRawText:string;
begin
if FRawText <> text then
result:=text;
end;

procedure TTextEdit.SetText(CC: string);
begin
if RawText <> CC then
RawText:=CC;
end;

function TTextEdit.GetText:string;
begin
if text <> RawText then
result:=RawText;
end;

procedure TTextEdit.Setuseable(AA: Boolean);
begin
if Fuseable <> AA then
BEGIN
Fuseable:= AA;
enabled := AA;
if AA then
Color:=clWindow
else
Color:=clSilver;
end;
end;

procedure Register;
begin
RegisterComponents( 'WintekIT Ctrl ', [TTextEdit]);
end;

end.



[解决办法]
这样有啥用,不明白
赋值的时候,注意一个

Text:=BB; 应该是FText:=BB; 要不继续执行SetText

读书人网 >.NET

热点推荐