TWebCombobox Does Not Populate

I have the following HTML code:

 <div class="col-md-2 text-center">
                          <h6 class="title">Carrier</h6>
                          <select id="carriers" style="width:150px;"></select>
                       </div>

Then on my form, I assign the TWebCombobox element Id = carriers and the name = carrierlist
I call a load procedure from webformshow with the following code:

CarrierList.Items.BeginUpdate;
   try
      CarrierList.Items.Clear;
      CarrierList.Items.Add('All')  //more to come later
   finally
      CarrierList.Items.EndUpdate;
   end;

But the control is empty

I had a similar case recently. I realized it happened to me if the itemindex is not changed from -1. I set it to 0 and solved my problem.

Thanks for the tip but still doe not work

I gave it a try and it worked? Started from a new TMS WEB Core Boostrap Application template.

image

Here's the code, just copied and pasted what you had.

unit Unit1;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls;

type
  TForm1 = class(TWebForm)
    CarrierList: TWebComboBox;
    procedure WebFormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WebFormShow(Sender: TObject);
begin
CarrierList.Items.BeginUpdate;
   try
      CarrierList.Items.Clear;
      CarrierList.Items.Add('All')  //more to come later
   finally
      CarrierList.Items.EndUpdate;
   end;
end;

end.

And Unit1.html had your block of HTML in it as well:

<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>TMS Web Project</title>
    <style>
    </style>
  </head>
  <body>
   <div class="col-md-2 text-center">
                          <h6 class="title">Carrier</h6>
                          <select id="carriers" style="width:150px;"></select>
                       </div>
  </body>
</html>

So not sure what to suggest? Are you on the latest TMS WEB Core? maybe double-check the ElementID spelling (all that stuff is case-sensitive of course).

arrgh!!! I had the same element ID in another form! All working now, thanks everyone

1 Like