Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Action and checked button on toolbar (https://www.delphipraxis.net/166330-action-checked-button-toolbar.html)

WojTec 8. Feb 2012 11:54

Delphi-Version: 2010

Action and checked button on toolbar
 
Previous I used toolbar buuttons without actions; group and autocheck was set in buttons; now I added actions (to add shortcuts) and moved code from OnClick to OnExecute and set autocheck and group properties, but can't 'unpress' (checked = false) button by mouse click (in Delphi can change Checked property). F1, please :(

Steku 8. Feb 2012 12:22

AW: Action and checked button on toolbar
 
untested:

in your onexecute use something like:

youraction.checked := not youraction.checked;

hope i've got you right...

Steku

WojTec 8. Feb 2012 13:25

Re: Action and checked button on toolbar
 
Nope, I tested it too - with this can't check.
So, whithout actions can check, but whith can't, why?

:(:?:

uligerhardt 8. Feb 2012 14:11

AW: Action and checked button on toolbar
 
I tested it with this DFM:
Delphi-Quellcode:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 337
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 635
    Height = 29
    ButtonHeight = 21
    ButtonWidth = 43
    Caption = 'ToolBar1'
    ShowCaptions = True
    TabOrder = 0
    object ToolButton1: TToolButton
      Left = 0
      Top = 0
      Action = Action1
    end
    object ToolButton2: TToolButton
      Left = 43
      Top = 0
      Action = Action2
    end
    object ToolButton3: TToolButton
      Left = 86
      Top = 0
      Action = Action3
    end
  end
  object ActionList1: TActionList
    Left = 312
    Top = 176
    object Action1: TAction
      Caption = 'Action1'
      Checked = True
      GroupIndex = 1
      OnExecute = Action1Execute
    end
    object Action2: TAction
      Caption = 'Action2'
      GroupIndex = 1
      OnExecute = Action1Execute
    end
    object Action3: TAction
      Caption = 'Action3'
      GroupIndex = 1
      OnExecute = Action1Execute
    end
  end
end
and this OnExecute handler:
Delphi-Quellcode:
procedure TForm1.Action1Execute(Sender: TObject);
var
  actn: TAction absolute Sender;
begin
  Assert(Sender is TAction);
  actn.Checked := not actn.Checked;
end;
and I can press and unpress just fine.

WojTec 8. Feb 2012 14:30

Re: Action and checked button on toolbar
 
Hm, I don't know why for you is ok when for me is not ok.
Acha, I used spTBXLib, maybe this is reason?

uligerhardt 8. Feb 2012 14:49

AW: Re: Action and checked button on toolbar
 
Zitat:

Zitat von WojTec (Beitrag 1149882)
Hm, I don't know why for you is ok when for me is not ok.
Acha, I used spTBXLib, maybe this is reason?

I added this:
Delphi-Quellcode:
  object SpTBXDock1: TSpTBXDock
    Left = 0
    Top = 29
    Width = 635
    Height = 25
    object SpTBXToolbar1: TSpTBXToolbar
      Left = 0
      Top = 0
      TabOrder = 0
      Caption = 'SpTBXToolbar1'
      object TBItem3: TTBItem
        Action = Action1
      end
      object TBItem2: TTBItem
        Action = Action2
      end
      object TBItem1: TTBItem
        Action = Action3
      end
    end
  end
Still works.


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