1 (edited by Hedan 2019-12-15 11:22:23)

Topic: Combobox Index Number

Hi,

A "new" ComboBox Index Question.

I have been struggled with this for while now. What i want to do is something like this.

When a user creates a new record i have a combobox in the form with different countries too choose from.

When someone fills in a Company name i check if there is an INI-file in that companys name.
If there is, a number of fields in the form if filled in automatically from the INI-file.

"
Adr := Form1.Edit3.Text;
If  FileExists(IFile) Then
begin
ini := TIniFile.Create(ExtractFilePath(Application.ExeName)+ '\ini\'+ Adr + '.ini');
  try
   Form1.Edit8.Text := ini.ReadString('Settings', 'Typ', '');
  -- A --> Str := ini.ReadString('Settings', 'Index', '');
  -- B --> Form1.ComboBox1.ItemIndex := StrToInt(Str);
   Form1.Edit7.Text := ini.ReadString('Settings', 'PG', '');
   Form1.Edit6.Text := ini.ReadString('Settings', 'OCR', '');
"
In the form i got a function, that helps users to create the INI-file.

The user can choose a country from a ComboBox in the form, but i really want to store the index number in the INI-file so that the row
markt A and B above works.

Does anyone have a solution to how to easy find the Index of a value in a ComboBox.

Regards
Hedan

2 (edited by sibprogsistem 2019-12-16 09:30:58)

Re: Combobox Index Number

var
ini:TIniFile;
a:integer;
begin
 ini:=TIniFile.Create(ExtractFilePath (ParamStr (0))+'settings.ini');
 Form1.ComboBox1.ItemIndex:=ini.ReadInteger('settings', 'Index',a);
end;

Re: Combobox Index Number

Thanks, but mayby i was unclear what i ment.

When a user selects a country from the ComboBox in the CreateINI_Form, for example "Germany". I really want to write the index number of "Germany" to the INI-file instead of the word "Germany".

So the problem is to get the index number for, in this case "Germany".

Hedan

4 (edited by sibprogsistem 2019-12-16 13:37:14)

Re: Combobox Index Number

Hedan wrote:

Thanks, but mayby i was unclear what i ment.

When a user selects a country from the ComboBox in the CreateINI_Form, for example "Germany". I really want to write the index number of "Germany" to the INI-file instead of the word "Germany".

So the problem is to get the index number for, in this case "Germany".

Hedan

var
ini:TIniFile;
begin
 ini:=TIniFile.Create(ExtractFilePath (ParamStr (0))+'settings.ini');
 ini.WriteInteger('settings', 'Index',Form1.ComboBox1.dbItemID);
end;

Re: Combobox Index Number

Thank you...

One step to a sulotion. It works OK, but i get the wrong index number.

If, i make it the hard way and create the INI-file myself i would put in the integer 3 for item number 3 in the combobx list.

dbItemID returns a integer not even close to 3.

What am i doing wrong??

Hedan

Re: Combobox Index Number

check database records

Re: Combobox Index Number

Hi again,

And thanks for your patience...

Don´t really know what you mean with "Check database records". Rebuild index?? How?

A Display of ID for the 25 records i have. See picture.

As i sayed earlier, to get the right value in the comboBox i have to input the number of the item in the combobox.

If i have:

Germany
England
France
Italy
Sweden
Norway

I have to put in the integer 3 to get "France" and not the database ID. Very strange....

Re: Combobox Index Number

attach your project

Re: Combobox Index Number

Form1.ComboBox1.dbItemID returns ID of record, not index.


Use Form1.ComboBox1.ItemIndex for index.

Dmitry.

Re: Combobox Index Number

Thank you very much,

That did the trick, very happy you to get this solution.

Hedan