Search code examples
delphibutton

How to determine which image is loaded in a BitBtn?


I want a sorting button for a table in Delphi. I have a TBitBtn with a Glyph (an up arrow). When that button is pressed, I want something like this to happen:

if btbSort.Glyph := 'Up.bmp' do
   Sort from down to up
or else
   Sort from up to down

Does this make sense?

There doesn't seem to be a property for the "loaded glyph".


Solution

  • There is no way to ask the Button which Glyph is loaded, because it does not keep track of that information. So you have to keep track of it yourself, for instance by using the button's Tag propety, eg:

    btbSort.Glyph.LoadFromFile('Up.bmp');
    btbSort.Tag := 1;
    ...
    if btbSort.Tag = 1 then begin
       // Sort from down to up ...
    end
    else begin
       // Sort from up to down ...
    end;