![]() |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Ja klar, aber auch dort auch jemand was reingeladen?
|
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Zitat:
Zitat:
|
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Hallo nochmal.
Ich habe die Komponente erweitert. Jetzt klappt es mit der Zuweisung "von außen" :-) Eine weitere Frage habe ich aber: Kann man die Property Picture der Subkomponente entfernen, dass diese nicht mehr sichtbar ist?
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, System.Types, Vcl.Controls, Vcl.ExtCtrls, Vcl.Forms, 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.16.0913'; type TSubPosition = (lpNone, lpTop, lpBottom, lpLeft, lpRight, lpClient, lpCustom); TTRM_ImageLabel = class(TCustomPanel) private FSubImage: TImage; FImagePosition: TSubPosition; FImagePicture: TPicture; FSubLabel: TLabel; FLabelCaption: String; FLabelPosition: TSubPosition; FVersion: String; procedure SetImagePosition(const Value: TSubPosition); procedure PictureChanged(Sender: TObject); procedure SetPicture(Value: TPicture); 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 ImagePicture: TPicture read FImagePicture write SetPicture; 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); FSubImage.SetSubComponent(True); FSubImage.Parent := Self; FSubImage.Align := alClient; FSubImage.Center := True; FSubImage.OnClick := ImageClick; FSubImage.OnDblClick := ImageDblClick; FSubImage.OnMouseEnter := ImageMouseEnter; FSubImage.OnMouseLeave := ImageMouseLeave; FSubLabel := TLabel.Create(Self); 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; FImagePicture := TPicture.Create; FImagePicture.OnChange := PictureChanged; 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.SetPicture(Value: TPicture); begin FImagePicture.Assign(Value); FSubImage.Picture.Assign(FImagePicture); end; procedure TTRM_ImageLabel.PictureChanged(Sender: TObject); begin Repaint; 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; FImagePicture.Free; inherited Destroy; end; end. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Warum hast Du die Subkomponenten eigentlich sichtbar? Was willst Du in denen einstellen was dir nicht woanders Ärger macht?
Bei guten komponenten gäbe es unterhalb von TImage ein TCommonImage. TImage würde keine andere Function haben außer alle Properties auf published zu setzen. Eine Ableitung von TCommonImage würde dir dann erlauben wegzulassen was du nicht brauchst. Aber hier geht das genauso TImage -> TMyImage. Alle Properties die Du nicht brauchst deklarierst Du unter public und nicht published. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Zitat:
weil ich nicht weiß, wie es anders gemacht wird und angenommen hatte, dass properties immer in published gehören. Ich mache die Programmiererei als Hobby, bin kein gelernter Programmierer. Ich versuche nachher nochmals die Subkomponenten nicht ins published zu stecken. :-) Danke für die Hilfe. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Huhu.
Scheinbar habe ich einige Prizipien nicht gelernt/verstanden. Nachdem ich die beiden Subkomponenten verschoben abe, ist es mir nicht mehr möglich, Standard-Eigenschaften von den Komponenten anzusprechen.
Delphi-Quellcode:
Jetzt müsste ich der Hauptkomponente also alle Eigenschaften, die ich später im Code setzten möchte, noch hinzufügen.
public
property SubImage: TImage read FSubImage; property SubLabel: TLabel read FSubLabel; Wo liegt jetzt der Vorteil in dieser Vorgensweise? LG nach Dubai :-) |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Zitat:
Ich habe Komponenten die fassen 5 oder 6 andere in einer zusammen. Die möchte ich nicht alle im Property Editor haben. Ich lege für die dann aber garkein Property an. Ich habe ja die lokale Variable im Object. Aber, für alles was Du nur im Code setzen willst brauchst Du ja nicht wirklich Properties. Nur was über den Editor zur Designzeit einstellbar sein soll muss zwingend ein Property bekommen. Durch Getter und Setter hat man bestimmte Vorteile. Ich liebe Properties dafür. Aber die sind bei mir trotzdem nur public oder protected deklariert. Nicht published. Denn ich brauche sie nicht sichtbar zur Designzeit. Zitat:
|
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Guten Morgen.
Hier ist ein Test, damit ich das Prinzip verstehen kann. Was mir jetzt fehlt, sind folgende Properties: Falls möglich, hätte ich die gerne gebündelt dargestellt, will heißen, im ObjectExplorer sollte z.B.:
Code:
erreichbar sein.
aImage + (aufklappbar)
- Caption - Visible aImage + (aufklappbar) - Picture - Visible [..] (weitere property)
Code:
TMyLabel ->
property Caption; property Visible; // als Test TMyImage -> property Picture; property Visible; // auch ein Test
Delphi-Quellcode:
unit ImageLabelTEST;
interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Graphics, Vcl.Forms; type TMyImage = class(TImage) private public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Picture; property Visible; end; TMyLabel = class(TLabel) private public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Caption; property Visible; end; TImageLabelTEST = class(TCustomControl) private FImage: TMyImage; FLabel: TMyLabel; function GetImage: TPicture; procedure SetImage(const Value: TPicture); function GetLabelCaption: TCaption; procedure SetLabelCaption(const Value: TCaption); function GetLabelFont: TFont; procedure SetLabelFont(const Value: TFont); protected procedure Resize; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property aImage: TMyImage read FImage; property aLabel: TMyLabel read FLabel; published // folgende properties würde ich gerne mit den properties aus den eigenen Subkomponenten ersetzen property I_Picture: TPicture read GetImage write SetImage; property L_Caption: TCaption read GetLabelCaption write SetLabelCaption; property L_Font: TFont read GetLabelFont write SetLabelFont; property Align; property Anchors; property Visible; end; procedure Register; implementation procedure Register; begin RegisterComponents('TRM', [TImageLabelTEST]); end; { TMyImage } constructor TMyImage.Create(AOwner: TComponent); begin inherited Create(AOwner); end; destructor TMyImage.Destroy; begin Self.Free; inherited Destroy; end; { TMyLabel } constructor TMyLabel.Create(AOwner: TComponent); begin inherited Create(AOwner); end; destructor TMyLabel.Destroy; begin Self.Free; inherited Destroy; end; { TImageLabel } constructor TImageLabelTEST.Create(AOwner: TComponent); begin inherited Create(AOwner); FImage := TMyImage.Create(Self); FImage.Parent := Self; FImage.Align := alTop; FImage.Height := 100; FLabel := TMyLabel.Create(Self); FLabel.Parent := Self; FLabel.Align := alClient; FLabel.Alignment := taCenter; end; procedure TImageLabelTEST.Resize; begin inherited; end; function TImageLabelTEST.GetImage: TPicture; begin Result := FImage.Picture; end; procedure TImageLabelTEST.SetImage(const Value: TPicture); begin FImage.Picture.Assign(Value); end; function TImageLabelTEST.GetLabelCaption: TCaption; begin Result := FLabel.Caption; end; procedure TImageLabelTEST.SetLabelCaption(const Value: TCaption); begin FLabel.Caption := Value; end; function TImageLabelTEST.GetLabelFont: TFont; begin Result := FLabel.Font; end; procedure TImageLabelTEST.SetLabelFont(const Value: TFont); begin FLabel.Font.Assign(Value); end; destructor TImageLabelTEST.Destroy; begin FImage.Free; FLabel.Free; inherited Destroy; end; end. |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Zitat:
Alles was Du nicht unter published haben willst must Du in deiner Ableitung als public deklarieren. Weglassen bedeutet das es in der gleichen Sichtbarkeit bleibt wie es ist. Dann könntest du das so machen:
Delphi-Quellcode:
public
constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property ImageProps: TMyImage read FImage; property LabelProps: TMyLabel read FLabel; property Align; property Anchors; property Visible; end; |
AW: Komponente (TImage & TLabel) -> Image wird nicht angezeigt
Ich verzweifle bald ;-)
Testweise habe ich in den SubComponenten Anchors beim TImage und Caption beim TLabel in public verschoben. Dennoch sind die weiterhin im Objectexplorer sichtbar und auch änderbar. Wo ist denn mein Fehler im Code, damit die beiden Properties nicht mehr angezeigt werden?
Delphi-Quellcode:
LG Mathias
unit ImageLabelTEST;
interface uses System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Graphics, Vcl.Forms; type { TMyImage } TMyImage = class(TImage) private protected public property Anchors; published end; { TMyLabel } TMyLabel = class(TLabel) private protected public property Caption; published end; { TIMageLabelTest } TImageLabelTEST = class(TCustomControl) private MyImage: TMyImage; MyLabel: TMyLabel; protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Resize; override; published property MySubImage: TMyImage read MyImage; property MySubLabel: TMyLabel read MyLabel; end; procedure Register; implementation procedure Register; begin RegisterComponents('TRM', [TImageLabelTEST]); end; { TMyImage } { TMyLabel } { TImageLabel } constructor TImageLabelTEST.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.Parent := TWinControl(AOwner); MyImage := TMyImage.Create(Self); MyImage.SetSubComponent(True); MyImage.Parent := Self; MyLabel := TMyLabel.Create(Self); MyLabel.SetSubComponent(True); MyLabel.Parent := Self; end; procedure TImageLabelTEST.Resize; begin inherited; end; destructor TImageLabelTEST.Destroy; begin MyImage.Free; MyLabel.Free; inherited Destroy; end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:57 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