0

I have a DBEdit control, connnected to an ADO record set displaying a floating point number. This number has been masked as a currency through the field editor of the record set. This causes a currency sign to be displayed at the front of the number, eg 1.5923432 -> £1.59. I'd like the user to be able to edit the number, and then click a button that pushes the edited number to the database. However, when I get the text content of the box (using strtofloat(DBEdit1.text)) the result produces an error as the text of the dbedit does of course include the currency sign, so cannot be converted to a number.

How can I get the plaintext contents of the DBEdit, (without the currency symbol) without any masking? Would simply deleting the first character from the front of the string be an effective way to do it or is there a simpler way?

James Paterson
  • 2,652
  • 3
  • 27
  • 40
  • How exactly are you converting it? I don't see that code... – Jerry Dodge Feb 18 '15 at 22:05
  • Have you set the field's edit and display properties to change the edit format? e.g. TFloatField(Table1.FieldByName('amount')).EditFormat := '#0.00'; –  Feb 18 '15 at 22:07
  • @JerryDodge I have a recordset with field details like: http://puu.sh/g2OrN/cf94fa44fd.png. This, in the object inspector, gives me a True/False "currency" field: http://puu.sh/g2OHm/fe9eeabe65.png. Setting this to true masks any dbedits using the field and formats it as a currency (The details in the database are unchanged). – James Paterson Feb 18 '15 at 22:15
  • Putting the response to a request for more details in images on an external site is not how things work here. Please [edit] your question and provide that information **in textual form** here in the question itself. (External links become invalid or are unavailable, meaning the content is lost. Putting additional information in comments gets lost among the clutter and is not clearly visible to readers or future users here.) – Ken White Feb 19 '15 at 02:15
  • Have you considered using the `OnSetText` event handler for your field? – Guillem Vicens Feb 19 '15 at 08:40

1 Answers1

0

I figured it out. You can get the contents of a dbedit with no masking by using: DBEdit1.Field.AsReal or DBEdit1.Field.AsInteger

This will give you the numerical value contained within the dbedit, with no currency signs or commas.

James Paterson
  • 2,652
  • 3
  • 27
  • 40