0

How can I use Unicode (or just Cyrillic) chars on TStringField.FieldName property of TClientDataSet on Delphi?

I've tried this and it doesn't work on the last line:

aStringField := TStringField.Create(aClientDataSet);
aStringField.FieldName := 'аАяЯ';
aStringField.DataSet := aClientDataSet;
aClientDataSet.CreateDataset;
Dmitry
  • 14,306
  • 23
  • 105
  • 189

1 Answers1

1

The program below compiles and executes (XE4) without error.

program CDS;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, db, dbclient;

procedure Test;
var
  aClientDataSet : TClientDataSet;
  aStringField : TStringField;
begin
  aClientDataSet := TClientDataSet.Create(Nil);
  aStringField := TStringField.Create(aClientDataSet);
  aStringField.FieldName := 'аАяЯ';
  aStringField.DataSet := aClientDataSet;
  aClientDataSet.CreateDataset;
end;

begin
  Test;
end.

Otoh if I use your declaration of aStringField (i.e. as TField) and your method of creating it, I get the r/time error "Invalid field type" on aClientDataSet.CreateDataset.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • I've used TStringField and got error "Field not found". The question was simplified. – Dmitry May 23 '14 at 19:01
  • Well, it works for me, like I said. What Delphi version are you using? Did you try running what I posted? – MartynA May 23 '14 at 19:04
  • Delphi XE5. Didn't try your code yet but it looks similar to mine. – Dmitry May 23 '14 at 19:06
  • Also, you aren't showing all the properties of your TClientDataSet, so: do you have any FieldDefs defined on it. – MartynA May 23 '14 at 19:08
  • No, I haven't: `aClientDataSet := TClientDataSet.Create(nil);` – Dmitry May 23 '14 at 19:17
  • 2
    Well, the program in my answer boils what you posted down to a SSCCE, and that produces no error. If it doesn't work for you, which you still haven't said, then presumably the problem must be some difference between XE4 and XE5; if otoh it does, but your code still doesn't work, it must be because of something you're not showing us. – MartynA May 23 '14 at 19:22
  • Your program works fine. But my code is exactly the same but on the big project. – Dmitry May 23 '14 at 19:26
  • 1
    Happy hunting then! I obviously can't help you any more. – MartynA May 23 '14 at 19:28
  • I've found out the error raises with many fields. (One field works fine on the project too.) – Dmitry May 23 '14 at 19:29
  • Then make a SSCCE with the second field and QC it. – MartynA May 23 '14 at 19:42