Meine Komponente basiert auf einem TCustomPanel. Müßte demnach nicht ein
Handle automatisch vorhanden sein? Und darauf sind auch Panels. Müßten die nicht automatisch ein
Handle erhalten?
Die Paintboxen bekommen nach ihrem Create als ersten das Parent ihres Panels, auf dem sie gezeichnet werden.
Hier mal meine komplette Createmothode:
Delphi-Quellcode:
constructor TUrlaubsplaner.Create(AOwner: TComponent); //TCustomPanel
begin
inherited Create(AOwner);
self.FLog:=TStringList.Create;
self.FPersons:=TPersons.Create(TPerson);
self.FEntryTypes:=TEntryTypes.Create(TEntryType);
self.FEntries:=TEntries.Create(TEntry);
self.FColors:=TtuColors.Create;
Self.FFonts:=TFonts.Create;
self.FLineWidth:=TLineWitdh.Create;
self.FOptions:=TOptions.Create;
self.FShowMonths:=True;
self.FColumnDayWidth:=20;
self.FStartDay:=Now;
self.FEndDay:=now+10;
self.FRowSpacing:=4;
self.FMousePressed:=False;
FPanelLeft:= TPanel.Create(Self); //alLeft
FPanelLeft.Parent:=Self;
FPanelLeft.Align:=alLeft;
FPanelLeft.Width:=80;
FPanelLeft.BevelOuter:=bvNone;
FPanelLeftBottom:=TPanel.Create(Self); //alBottom
FPanelLeftBottom.Parent:=FPanelLeft;
FPanelLeftBottom.Align:=alBottom;
FPanelLeftBottom.Height:=17;
FPanelLeftBottom.BevelOuter:=bvNone;
FPanelLeftBottom.Color:=self.FColors.Color;
FPanelLeftTop:=TPanel.Create(Self); //alTop
FPanelLeftTop.Parent:=FPanelLeft;
FPanelLeftTop.Align:=alTop;
FPanelLeftTop.Height:=40;
FPanelLeftTop.BevelOuter:=bvNone;
FPanelLeftTop.Color:=self.FColors.Color;
FPanelPersonal:=TPanel.Create(Self); //alClient
FPanelPersonal.Parent:=FPanelLeft;
FPanelPersonal.Align:=alClient;
FPanelPersonal.BevelOuter:=bvNone;
FSplitter:=TSplitter.Create(self);
FSplitter.Parent:=Self;
FSplitter.Left:=185;
FSplitter.Align:=alLeft;
FSplitter.Color:=clSilver;
FPanelRight:=TPanel.Create(Self); //alClient
FPanelRight.Parent:=self;
FPanelRight.Align:=alClient;
FPanelRight.BevelOuter:=bvNone;
FPanelRightBottom:=TPanel.Create(Self); //alBottom
FPanelRightBottom.Parent:=FPanelRight;
FPanelRightBottom.Align:=alBottom;
FPanelRightBottom.Height:=17;
FPanelRightBottom.BevelOuter:=bvNone;
FPanelRightBottomRight:=TPanel.Create(self); //alRight
FPanelRightBottomRight.Parent:=FPanelRightBottom;
FPanelRightBottomRight.Align:=alRight;
FPanelRightBottomRight.Width:=17;
FPanelRightBottomRight.BevelOuter:=bvNone;
FPanelRightBottomRight.Color:=self.FColors.Color;
FScrollbarHorizontal:=TScrollbar.Create(Self); //alRight
FScrollbarHorizontal.Parent:=FPanelRightBottom;
FScrollbarHorizontal.Kind:=sbHorizontal;
FScrollbarHorizontal.Align:=alClient;
FScrollbarHorizontal.OnScroll:=OnHorizontalScroll;
FPanelRightTop:=TPanel.Create(Self); //alTop
FPanelRightTop.Parent:=FPanelRight;
FPanelRightTop.Align:=alTop;
FPanelRightTop.Height:=40;
FPanelRightTop.BevelOuter:=bvNone;
FPanelRightTopRight:=TPanel.Create(Self); //alRight
FPanelRightTopRight.Parent:=FPanelRightTop;
FPanelRightTopRight.Align:=alRight;
FPanelRightTopRight.Width:=17;
FPanelRightTopRight.BevelOuter:=bvNone;
FPanelRightTopRight.Color:=self.FColors.Color;
FPanelDate:=TPanel.Create(Self); //alClient
FPanelDate.Parent:=FPanelRightTop;
FPanelDate.Align:=alClient;
FPanelDate.BevelOuter:=bvNone;
FPanelDays:=TPanel.Create(Self); //alClient
FPanelDays.Parent:=FPanelRight;
FPanelDays.Align:=alClient;
FPanelDays.BevelOuter:=bvNone;
FScrollbarVertical:=TScrollBar.Create(Self); //alClient
FScrollbarVertical.Parent:=FPanelDays;
FScrollbarVertical.Kind:=sbVertical;
FScrollbarVertical.Align:=alRight;
FScrollbarVertical.OnScroll:=OnVerticalScroll;
FDatePaint:=TPaintBox.Create(self);
FDatePaint.Parent:=FPanelDate;
FPanelLeftTop.Height:=GetDateHeight; //Hier könnte der Fehler sein.
FPanelRightTop.Height:=GetDateHeight;
FDatePaint.Left:=0;
FDatePaint.Top:=0;
FDatePaint.Height:=FPanelDate.Height;
FPersonPaint:=TPaintBox.Create(self);
FPersonPaint.Parent:=FPanelPersonal;
FPersonPaint.Left:=0;
FPersonPaint.Top:=0;
FPersonPaint.Width:=FPanelPersonal.Width;
FGridPaint:=TPaintBox.Create(self);
FGridPaint.Parent:=FPanelDays;
FGridPaint.Left:=0;
FGridPaint.Top:=0;
FGridPaint.OnMouseUp:=OnGridMouseUp;
FGridPaint.OnMouseDown:=OnGridMouseDown;
FGridPaint.OnMouseMove:=OnGridMouseMove;
FGridPaint.OnDblClick:=OnGridDblClick;
Self.Clear;
end;
destructor TUrlaubsplaner.Destroy;
begin
self.FPersons.Free;
self.FEntryTypes.Free;
Self.FEntries.Free;
Self.FColors.Free;
self.FFonts.Free;
self.FLineWidth.Free;
self.FOptions.Free;
self.FLog.Free;
inherited;
end;
Und hier mein GetDateHeight-Function, ich ich im Create aufrufe:
Delphi-Quellcode:
function TUrlaubsplaner.GetDateHeight: Integer;
var
m, dn, d: Integer;
begin
FDatePaint.Font:=Self.FFonts.MonthFont;
m:=FDatePaint.Canvas.TextHeight('00');
FDatePaint.Font:=self.FFonts.DateFont;
d:=FDatePaint.Canvas.TextHeight('00');
dn:=FDatePaint.Canvas.TextHeight('00');
Result:=d+4;
if self.FOptions.ShowDayNames then
Result:=Result+dn+4;
if self.FShowMonths then
Result:=Result+m+4;
FIntMonthHeight:=m+4;
FIntDayNameHeight:=dn+4;
FIntDayCountHeight:=d+4;
end;