Automatic TxStringField size adjustment and Unicode
Posted: Tue 14 Jun 2011 08:41
I've recently created a real Unicode branch of the app and noticed that the automatic field size adjustment is not available for TWideStringField.
Steps:
- create a new VCL app
- add a TOraSession and TOraQuery querying a table with a string field
- add a component for the string field using the Fields Editor and lower the Size property of the TStringField
- add a button that opens the query and shows afterwards the Size property of the TStringField component (see my test code below)
- run the app
- press the button and see that the Size property of the TStringField component is equal to the actual size in the database
- close the app
- enable Options.UseUnicode in the TOraSession
- change TStringField to TWideStringField in the .PAS and .DFM file
- run the app again
- press the button
Expected: the Size property of the TStringField component is equal to the actual size in the database
Actual: the Size property of the TStringField component is *not* equal to the actual size in the database
In order to fix the problem I've changed line 916 in MemDS.pas (most recently release 7.20.0.6) in TMemDataSet.InternalOpen from
to
Steps:
- create a new VCL app
- add a TOraSession and TOraQuery querying a table with a string field
- add a component for the string field using the Fields Editor and lower the Size property of the TStringField
- add a button that opens the query and shows afterwards the Size property of the TStringField component (see my test code below)
- run the app
- press the button and see that the Size property of the TStringField component is equal to the actual size in the database
- close the app
- enable Options.UseUnicode in the TOraSession
- change TStringField to TWideStringField in the .PAS and .DFM file
- run the app again
- press the button
Expected: the Size property of the TStringField component is equal to the actual size in the database
Actual: the Size property of the TStringField component is *not* equal to the actual size in the database
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
const
ExpectedSize = 50;
var
Counter: Integer;
begin
Counter := 0;
if OraQuery1FOO.Size ExpectedSize then
Inc(Counter);
OraQuery1.Open;
if OraQuery1FOO.Size = ExpectedSize then
Inc(Counter);
if Counter = 2 then
ShowMessage('PASS')
else
ShowMessage('FAIL');
end;
Code: Select all
if FieldDefs[i].DataType = ftString then begin
Code: Select all
if FieldDefs[i].DataType in [ftString, ftWideString] then begin