Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi TTaskDialog.Buttons.Add (https://www.delphipraxis.net/211287-ttaskdialog-buttons-add.html)

TurboMagic 25. Aug 2022 22:36

TTaskDialog.Buttons.Add
 
Hallo,

weiß jemand warum TTaskDialog.Buttons.Add ein TTaskDialogBaseButtonItem Objekt und nicht ein
TTaskDialogButtonItem Objekt zurückliefert?

Wie füge ich per Code einen Button hinzu, dem ich auch einen CommandLinkHint setzen kann?

Grüße
TurboMagic

Uwe Raabe 25. Aug 2022 22:59

AW: TTaskDialog.Buttons.Add
 
Das musst du casten. In TCustomTaskDialog.Create wird beim Erzeugen von FButtons die gewünschte Klasse angegeben, so dass der Cast auch funktioniert.

Das ist allgemein das Verhalten von Collections im Gegensatz zu generischen Listen.

Delphi-Quellcode:
constructor TCustomTaskDialog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FButtons := TTaskDialogButtons.Create(Self, TTaskDialogButtonItem);
  FCommonButtons := [tcbOk, tcbCancel];

KodeZwerg 25. Aug 2022 23:20

AW: TTaskDialog.Buttons.Add
 
Delphi-Quellcode:
with TTaskDialog.Create(self) do
  try
    Title := 'Confirm Removal';
    Caption := 'Rejbrand BookBase';
    Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
    CommonButtons := []; // <<<--- das ist entscheidend!
    with TTaskDialogButtonItem(Buttons.Add) do
    begin
      Caption := 'Remove';
      CommandLinkHint := 'Remove the book from the catalogue.';
      ModalResult := mrYes;
    end;
    with TTaskDialogButtonItem(Buttons.Add) do
    begin
      Caption := 'Keep';
      CommandLinkHint := 'Keep the book in the catalogue.';
      ModalResult := mrNo;
    end;
    Flags := [tfUseCommandLinks];
    MainIcon := tdiNone;
    if Execute then
      if ModalResult = mrYes then
        DoDelete;
  finally
    Free;
  end
how-to-use-the-ttaskdialog

TurboMagic 25. Aug 2022 23:27

AW: TTaskDialog.Buttons.Add
 
Ok, das mit dem Casten hab' ich inzwischen auch rausgefunden und das funktioniert.
Ist halt nicht gleich offensichtlich...


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:04 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