Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   von ComboBox abgeleitete Komponente (https://www.delphipraxis.net/211496-von-combobox-abgeleitete-komponente.html)

iphi 23. Sep 2022 15:11

Delphi-Version: 7

von ComboBox abgeleitete Komponente
 
Hallo,

ich stehe gerade auf dem Schlauch.
Ich möchte von TComboBox eine Komponente ableiten, im Wesentlichen so:
Delphi-Quellcode:
type
  TComComboBox = class(TComboBox)
  private
    Popup: TPopupMenu;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Items;
  end;
Der wesentliche Unterschied zur Originalkomponente:
Die ComComboBox soll bereits mit Systeminfos aufgefüllt sein (und ein Popup-Menü besitzen).

Mein Problem:
Wie und wo fülle ich meine Strings in die Items ein? Im Constructor? Wie?

Danke!

KodeZwerg 23. Sep 2022 15:49

AW: von ComboBox abgeleitete Komponente
 
Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;

type
  TXComboBox = class(TComboBox)
    strict private
      FPopupMenu: TPopupMenu;
    public
      constructor Create(AOwner: TComponent); override;
    public
      property PopupMenu: TPopupMenu read FPopupMenu write FPopupMenu;
  end;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    FComboBox: TXComboBox;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

constructor TXComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Parent := TWinControl(AOwner);
  FPopupMenu := nil;
  Items.Add('Foo');
  Items.Add('Bar');
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  FComboBox := TXComboBox.Create(Self);
  FComboBox.Left := 10;
  FComboBox.Top := 10;
end;

end.
Eventuell so?

iphi 23. Sep 2022 16:13

AW: von ComboBox abgeleitete Komponente
 
Super, danke für die schnelle Hilfe! :-)

Delphi-Quellcode:
Parent := TWinControl(AOwner);
Der wars, den hatte ich vergessen. :(

himitsu 23. Sep 2022 17:28

AW: von ComboBox abgeleitete Komponente
 
An dieser Stelle besser (AOwner as TWinControl), falls es doch mal kein WinControl ist.

KodeZwerg 23. Sep 2022 17:58

AW: von ComboBox abgeleitete Komponente
 
Zitat:

Zitat von iphi (Beitrag 1512354)
Super, danke für die schnelle Hilfe! :-)

Gerne!
Zitat:

Zitat von himitsu (Beitrag 1512359)
An dieser Stelle besser (AOwner as TWinControl), falls es doch mal kein WinControl ist.

Gut aufgepasst!


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz