3

I am using Anydac components to access database. TADOQuery is for selecting of data from SQL database.

One of the fields is text, but I need to display some RTF instead of this text (same text but with highlighted words, etc). I tried to create calculated field of BLOB type and fill it with correct value (original text from DB + some processing) in OnCalcFields event of TADQuery. But it doesn't work. I get AV on start of app:

"Field 'xxx' cannot be a calculated or lookup field.".

If I change FieldKind property to fkInternalCalc (default value is fkCalculated) then app starts, but then I get AV at OnCalcFields when try to set value:

"Dataset not in edit or insert mode."

If I define calculated string field (instead of BLOB field), then everything is ok, but string type has another problem. For string type I have to provide Size property limiting max size of the text. And if I use value above 64k, for example 67000, I get AV when try to assign value (even short value!) at OnCalcFields event handler:

Project xxx.exe raised exception class $C0000005 with message "access violation at 0x004094fc: read of address 0xfffffffc".

So, I can create neither calculated BLOB field nor calculated string field. (It is limited in max size and there is no information what maximum size is really safe. I found problem with size >64k, but not sure it will be stable with smaller blocks.)

Any ideas what I am doing wrong?

Update: At moment I have implemented it in a different way. I replace data on presentation layer, but it is just a workaround and question is still here. Is it possible to use calculated fields of BLOB type in Delphi (preferably with Anydac TADQuery)? Is there any information regarding to limitations on calculated fields of string type (or maybe someone has experience how to avoid them)?

procedure TDBDM.CommentsCalcFields(DataSet: TDataSet);
begin
  CommentsHighlighted.AsString := 'test';
end;

So, TADQuery has some SQL query, some fields defined + 1 calculated field of BLOB type + OnCalcFields event handler (code is above). It generates AV when I start app (and try to open query). Other things I tried were described earlier.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Andrei Galatyn
  • 3,322
  • 2
  • 24
  • 38
  • Why not use an ordinary field? Why do you think it should be "calculated"? If you get an AV or exception then post the relevant code. – Sam Aug 05 '13 at 17:42
  • 1
    2Sam: Sorry, i don't understand what you mean when you say "ordinary field". Calculated field is ordinary field, but it is not stored in DB, it is calculated, that is the only difference i think. I can't add new field in DB, because i don't need it in the DB. And i don't see how to add "regular" field which is neither calculated nor stored in the DB. All the code is MyCalcField.AsString := 'test' at OnCalcFields event handler, everything else done in GUI as i described, so probably it is not something related with the code. – Andrei Galatyn Aug 05 '13 at 19:25
  • Why not store the rtf text in the database rather than processing it at the time of selecting. – KE50 Aug 06 '13 at 05:11
  • 2Sam: Problem is not (my) code related. It seems like problem in Anydac library (maybe some versions of Anydac do not suffer of that?) or in Delphi DB-related components (Anydac rely on standard component in many ways). – Andrei Galatyn Aug 06 '13 at 06:05
  • 1
    2KE50: Production DB is not a playground, i will do changes in DB only if it is really required. That is not a case. – Andrei Galatyn Aug 06 '13 at 06:08

0 Answers0