Hi,
Does anyone know how to compare 2 values which is in the same column in a string grid.
I want to compare 2 values in order to sort the values. I wrote my code as follows:
Begin
MYStringGrid := False;
If MYStringGrid.RowCount > 1 Then
While NOT SortedX Do
Begin
SortedX := True;
For i:= 2 To MaxPoints Do
Begin
If ( StrToFloat(MYStringGrid.Cells[1,i]) < StrToFloat(MYStringGrid.Cells[1,i-1]) ) Then
Begin
SortedX := False;
Temp1 := MYStringGrid.Cells[1,i];
Temp2 := MYStringGrid.Cells[2,i];
MYStringGrid.Cells[1,i] := MYStringGrid.Cells[1,i-1];
MYStringGrid.Cells[2,i] := MYStringGrid.Cells[2,i-1];
MYStringGrid.Cells[1,i-1] := Temp1;
MYStringGrid.Cells[2,i-1] := Temp2;
End;
In the OnSelectCell event i have called the sortX function (Above). but my problem is each and everytime i run the program it allows me to enter only one value to the grid. After that it will display an error message saying that 'Error converting floating point numbers' . I know this causes the conversion i have made in my sortX Function. Does anyone know how to fix my problem???????????
Many Thanks
Sanjna....
Does anyone know how to compare 2 values which is in the same column in a string grid.
I want to compare 2 values in order to sort the values. I wrote my code as follows:
Begin
MYStringGrid := False;
If MYStringGrid.RowCount > 1 Then
While NOT SortedX Do
Begin
SortedX := True;
For i:= 2 To MaxPoints Do
Begin
If ( StrToFloat(MYStringGrid.Cells[1,i]) < StrToFloat(MYStringGrid.Cells[1,i-1]) ) Then
Begin
SortedX := False;
Temp1 := MYStringGrid.Cells[1,i];
Temp2 := MYStringGrid.Cells[2,i];
MYStringGrid.Cells[1,i] := MYStringGrid.Cells[1,i-1];
MYStringGrid.Cells[2,i] := MYStringGrid.Cells[2,i-1];
MYStringGrid.Cells[1,i-1] := Temp1;
MYStringGrid.Cells[2,i-1] := Temp2;
End;
In the OnSelectCell event i have called the sortX function (Above). but my problem is each and everytime i run the program it allows me to enter only one value to the grid. After that it will display an error message saying that 'Error converting floating point numbers' . I know this causes the conversion i have made in my sortX Function. Does anyone know how to fix my problem???????????
Many Thanks
Sanjna....