Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get currently selected Combobox value and use it as variable

My question is about Delphi 7.

I need to get currently selected ComboBox1 value to use it as Floating point variable in my code:

t:=t+ComboBox1. // Not sure what to write here...

Thank you!

like image 263
enflam3 Avatar asked Nov 19 '11 12:11

enflam3


People also ask

How do I find the value of a ComboBox?

Suppose your ComboBox name is comboBoxA . Then its value can be gotten as: string combo = comboBoxA. SelectedValue.


2 Answers

Not sure if the TryStrToFloat is already in Delphi 7, but if yes I would do it this way.

procedure TForm1.ComboBox1Change(Sender: TObject);
var
  Value: Double;
begin
  if TryStrToFloat(ComboBox1.Text, Value) then
    T := T + Value
  else
    ShowMessage('You''ve entered wrong value ...');
end;
like image 51
TLama Avatar answered Oct 13 '22 11:10

TLama


// ItemIndex is the index of the selected item
// If no item is selected, the value of ItemIndex is -1
if (ComboBox1.ItemIndex >= 0) then
begin
  t := t + StrToFloat(ComboBox1.Items[ComboBox1.ItemIndex]);
end;
like image 42
splash Avatar answered Oct 13 '22 11:10

splash