Search code examples
delphiunicodefastreport

Does Fast Report 4 (Delphi 7) support UTF8 using frxUserDataSet?


I've done my homework, and specifically:

1) Read the whole FASTREPORT 4 manual. It does not mention UTF8, nor Unicode support

2) Looked for an answer here on SO

3) Googled it around

If I set a Text field and fill it with Thai characters, they are perfectly printed, so FastReport CAN handle Unicode characters, at least it can print them.

If I try to "pass" a value using the callbacks provided by the frxUserDataSet, then what I see is some garbled not-unicode text. In particular, if I pass e.g. a string made with the same 10 Thai characters, I see the same "set" of 3 or 4 garbled characters repeated ten times, so I am sure the data is passed correctly, but then FastReport has probably no way to know that they should be handled as Unicode.

The callback requires the data passed back to be of "variant" type, so I guess it's totally useless to cast them to any type, because variant will accept any of them.

I forgot to mention that I get the strings from a MySql DB and the data is stored as UTF8, and I do not even copy the data in a local variable: what I get from the DB is put into the variant.

Is there a way to force FastReport to print the data received as Unicode?

Thank you


Solution

  • Yes, FR4 with Delphi7 supports UTF8 using frxUserDataSet.

    Just for future reference:

    1) You MUST set your DB (MySql in my case) to use UTF8

    2) You MUST set the character set in the component you use to access the DB to utf8 ("DAC for MySql" in my case, and the property is called ConnectionCharacterSet)

    3) In all the frxUserDataSet callbacks, before setting the "value" variable, you MUST CONVERT whatever you have using the Utf8decode Delphi system routine, like this:

    value := Utf8decode(fReports.q1.FieldValueByFieldName('yourDBfield'));

    where fReports is the form name, and q1 the component used to access the DB.

    I keep reading that using D7 and UniCode is almost impossible, but - as long as you use XP and up - it's only harder from what I am seeing. Unfortunately, I must use XP, D7 and cannot upgrade. But, as said, I am quickly becoming used to solve these problems so, in the future, I hope to be able to give back some help in the same way everybody has always helped me here :)