DBGrid 1/2 & 1/4

I am writing a program that uses labour times that need to be entered into a grid in 1/2 & 1/4 (Eg.) 1.2 0r 1.6 0r 2.9 etc can somebody please help as i only know how to enter full numbers in the DbGrid

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

AshokConnect With a Mentor Commented:
One of the ways you could do it is
Add all fields to TQuery (or TTable).
Make the field invisible which accepts 1/2 1/4.
Add a calculated field to the TTable (or TQuery), type String, name the field something like fraction1.

Add all fields in DBGrid by double-clicking on the grid.
Click on fraction1 field then in Object Inspector for this field, click on PickList property
and add all possible values in "1/2", "1/4", format (of cource without double quotes).

Us OnCalcEvents to store correct value to the field which you made invisible depending on what user has selected.

This way users see what they like and you store what you like (0.5 for 1/2, 0.25 for 1/4, etc.)

You want to enter float numbers in the DBGrid on runtime? Because ... if it is a DBGrid it should be connected to a Table/Query datasource. And if the table/Query contains records that have on some fields values that are not integer... then the DBGrid will show them without problem. So your question must be about entering the values in editing mode on runtime.
For that you should try to use the '.' separator for decimals. In case that this is your problem, you could make a function on keypressed event (up/down/pressed) that captures the key pressed and replaces it with '.' if it is ','.
Let me know if I understood your question.
If not then elaborate it.
If number of possibilities are too many,
you can just create a Calculated field (without PickList)
then parse the string to make sure it is valid (does not have invalid characters).
then if there is a space, take all numbers before the space to treat them as a whole number (store it in wholeNum var).
then search for "/", if exists take number before and after "/" and

Following is some code you have to apply it to OnCalc event of the Calcuted field you created in first step.

  wholeNum : Integer;
  frac, actual_num : double;
  // store value to  wholeNum here
  frac := numBeforeSlash / numAfterSlash;
  actual_num := wholeNum + frac;
  // store actual_num to the database  

All Courses

From novice to tech pro — start learning today.