Recent

Author Topic: [SOLVED] TPopUpMenu and changing icons  (Read 1089 times)

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[SOLVED] TPopUpMenu and changing icons
« on: January 15, 2023, 07:55:20 pm »
I have a TPopupMenu and is filled with 6 items.
2 of these items are color dependent.
I use the following code to change the icons.
Code: Pascal  [Select][+][-]
  1.   TForm_Wedstrijd_Overzicht = class(TForm)
  2.     .....
  3.     .....
  4.     PUM_Wedstrijden: TPopupMenu;    
  5.     PUM_Wedstrijd_Declaratie: TMenuItem;
  6.     PUM_Wedstrijd_Nieuw: TMenuItem;
  7.     PUM_Wedstrijd_Bewerken: TMenuItem;
  8.     PUM_Wedstrijd_Verwijderen: TMenuItem;
  9.     PUM_Wedstrijd_Mail: TMenuItem;
  10.     PUM_Wedstrijd_Close: TMenuItem;
  11.   private
  12.     { private declarations }
  13.   public
  14.     { public declarations }
  15.   end;
  16.  
  17. .....
  18. .....
  19.  
  20.   case KleurPop of
  21.     Oranje : begin  // Oranje
  22.                PUM_Wedstrijd_Mail.ImageIndex := 21;
  23.                PUM_Wedstrijd_Declaratie.ImageIndex := 31;
  24.              end;  // Oranje
  25.     Rood   : begin  // Rood-Rose
  26.                PUM_Wedstrijd_Mail.ImageIndex := 22;
  27.                PUM_Wedstrijd_Declaratie.ImageIndex := 32;
  28.              end;  // Rood-Rose
  29.     Blauw  : begin  // Blauw
  30.                PUM_Wedstrijd_Mail.ImageIndex := 23;
  31.                PUM_Wedstrijd_Declaratie.ImageIndex := 33;
  32.              end;  // Blauw
  33.     Groen  : begin  // Groen
  34.                PUM_Wedstrijd_Mail.ImageIndex := 24;
  35.                PUM_Wedstrijd_Declaratie.ImageIndex := 34;
  36.              end;  // Groen
  37.     Paars  : begin  // Paars
  38.                PUM_Wedstrijd_Mail.ImageIndex := 25;
  39.                PUM_Wedstrijd_Declaratie.ImageIndex := 35;
  40.               end;  // Paars
  41.     Geel   : begin  // Geel
  42.                PUM_Wedstrijd_Mail.ImageIndex := 26;
  43.                PUM_Wedstrijd_Declaratie.ImageIndex := 36;
  44.              end;  // Geel
  45.     else
  46.       begin
  47.         PUM_Wedstrijd_Mail.ImageIndex := 20; // Black
  48.         PUM_Wedstrijd_Declaratie.ImageIndex := 30;
  49.       end; // else
  50.   end;  // case
  51.  


The first time this code is running it works like a charm. The color is changed.
But when I change the color from 'Rood' to 'Blauw' the code fails to work.


So do i have to refresh the PopupMenu?
If so how?
« Last Edit: January 25, 2023, 12:40:16 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

howardpc

  • Hero Member
  • *****
  • Posts: 4104
Re: TPopUpMenu and changing icons
« Reply #1 on: January 15, 2023, 08:37:28 pm »
Assigning different imageindex values to popupmenu items on Windows changes the menuitem display consistently correctly.
So perhaps this is a Mac bug if your code logic is correct (you do not show compilable code).

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #2 on: January 16, 2023, 08:51:56 am »
I know th code is correct.
Because I use the same code on a different popupmenu which is in the main form.
So that is why it is so curious...


Will try and make a runnable program to compile
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #3 on: January 16, 2023, 12:39:23 pm »
Made a working version of my app.


You can download it at [LINK DELETED]


It is 60Mb due to some pictures I had to let in for demonstration of changing the colors.

In the Files-Menu you can change the colors under [Options].
In the Games-Menu you can open the [Overview of Games] and there is the popupmenu under your right-mouse button.

Play with the colors multiple times and this popupmenu will not change (at least in MacOS).

Hope you can help me with my problem
« Last Edit: January 25, 2023, 12:40:22 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #4 on: January 23, 2023, 06:32:10 pm »
just to bump up and see if someone knows an answer
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

wp

  • Hero Member
  • *****
  • Posts: 10489
Re: TPopUpMenu and changing icons
« Reply #5 on: January 23, 2023, 07:19:06 pm »
Sorry, please simplify the project in reply #3. I am not willing to install "tons" of third-party components. Remove everything which is not needed to show the issue.

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #6 on: January 23, 2023, 09:08:50 pm »
As requested. I have simplified the app.


The link stayed the same [LINK DELETED]
But now it is just over 10Mb  :)
« Last Edit: January 25, 2023, 12:40:42 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

wp

  • Hero Member
  • *****
  • Posts: 10489
Re: TPopUpMenu and changing icons
« Reply #7 on: January 23, 2023, 09:56:35 pm »
I still cannot load the project, it requires BGRAControls. Sorry to be insistent...

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #8 on: January 23, 2023, 11:40:04 pm »
yes it is needed everywhere
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

jamie

  • Hero Member
  • *****
  • Posts: 5072
Re: TPopUpMenu and changing icons
« Reply #9 on: January 23, 2023, 11:52:05 pm »
The only true wisdom is knowing you know nothing

howardpc

  • Hero Member
  • *****
  • Posts: 4104
Re: TPopUpMenu and changing icons
« Reply #10 on: January 24, 2023, 10:26:18 am »
Even with BGRA installed, and the synapse library referenced correctly I cannot compile your project because of a missing file Referee5_DB.xml.

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #11 on: January 24, 2023, 11:00:20 am »
That is in the bundle. And it looks like this:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<REFEREE_5>
  <DATABASE>
    <Version Value="5"/>
    <Release Value="0"/>
    <Updates Value="0"/>
    <Current Value="Ref5_Int.r5db"/>
  </DATABASE>
  <SETUP>
    <Color Value="4"/>
    <Style Value="1"/>
    <Base_MS Value=""/>
    <Base_MP Value=""/>
    <Base_UN Value=""/>
    <Base_UP Value=""/>
    <Base_NM Value=""/>
    <Base_NE Value=""/>
    <Base_TI Value=""/>
    <Base_RP Value=""/>
  </SETUP>
  <RefereeDatabase>
    <Current Value="Referees.r5db"/>
    <Version Value="5"/>
    <Update Value="0."/>
  </RefereeDatabase>
</REFEREE_5>
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TPopUpMenu and changing icons
« Reply #12 on: January 25, 2023, 12:40:04 am »
While trying to clean up my code even more for the example on here.
I came across this piece of code:
Code: Pascal  [Select][+][-]
  1. PUM_Overzicht_Wedstrijd.UpdateImage(True)
This piece of code is what I needed to update the image of that popupmenu-item.


Problem solved !!
 :D :D :D
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

howardpc

  • Hero Member
  • *****
  • Posts: 4104
Re: [SOLVED] TPopUpMenu and changing icons
« Reply #13 on: January 25, 2023, 08:56:23 am »
So wp's insistence that you provide the simplest possible compilable example of the problem paid off.

Glad you were able to debug your own code in that way.

Sometimes we are unable to distance ourselves from code we wrote sufficiently to see it with fresh eyes, the eyes of the stranger who would immediately see a flaw or ambiguity or logical nonsense, or missing piece.

madref

  • Hero Member
  • *****
  • Posts: 895
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: [SOLVED] TPopUpMenu and changing icons
« Reply #14 on: January 25, 2023, 12:39:53 pm »
Yes it paid off...


Going to remove the link....


Thanks for the help
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.3.0 (rev main-2_3-2740-g4c53c90895) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

 

TinyPortal © 2005-2018