WebComboBox fails to select the database value.

I am using a TWebComboBox to display the Country for my Person Entity.
On a new record and on updating and saving an existing record the control works correctly.

However, on editing an existing record the control fails to show the correct country. It picks the first alphabetic country it finds.

Initially, I was using code from the generated Web app. As this failed to work I copied the same code from the MUSIC demo. This, in essence, calls SelectCountry once the Person and Country Entities are loaded. The code I copied referred to ....properties['id'], I subsequently changed this to properties['i_countryid']. Neither work.

I wrote to the console to see the data, shown in the image provided.

  1. Please tell me what to compare in order for this to work.
  2. How to iterate through properties to see which properties are available.

procedure TFViewProfile.SelectCountry;
var
I: Integer;
begin
for I := 0 to cbCountryid.Items.Count - 1 do
begin
console.log(TJSObject(cbCountryid.Items.Objects[I]));
console.log(TJSObject(WebUserDatasetCountryid.Value));
console.log(TJSObject(cbCountryid.Items.Objects[I]).Properties['i_countryid']);
console.log(TJSObject(cbCountryid.Items.Objects[I]).Properties['id']);
if TJSObject(cbCountryid.Items.Objects[I]).Properties['i_countryid'] =
TJSObject(WebUserDatasetCountryid.Value).Properties['i_countryid'] then
begin
cbCountryid.ItemIndex := I;
Break;
end;
end;
end;

Foreign key in combobox

Property names in raw JavaScript objects are case-sensitive. The problem here is just that the actual property name of the object is i_CountryId, but you are trying to read the property i_countryid, which doesn't exist.

To get the property names of an object, you can use:

for propName in TJSObject.keys(TJSObject(cbCountryid.Items.Objects[I])) do
  console.log(propName);

Yes!! It works, Yay!

Thank you. And more so of reminding me of case sensitivity and how to see the properties.

FYI : The reason I went down this road was that the generated code failed to work. But Hey, I'm smiling.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.