1

I have a TDBGrid linked to a TDataSource with a TFibDataSet behind. On the OnCalcFields of the dataset I'm trying to add the string 'Russisch (русский)'.

procedure TForm1.pFIBDataSet1CalcFields(DataSet: TDataSet);
begin
  DataSource1.DataSet.FieldByName('Language').AsString := ('Russisch (русский)');

The problem is that in the grid the result is displayed as :Russisch(????????)

 DataSource1.DataSet.FieldByName('Language').AsWideString :=('Russisch (русский)'); 

has the same result

FibDataBase component has ConnectParams.Charset set to UTF-8. Also I set in the DBParams value lc_ctype=UTF8.

What I'm doing wrong here?

LE: Delphi XE, Firebird and UTF8 - this does not solve my problem.

LE1: Problem occurs only with calculated fields. Live data 'Russisch (русский)' is displayed correctly.

Community
  • 1
  • 1
RBA
  • 12,337
  • 16
  • 79
  • 126
  • 2
    Does this happen only for calculated fields or with live data as well? – kobik Sep 05 '12 at 09:46
  • I've made a test now, and it happens only with calculated fields. If live data is ''Russisch (русский)' is displayed correctly. – RBA Sep 05 '12 at 09:48
  • I don't have access to Delphi XE at the moment. Look at the definition of `AsString`. Is it `AnsiString`? – iMan Biglari Sep 05 '12 at 09:57
  • I have tried to make it AsWideString and the result is the same – RBA Sep 05 '12 at 09:58
  • 2
    If you use persistent fields, make sure you have it defined as T(FIB)WideStringField field instead of TStringField. – Marcodor Sep 05 '12 at 10:03
  • For the persistent fields this is not a problem. 'Russisch (русский)' is displayed correctly. My problem is on the calculated fields. – RBA Sep 05 '12 at 10:05
  • Is your unit file saved as `unicode` itself? I mean, what does `ShowMessage('Russisch (русский)');` display? – iMan Biglari Sep 05 '12 at 10:10
  • Did you define your calculated field as `string` or `WideString`? Note that when you create a `string` field using the buil-in field creator of `TDataSet`, it's not `UTF`. – iMan Biglari Sep 05 '12 at 10:17
  • iMan Biglari - post it as answer – RBA Sep 05 '12 at 10:22
  • "Persistent fields" not means physical fields from your database. They just are explicitly defined/created in your class instead of dynamic gathering and creation. More info: http://stackoverflow.com/questions/6526832/code-to-create-persistent-field-components-associated-with-tdataset – Marcodor Sep 05 '12 at 12:52

1 Answers1

3

I guess you made the same mistake I always make. When you create a field like this:

enter image description here

it's ANSI. You have to select WideString for it to be unicode:

enter image description here

iMan Biglari
  • 4,674
  • 1
  • 38
  • 83