Andrew Spencer 2 Posted November 18 I have a table with a float field, and would like to format the decimal places displayed for this value based on the content of another (integer) field in the same record. Access is via a TFDQuery. I tried to hook the OnGetText event of the float field in question with the following code, but this is giving an access violation error. procedure TfrmMain.ItemValueFormat(Sender: TField; var Text: String; DisplayText: Boolean); begin Text := Format('%.*f', [qMyTable.FieldByName('decimals').AsInteger, Sender.Value]); end; If anyone has tried something like this before, I'd appreciate some tips/code snippets. Thanks! Share this post Link to post
Andrew Spencer 2 Posted November 18 I get the feeling that qMyTable is no longer in scope when this event is launched Share this post Link to post
Andrew Spencer 2 Posted November 18 Answering my own questions... The line should have been Text := Format('%.*f', [TfrmMain.qMyTable.FieldByName('decimals').AsInteger, Extended(Sender.Value)]); Share this post Link to post
Remy Lebeau 1432 Posted November 18 I would not use any global variable at all. The TField has access to the DataSet that owns the current record's fields, eg: Text := Format('%.*f', [Sender.DatSet.FieldByName('decimals').AsInteger, Extended(Sender.Value)]); Alternatively: Text := FloatToStrF(Sender.Value, ffFixed, 18, Sender.DatSet.FieldByName('decimals').AsInteger); 1 Share this post Link to post