Mam taki prosty komponent:
TTwAppleItem = class(TCustomControl)
private
FLabel : TLabel;
FLabelCaption : string;
function GetLabelCaption: string;
procedure SetLabelCaption(const Value: string);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property LabelCaption: string read FLabelCaption write SetLabelCaption;
end;
constructor TTwAppleItem.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 200;
Height := 28;
Color := clWhite;
FLabelCaption := 'TwAppleLabel';
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.Left := 0;
FLabel.Top := 4;
FLabel.Font.Size := 9;
FLabel.Font.Style := [fsBold];
FLabel.Transparent := False;
FLabel.ParentColor := False;
FLabel.Color := clWhite;
FLabel.Caption := FLabelCaption;
end;
destructor TTwAppleItem.Destroy;
begin
FLabel.Free;
inherited Destroy;
end;
function TTwAppleItem.GetLabelCaption: string;
begin
result := FLabelCaption;
end;
procedure TTwAppleItem.SetLabelCaption(const Value: string);
begin
FLabelCaption := Value;
FLabel.Caption := Value;
end;
Komponent jest banalny. I wszystko działa OK do momentu gdy w fazie projektowej ustawię LabelCaption na pusty łańcuch. Wtedy po uruchomieniu programu wyświetla się tekst: 'TwAppleLabel'.
Sprawdziłem, że gdy w LabelCaption jest wpisany pusty string to nie jest ta właściwość zapamiętywana tzn gdy przejdę na View as Text to widać:
object TwAppleItem1: TTwAppleItem
Left = 32
Top = 431
Width = 289
Height = 33
end
a gdy LabelCaption jest z jakimś tekstem to mam:
object TwAppleItem1: TTwAppleItem
Left = 32
Top = 431
Width = 289
Height = 33
LabelCaption = 'COS'
end
Delphi 2007. Proszę o pomoc w czym tkwi problem?
Ps. Jak LabelCaption jest spacją to jest OK.