Hallo !
Ich habe ein Delphi Projekt, das folgendes macht: eine Status bar, in der Text angezeigt wird (dynamischer Text).
Da sich der Text zur Laufzeit ändert, kann ich kein PageScroller verwenden.
Also will ich das selber bauen.
Habe folgendes gemacht (auf einem Formular zum Testen, nciht als Komponente):
Parent Panel, Align Bottom
Da drauf zwei weitere Panels, das eine links und das andere rechts alignt ist, breite 12 Pixel breit.
In die Mitte ein Middle Panlel, ALClient.
Auf das Middle Panel ein Text Panel, das den Text beinhaltet und das gescrollt werden soll (kein Alignment).
Auf die beiden Panels am Rand (links un rechts) habe ich anfangs einen Speedbutton gesetzt.
Wenn ich den linken drücke, wird der Text nach links gescrollt, wenn ich den rechten drücke, scrollt der Text nach rechts.
Natürlich habe ich noch Abfragen drinnen, die die Buttons bei Bedarf ein und ausblenden.
Funktioniert bestens.
Da aber die Speedbuttons immer unten bleiben habe ich anstelle von ihnen Panels genommen.
Da der Text auf einem Panel bei "disabled" nicht deaktiviert dargestellt wird, sind auf den Panels jeweils ein label.
Also anstelle eines Speedbuttons habe ich ein Panel mit Label drauf.
TButton hat leider beim Klicken um die Caption herum einen gepunkteten Rand und er ist nicht flat, daher habe ich mich für diese Lösung entschieden.
Auf einem Formular geht es wunderbar.
Wenn ich das ganze als Komponente mache, habe ich folgendes Problem:
Habe eine Komponente gemacht, abgeleitet von TPanel.
Hier der (abgespeckte) Code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167:
| type TScrollingStatusBar = class(TPanel) private protected FScrollingInterval: Integer; FScrollingCaption: TCaption; pnlMiddleText: TPanel; pnlLeftButton: TPanel; pnlRightButton: TPanel; pnlHintInhalt: TPanel; pnlScrollLeftButton: TPanel; pnlScrollRightButton: TPanel; lblScrollLeftButton: TLabel; lblScrollRightButton: TLabel; procedure ResizeTextPanel; procedure SetCaptionText(aCaption: TCaption); function GetCaptionText: TCaption; public constructor Create(aOwner: TComponent); override; published property ScrollingInterval: integer read FScrollingInterval write FScrollingInterval; property Caption: TCaption read GetCaptionText write SetCaptionText; end;
constructor TScrollingStatusBar.Create(aOwner: TComponent); begin inherited; FScrollingInterval := 40;
Align := alBottom; BevelOuter := bvLowered; Height := 23; Caption := '';
pnlLeftButton := TPanel.Create(Self); with pnlLeftButton do begin Align := alLeft; Width := 16; BevelOuter := bvNone; Parent := Self; end;
pnlRightButton := TPanel.Create(Self); with pnlRightButton do begin Align := alRight; Width := 16; BevelOuter := bvNone; Parent := Self; end;
pnlMiddleText := TPanel.Create(Self); with pnlMiddleText do begin Align := alClient; BevelOuter := bvNone; Parent := Self; end;
pnlHintInhalt := TPanel.Create(Self); with pnlHintInhalt do begin Left := 100; Top := 2; Width := 150; Height := 17; Alignment := taLeftJustify; Parent := pnlMiddleText; end;
pnlScrollLeftButton := TPanel.Create(Self); with pnlScrollLeftButton do begin Align := alLeft; Width := 12; Enabled := False; Parent := pnlLeftButton; end;
pnlScrollRightButton := TPanel.Create(Self); with pnlScrollRightButton do begin Align := alRight; Width := 12; Enabled := False; Parent := pnlRightButton; end;
lblScrollLeftButton := TLabel.Create(Self); with lblScrollLeftButton do begin Align := alClient; Layout := tlCenter; Alignment := taCenter; Caption := '<'; Font.Style := [fsBold]; Font.Color := clBlack; Parent := pnlScrollLeftButton; end;
lblScrollRightButton := TLabel.Create(Self); with lblScrollRightButton do begin
Align := alClient; Layout := tlCenter; Alignment := taCenter; Caption := '>'; Font.Style := [fsBold]; Font.Color := clBlack; Parent := pnlScrollRightButton; end;
end; |
Anmerkung zwischen drin:
Ich habe bei den Panels alle BevelOuter auf bvRised gelassen, damit ich bei der Entwicklung die anordnung der Panels sehe.
Aussehen tut die Komponente sehr gut.
Um die Caption im ObjektInspektor zu setzen, mache ich:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| procedure TScrollingStatusBar.SetCaptionText(aCaption: TCaption); begin
FScrollingCaption := aCaption; pnlHintInhalt.Caption := FScrollingCaption; end; |
Wenn ich das so programmiere, kann ich im ObjektInspektor die Caption ändern und die wird auch auf das Panel gesetzt.
Passt.
Wenn ich danach das Panel breiter mache oder die Position (Left) verändere, crasht das Programm, wenn ich die Komponente auf mein Formular platziere.....
Zugriffsverletzung.
Was los?
Die Variablen der Panels sind nach außen nicht sichtbar, aber intern kann ich sie doch ansprechen.
Die Caption kann ich ja setzen, warum die Breite nicht?
Danke !
OLLI