?
Solved

DBGrid 1/2 & 1/4

Posted on 2005-03-25
3
Medium Priority
?
203 Views
Last Modified: 2010-04-05
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


Thanks
0
Comment
Question by:ameens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 13635373
???
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.
Cheers
0
 
LVL 13

Accepted Solution

by:
Ashok earned 250 total points
ID: 13636112
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.)

HTH
0
 
LVL 13

Expert Comment

by:Ashok
ID: 13636233
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.

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

HTH
Ashok
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question