Home Using For to add numbers as string in combobox text increasing by 0.1
Reply: 1

Using For to add numbers as string in combobox text increasing by 0.1

K Boykin
1#
K Boykin Published in 2018-02-11 15:57:32Z

I want to code adding numbers from 1 to 5 to combobox as text increasing by 0.1 in delphi 2010, but keep getting errors. I am a self-taught amateur coder and have never attempted this before. This is what I tried:

procedure TfrmWines.FillCombos;
var
  c : TStringList;
  i : Double;
begin
  c :=  TStringlist.Create;
  with c do
  begin
    sorted  :=  True;
    duplicates  := dupIgnore;
  end;
  try
    wdatamod.wines.first;
    wdatamod.wines.DisableControls;
    while not wdatamod.wines.eof do
    begin
      c.Add(wdatamod.wines.FieldByName('country').AsString);
      wdatamod.wines.Next;
    end;
  finally
     edCountryLst.Items :=  c;
     wdatamod.wines.EnableControls;
     c.Free;
  end;
  edRating.Items.Clear;
  for i := 1 to 5 do
  begin
    edRating.Items.add(FloatToStr(0.1 +i));
  end;
end;

What am I doing wrong? Any help with helping me figure out would be appreciated. Combobox strings should 1, 1.1, 1.2, and so on up to 5.0.

K Boykin
2#
K Boykin Reply to 2018-02-11 20:54:33Z

Thanks to @Remy Lebeau, this is the solution.

procedure TfrmWines.FormActivate(Sender: TObject);
var
  i : integer;
begin
  edRating.Items.Clear;
  for i := 10 to 50 do
  begin
    edRating.Items.add(FloatToStr(i /10));
  end;
end;

Again, thanks!!!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.295249 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO