Question

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!

Was it helpful?

Solution

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;

OTHER TIPS

// 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;

In Delphi 10.2 Tokyo i just do:

[string] := ComboBox.Selected.Text

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top