I am creating my first custom Delphi component. Its basically a custom Tpanel with header and lines text displayed on it.
I want to be able to add multiple lines text using a stringlist.
When testing the component I cannot get the text lines to display on the panel when adding lines: NewLinesText.add('line1 text')
It does however work when I create and populate a new stringlist at runtime and then assign it to my control : controlPanelitem.NewLinesText = MyNewStringlist
I want to be able to add lines like this: NewLinesText.add('line1 text')
I am using Delphi 7 professional on WinXP. See code below.
Any help would be appreciated!
unit ControlPanelItem;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, Graphics, AdvPanel, StdCtrls,
Windows,Forms,Dialogs;
type
tControlPanelItem = class(TAdvPanel)
private
fLinesText : TStrings;
procedure SetLinesText(const Value: TStrings);
procedure SetText;
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property NewLinesText : TStrings read FLinesText write SetLinesText;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [tControlPanelItem]);
end;
constructor tControlPanelItem.Create(AOwner: TComponent);
begin
inherited;
fLinesText := TStringList.Create;
end;
destructor tControlPanelItem.Destroy;
begin
fLinesText.Free;
inherited;
end;
procedure tControlPanelItem.SetLinesText(const Value: TStrings);
begin
fLinesText.Assign(value);
SetText;
end;
procedure tControlPanelItem.SetText;
var
count : Integer;
begin
for count := 0 to fLinesText.Count - 1 do
ShowMessage(fLinesText.strings[count]);
end;
end.