Jump to content

Problem with uniComboBox when not used at designe time


Delphigui

Recommended Posts

Hi Everybody,

I tried to contact the support but I'm not sure of the mail so I'm here. I'm not sure too of the right section of the Forum?

I met some problems when I use the combobox with imagelist by code (but manually at design time that works)

I proceed like that :

  • I put on a form a unicombobox, unibutton, and uniImagelist
  • ont the button event I'm writing this:
    •   unicombobox.Images := UniImageList1;
        intCompteur := 0;
        for strLangue in stlListe do
        begin
          with (unicombobox.IconItems.Add) do
          begin
            Caption := strLangue;
            ImageIndex := intCompteur;
          end;
      
          Inc(intCompteur);
        end;

       

  • I compile and launch the project

But when the browser displays the form the combobox is displaying the 3 items (Choose a language ..., French, English) but without icons.

If I do the same thing at design time by affecting imagelist directly on the component and filling iconitems property manually, I recompile and launch that works!

But I need to run this dynamically, so I'm blocked! Someone as an idea to help me?

Just a last precision, I use Delphi Sydney 10.4.2 with unigui components 1.90.0.1555. Also tried uninstallation of components, cleaning and fresh install but unfortunately not better.

 

Thanks in advance for the attention you will give to my post and for your assistance.

Link to comment
Share on other sites

Hi the forum,

I've a little bit progressed on my problem.

In fact that works only if you put the piece of code inside the "OnCreate" event.

The problem now is if you need to change or clean and refill the combobx during the use of the application. In this case it doesn't work!

Is there somebody able to help me? Any help much appreciated.

Good afternoon to everybody.

Link to comment
Share on other sites

  • 1 month later...

Hi the forum,

I'm always in the dark.

I'm thinking to another approach. Is there possible to load the different icons corresponding to the the different items (plus the one selected) of the UniComboBox dynamically (once the combo is populated) with the assistance of the ClientEvents property (ExtEvents or UniEvents) ?

For the moment I've the following process :

  • Inside the MainModule, I've a TUniNativeImageList which is filled dynamically during the UniGUIMainModuleCreate event with the assistance of AddImageFile to add differents bmp of 20 x 20

 

  • Inside a TUniForm during the UniFormCreate event I have this :
    unicombobox.Images := UniMainModule.UniNativeImageListCommune;
    And here the code to loop every country to fill the combo like in the first discussion of this topic.

When I compile my project on the partition D:\ it seems to works but when I move the executable to C:\ it doesn't worked anymore but the location for the BMP is on C:\for both attempts.

For now, I saw that the folder created automatically by the executable during is launch in D:\ and C:\ is not totally the same. The one on D:\has more resources than C:\ which could explain that it works for D:\ and not for C:\ ?

Moreover I saw that inside the folder which is created automatically there is a sub folder titled "files" (where I can imagine to copy my BMP), so it's why I'm wondering if I could replace the blank icons of the combo, after the combo is rendered, directly in the JavaScript code?

Thanks in advance for the help.

Link to comment
Share on other sites

Hello,

On 12/17/2021 at 3:50 PM, Delphigui said:
unicombobox.Images := UniImageList1;
  intCompteur := 0;
  for strLangue in stlListe do
  begin
    with (unicombobox.IconItems.Add) do
    begin
      Caption := strLangue;
      ImageIndex := intCompteur;
    end;

    Inc(intCompteur);
  end;

Sorry I didn't notify sooner. I already opened a ticket in the support portal.

13 hours ago, Delphigui said:

Moreover I saw that inside the folder which is created automatically there is a sub folder titled "files" (where I can imagine to copy my BMP), so it's why I'm wondering if I could replace the blank icons of the combo, after the combo is rendered, directly in the JavaScript code?

You can try this JS code:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniComboBox1.JSInterface do
  begin
    // items[4] - Fifth record
    JSAssign('getStore().data.items[4].data.icon.iconUrl', ['files/free-icon-canary-islands.png']);
    JSCall('fireEvent', ['change']); // If the record is already selected
  end;
end;

 

Link to comment
Share on other sites

Hi Sherzod,

Thank you very much for your reply.

Quote

You can try this JS code:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniComboBox1.JSInterface do
  begin
    // items[4] - Fifth record
    JSAssign('getStore().data.items[4].data.icon.iconUrl', ['files/free-icon-canary-islands.png']);
    JSCall('fireEvent', ['change']); // If the record is already selected
  end;
end;

That works smoothly for the different items inside the combo but not for the one selected (even with the line "JSCall('fireEvent', ['change']);"). The icon stay blank.

But thanks a lot it's a progress because now I'm able to put icon for each item 🙂

Do you have another clue perhaps?

Thanks again for your help 🙏

Link to comment
Share on other sites

Unfortunately it doesn't work.

Another point strange :

  • I have 3 items in the combo
  • By defaut the second is selected with itemindex to 1
  • I use JSAssign('getStore().data.items[1].data.icon.iconUrl', ['files/English.bmp']); to put an icon only for the second item
  • If I select the third and some seconds later back to the second the icon of the second is not copied to the "selected zone"
  • So it appears that with your line of code we are able to properly set an icon for each item of the list of the combo but it seems to be separated of the mechanism which manage the icon of the selected item

Here is an illustration on the example.png :

  • As you can see in the selected zone there is a blank icon at the left of the text
  • If I chose French (with the wrong flag I know it's just for test), he will write French in the selected zone but the icon will stay blank in place of the union jack flag.
  • Perhaps it's normal because it's not normal behaviour?

Thanks again for your help really appreciated.

Example.png

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...