unit MyComponent;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Dialogs, ExtCtrls, Math, StrUtils;
type TPanelButton = record
Left : integer;
Top : integer;
Width : integer;
Height : integer;
Caption : String;
BorderColor : TColor;
FillColor : TColor;
FillCheckColor : TColor;
UnCheckedFont : TFont;
CheckedFont : TFont;
Checked : boolean;
end;
Type TPanelButtons = Array of TPanelButton;
...
MyComponent = class(TPaintBox)
private
VButtonList : TStringList;
...
procedure SetButtonList(Value: TStringList);
AllButtons : TPanelButtons;
published
...
property ButtonList : TStringList read VButtonList write SetButtonList;
public
procedure ReadButtons(List : TStrings; var BTNArr : TPanelButtons);
...
implementation
...
constructor MyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
VButtonList := TStringList.create;
...
end;
procedure MyComponent.SetButtonList(Value: TStringList);
begin
VButtonList.Assign(Value);
ReadButtons(VButtonList, AllButtons);
refresh;
end;
procedure MyComponent.ReadButtons(List : TStrings; var BTNArr : TPanelButtons);
var
i: Integer;
PosKomma : integer;
PosStart : integer;
begin
// Format of Button Strings: Caption,Left,Width,Top,Height
SetLength(BTNArr, List.count);
for i := 0 to List.Count - 1 do
begin
// Caption
PosStart := 1;
PosKomma := Pos(',', List[i]);
BTNArr[i].Caption := Copy(List[i],PosStart,PosKomma-PosStart);
// Left
PosStart := PosKomma+1;
PosKomma := PosEx(',', List[i], PosStart);
BTNArr[i].Left := StrToInt(Copy(List[i],PosStart,PosKomma-PosStart));
// Top
PosStart := PosKomma+1;
PosKomma := PosEx(',', List[i], PosStart);
BTNArr[i].Width := StrToInt(Copy(List[i],PosStart,PosKomma-PosStart));
// Width
PosStart := PosKomma+1;
PosKomma := PosEx(',', List[i], PosStart);
BTNArr[i].Top := StrToInt(Copy(List[i],PosStart,PosKomma-PosStart));
// Height
PosStart := PosKomma+1;
PosKomma := Length(List[i])+1;
BTNArr[i].Height := StrToInt(Copy(List[i],PosStart,PosKomma-PosStart));
// Other Button Options
BTNArr[i].UnCheckedFont := TFont.Create;
BTNArr[i].UnCheckedFont.Color := clBlue;
BTNArr[i].CheckedFont := TFont.Create;
BTNArr[i].CheckedFont.Color := clWhite;
BTNArr[i].BorderColor := clBlue;
BTNArr[i].FillColor := clWhite;
BTNArr[i].FillCheckColor := clBlue;
BTNArr[i].Checked := false;
end;
end;
...
procedure MyComponent.paint();
begin
... hier werden die buttons aus dem Array gezeichnet
end;