![]() |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Für mich macht es Sinn. Bei den Standardkomponenten hat sich ja bisher sicher auch keiner daran gestört, dass die Eigenschaften auf 3 gesetzt sind ;-)
|
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Zitat:
Aber UnterKomponenten standardmäßig nicht. * SetSubcomponent * oder, wenn es nur ums Speichern geht, diese Funktion in die Hauptkomponente und dann intern die Daten zur Subkomponente durchreichen. Ach ja, wenn man die initialen Werte von "Standardeigenschaften" ändert, dann sollte man auch niemals vergessen das DEFAULT am Property zu aktualisieren. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Danke für die Ergänzung. 😃
LG Mathias |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Ich habe eine Rückfrage zu SetSubComponent.
Die Komponente funktioniert sehr gut, jedoch besteht jetzt das Problem, dass das Label (SubComponente) einige Eigenschaften nicht speichert. Z.B. Align. Ich setze die Eigenscahft der Subcomponente auf alClient, speichere das Project, schließe und lade es erneut. Dann ist die Eigenschaft wieder auf alRight. Hier der Code der aktuellen Version
Delphi-Quellcode:
unit TRM_ImageLabel;
(* TRM_ImageLabel erstellt von Mathias Fiege 2024 www.nogad.de Open Source License Permission is hereby granted, free of charge, to any person obtaining a copy of this software component and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Thanks and greetings to www.delphipraxis.net *) interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Imaging.GIFConsts, Vcl.Imaging.GIFImg, Vcl.Imaging.JConsts, Vcl.Imaging.jpeg, Vcl.Imaging.pngimage, Vcl.Imaging.pnglang; type TLabelPosition = (lpTop, lpBottom, lpLeft, lpRight); TTRM_ImageLabel = class(TCustomPanel) private FSubImageComponent: TImage; FSubLabelComponent: TLabel; FLabelPosition: TLabelPosition; FVersion: String; procedure SetLabelPosition(const Value: TLabelPosition); procedure ImageClick(Sender: TObject); procedure ImageDblClick(Sender: TObject); procedure ImageMouseEnter(Sender: TObject); procedure ImageMouseLeave(Sender: TObject); procedure LabelClick(Sender: TObject); procedure LabelDblClick(Sender: TObject); procedure LabelMouseEnter(Sender: TObject); procedure LabelMouseLeave(Sender: TObject); protected procedure Resize; override; public constructor Create(AOwner: TComponent); override; published property SubImageComponent: TImage read FSubImageComponent; property SubLabelComponent: TLabel read FSubLabelComponent; property Align; property Anchors; property BevelInner; property BevelKind; property BevelOuter; property BevelWidth; property BorderStyle; property BorderWidth; property Caption; property Ctl3D; property Cursor; property ParentBackground; property PopupMenu; property OnClick; property OnDblClick; property OnMouseEnter; property OnMouseLeave; property LabelPosition: TLabelPosition read FLabelPosition write SetLabelPosition; property Version: String read FVersion; end; procedure Register; implementation procedure Register; begin RegisterComponents('TRM', [TTRM_ImageLabel]); end; { TTRM_ImageLabel } constructor TTRM_ImageLabel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Width := 64; Self.Height := 89; Self.AlignWithMargins := True; Self.Margins.Top := 0; Self.Margins.Left := 8; Self.Margins.Right := 8; Self.Margins.Bottom := 0; Self.BevelInner := bvNone; Self.BevelKind := bkNone; Self.BevelOuter := bvNone; Self.BevelWidth := 1; Self.BorderStyle := bsNone; Self.BorderWidth := 0; Self.Caption := ''; Self.Ctl3D := False; Self.Cursor := crHandPoint; Self.ParentBackground := True; FSubImageComponent := TImage.Create(Self); SubImageComponent.SetSubComponent(True); FSubImageComponent.Parent := Self; FSubImageComponent.Align := alClient; FSubImageComponent.OnClick := ImageClick; FSubImageComponent.OnDblClick := ImageDblClick; FSubImageComponent.OnMouseEnter := ImageMouseEnter; FSubImageComponent.OnMouseLeave := ImageMouseLeave; FSubLabelComponent := TLabel.Create(Self); SubLabelComponent.SetSubComponent(True); FSubLabelComponent.Parent := Self; FSubLabelComponent.Height := 25; FSubLabelComponent.AlignWithMargins := False; FSubLabelComponent.Margins.Left := 0; FSubLabelComponent.Margins.Right := 0; FSubLabelComponent.Margins.Top := 8; FSubLabelComponent.Margins.Bottom := 0; FSubLabelComponent.Caption := '...'; SubLabelComponent.Font.Size := 14; SubLabelComponent.OnClick := LabelClick; SubLabelComponent.OnDblClick := LabelDblClick; SubLabelComponent.OnMouseEnter := LabelMouseEnter; SubLabelComponent.OnMouseLeave := LabelMouseLeave; FLabelPosition := lpBottom; FVersion := '2024.05.14.1038'; Resize; end; procedure TTRM_ImageLabel.Resize; begin inherited; case FLabelPosition of lpTop: begin FSubLabelComponent.Align := alTop; // FSubLabelComponent.Alignment := taCenter; end; lpBottom: begin FSubLabelComponent.Align := alBottom; // FSubLabelComponent.Alignment := taCenter; end; lpLeft: begin FSubLabelComponent.Align := alLeft; // FSubLabelComponent.Alignment := taCenter; end; lpRight: begin FSubLabelComponent.Align := alRight; // FSubLabelComponent.Alignment := taCenter; end; end; Update; end; procedure TTRM_ImageLabel.SetLabelPosition(const Value: TLabelPosition); begin if FLabelPosition <> Value then begin FLabelPosition := Value; Resize; end; end; procedure TTRM_ImageLabel.ImageClick(Sender: TObject); begin if Assigned(OnClick) then OnClick(Self); end; procedure TTRM_ImageLabel.ImageDblClick(Sender: TObject); begin if Assigned(OnDblClick) then OnDblClick(Self); end; procedure TTRM_ImageLabel.ImageMouseEnter(Sender: TObject); begin if Assigned(OnMouseEnter) then OnMouseEnter(Self); end; procedure TTRM_ImageLabel.ImageMouseLeave(Sender: TObject); begin if Assigned(OnMouseLeave) then OnMouseLeave(Self); end; procedure TTRM_ImageLabel.LabelClick(Sender: TObject); begin if Assigned(OnClick) then OnClick(Self); end; procedure TTRM_ImageLabel.LabelDblClick(Sender: TObject); begin if Assigned(OnDblClick) then OnDblClick(Self); end; procedure TTRM_ImageLabel.LabelMouseEnter(Sender: TObject); begin if Assigned(OnMouseEnter) then OnMouseEnter(Self); end; procedure TTRM_ImageLabel.LabelMouseLeave(Sender: TObject); begin if Assigned(OnMouseLeave) then OnMouseLeave(Self); end; end. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Ich habs mal versucht nachzustellen wobei ich gleich auf TPanel umgestiegen bin.
Zur laufzeit benötige ich nicht mehr als:
Delphi-Quellcode:
unit EinUnitName;
interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls; type TLabeledImage = class(TCustomPanel) strict private FImage: TImage; FLabel: TLabel; public constructor Create(AOwner: TComponent); destructor Destroy; override; published property Img: TImage read FImage write FImage; property Lbl: TLabel read FLabel write FLabel; end; implementation { TLabeledImage } constructor TLabeledImage.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Parent := TWinControl(AOwner); FLabel := TLabel.Create(Self); try FLabel.Parent := Self; FLabel.Align := alBottom; FLabel.Alignment := taCenter; FLabel.Caption := ''; FLabel.Visible := True; finally end; FImage := TImage.Create(Self); try FImage.Parent := Self; FImage.Align := alClient; FImage.Visible := True; finally end; Self.Width := 150; Self.Height := 150; end; destructor TLabeledImage.Destroy; begin FImage.Free; FLabel.Free; inherited Destroy; end; end. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Huhu. Danke für Deine Hilfe.
Ich habe den Fehler gefunden:
Delphi-Quellcode:
FSubImageComponent := TImage.Create(Self);
SubImageComponent.SetSubComponent(True); // <--- hier fehlt ein F; ebenso beim Label. FSubImageComponent.Parent := Self; Tut mir leid, hatte ich übersehen. LG Mathias :-) |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Hier ist die aktuelle Variante der Komponente. Jetzt klappt es auch mit den Zuweisungen. Der Fehler war, dass ich TSubPosition nur als (lpTop, lpBottom, lpLeft, lpRight) deklariert hatte. Wenn ich dann die Subkomponente (Label) aber z.B. als Client eingestellt hatte, gab es diesen ominösen Fehler beim Laden. Jetzt, nachdem ich TSubPosition als (lpNone, lpTop, lpBottom, lpLeft, lpRight, lpClient, lpCustom) deklariert habe, klappt es.
Was ich jetzt noch gern machen würde, wäre eine Abkürzung, um ein Bild (png,bmp,gif,...) über den ObjectInspector als Property bereitstellen zu können. Aber ich scheitere an der korrekten Zuweisung ;-)
Delphi-Quellcode:
unit TRM_ImageLabel;
(* TRM_ImageLabel erstellt von Mathias Fiege 2024 www.nogad.de Open Source License Permission is hereby granted, free of charge, to any person obtaining a copy of this software component and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Thanks and greetings to www.delphipraxis.net *) interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Imaging.GIFConsts, Vcl.Imaging.GIFImg, Vcl.Imaging.JConsts, Vcl.Imaging.jpeg, Vcl.Imaging.pngimage, Vcl.Imaging.pnglang, Vcl.Graphics; const _version = '2024.05.15.0901'; type TSubPosition = (lpNone, lpTop, lpBottom, lpLeft, lpRight, lpClient, lpCustom); TTRM_ImageLabel = class(TCustomPanel) private FSubImage: TImage; FImagePosition: TSubPosition; FSubLabel: TLabel; FLabelCaption: String; FLabelPosition: TSubPosition; FVersion: String; procedure SetImagePosition(const Value: TSubPosition); procedure SetLabelCaption(const Value: String); procedure SetLabelPosition(const Value: TSubPosition); procedure ImageClick(Sender: TObject); procedure ImageDblClick(Sender: TObject); procedure ImageMouseEnter(Sender: TObject); procedure ImageMouseLeave(Sender: TObject); procedure LabelClick(Sender: TObject); procedure LabelDblClick(Sender: TObject); procedure LabelMouseEnter(Sender: TObject); procedure LabelMouseLeave(Sender: TObject); protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Resize; override; published property SubImage: TImage read FSubImage; property SubLabel: TLabel read FSubLabel; property Align; property Anchors; property BevelInner; property BevelKind; property BevelOuter; property BevelWidth; property BorderStyle; property BorderWidth; property Caption; property Ctl3D; property Cursor; property ParentBackground; property PopupMenu; property OnClick; property OnDblClick; property OnMouseEnter; property OnMouseLeave; property ImagePosition: TSubPosition read FImagePosition write SetImagePosition; property LabelCaption: String read FLabelCaption write SetLabelCaption; property LabelPosition: TSubPosition read FLabelPosition write SetLabelPosition; property Version: String read FVersion; end; procedure Register; implementation procedure Register; begin RegisterComponents('TRM', [TTRM_ImageLabel]); end; { TTRM_ImageLabel } constructor TTRM_ImageLabel.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Parent := TWinControl(AOwner); FSubImage := TImage.Create(Self); try FSubImage.SetSubComponent(True); FSubImage.Parent := Self; FSubImage.Align := alClient; FSubImage.OnClick := ImageClick; FSubImage.OnDblClick := ImageDblClick; FSubImage.OnMouseEnter := ImageMouseEnter; FSubImage.OnMouseLeave := ImageMouseLeave; finally end; FSubLabel := TLabel.Create(Self); try FSubLabel.SetSubComponent(True); FSubLabel.Parent := Self; FSubLabel.Align := alBottom; FSubLabel.AutoSize := True; FSubLabel.Height := 25; FSubLabel.AlignWithMargins := False; FSubLabel.Margins.Left := 0; FSubLabel.Margins.Right := 0; FSubLabel.Margins.Top := 8; FSubLabel.Margins.Bottom := 0; FSubLabel.Caption := '...'; FSubLabel.Font.Size := 14; FSubLabel.OnClick := LabelClick; FSubLabel.OnDblClick := LabelDblClick; FSubLabel.OnMouseEnter := LabelMouseEnter; FSubLabel.OnMouseLeave := LabelMouseLeave; finally end; Self.Width := 64; Self.Height := 89; Self.AlignWithMargins := True; Self.Margins.Top := 0; Self.Margins.Left := 8; Self.Margins.Right := 8; Self.Margins.Bottom := 0; Self.BevelInner := bvNone; Self.BevelKind := bkNone; Self.BevelOuter := bvNone; Self.BevelWidth := 1; Self.BorderStyle := bsNone; Self.BorderWidth := 0; Self.Caption := ''; Self.Ctl3D := False; Self.Cursor := crHandPoint; Self.ParentBackground := True; FVersion := _version; FImagePosition := lpClient; FLabelPosition := lpBottom; Update; Resize; end; procedure TTRM_ImageLabel.Resize; begin (* lpNone, lpTop, lpBottom, lpLeft, lpRight, lpClient, lpCustom *) inherited; case FLabelPosition of lpNone: begin FSubLabel.Align := alNone; end; lpTop: begin FSubLabel.Align := alTop; end; lpBottom: begin FSubLabel.Align := alBottom; end; lpLeft: begin FSubLabel.Align := alLeft; end; lpRight: begin FSubLabel.Align := alRight; end; lpClient: begin FSubLabel.Align := alClient; end; lpCustom: begin FSubLabel.Align := alCustom; end; end; case FImagePosition of lpNone: begin FSubImage.Align := alNone; end; lpTop: begin FSubImage.Align := alTop; end; lpBottom: begin FSubImage.Align := alBottom; end; lpLeft: begin FSubImage.Align := alLeft; end; lpRight: begin FSubImage.Align := alRight; end; lpClient: begin FSubImage.Align := alClient; end; lpCustom: begin FSubImage.Align := alCustom; end; end; FSubLabel.Caption := FLabelCaption; Update; end; procedure TTRM_ImageLabel.SetImagePosition(const Value: TSubPosition); begin if FImagePosition <> Value then begin FImagePosition := Value; Resize; end; end; procedure TTRM_ImageLabel.SetLabelCaption(const Value: string); begin if FLabelCaption <> Value then begin FLabelCaption := Value; Resize; end; end; procedure TTRM_ImageLabel.SetLabelPosition(const Value: TSubPosition); begin if FLabelPosition <> Value then begin FLabelPosition := Value; Resize; end; end; procedure TTRM_ImageLabel.ImageClick(Sender: TObject); begin if Assigned(OnClick) then OnClick(Self); end; procedure TTRM_ImageLabel.ImageDblClick(Sender: TObject); begin if Assigned(OnDblClick) then OnDblClick(Self); end; procedure TTRM_ImageLabel.ImageMouseEnter(Sender: TObject); begin if Assigned(OnMouseEnter) then OnMouseEnter(Self); end; procedure TTRM_ImageLabel.ImageMouseLeave(Sender: TObject); begin if Assigned(OnMouseLeave) then OnMouseLeave(Self); end; procedure TTRM_ImageLabel.LabelClick(Sender: TObject); begin if Assigned(OnClick) then OnClick(Self); end; procedure TTRM_ImageLabel.LabelDblClick(Sender: TObject); begin if Assigned(OnDblClick) then OnDblClick(Self); end; procedure TTRM_ImageLabel.LabelMouseEnter(Sender: TObject); begin if Assigned(OnMouseEnter) then OnMouseEnter(Self); end; procedure TTRM_ImageLabel.LabelMouseLeave(Sender: TObject); begin if Assigned(OnMouseLeave) then OnMouseLeave(Self); end; destructor TTRM_ImageLabel.Destroy; begin FSubImage.Free; FSubLabel.Free; inherited Destroy; end; end. LG Mathias |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Hey,
Wie das genau geht lässt sich am besten herausfinden wenn Du dir die Quelltexte von TImage ansiehst. Das ist eigentlich ganz einfach, wenn man weis wie es geht. Grüße in die Stadt im Park. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Hat das Image überhaupt ein Bild, welches es anzeigen könnte?
Die Free im Destroy sind nicht nötig, da du Self als Owner nutzt und somit dein ImageLabel das automatisch freigibt. Wozu die leeren Try-Finally? Im Create würde ich nicht strändig zwischen FSub... und Sub... wechseln, alleine schon von der Lesbarkeit her. Ja, da es (aktuell) keinen Getter gibt, ist es am Ende technisch vollkommen irrelevant. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Zitat:
Delphi-Quellcode:
.
property Picture
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:22 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz