Bladeren bron

* PChar -> PansiChar

Michaël Van Canneyt 2 jaren geleden
bovenliggende
commit
eb009243aa
64 gewijzigde bestanden met toevoegingen van 1138 en 953 verwijderingen
  1. 10 6
      packages/fcl-db/examples/dbftool.lpi
  2. 2 0
      packages/fcl-db/examples/dbftool.lpr
  3. 1 1
      packages/fcl-db/fpmake.pp
  4. 33 18
      packages/fcl-db/src/base/bufdataset.pas
  5. 22 20
      packages/fcl-db/src/base/bufdataset_parser.pp
  6. 6 6
      packages/fcl-db/src/base/dataset.inc
  7. 12 8
      packages/fcl-db/src/base/db.pas
  8. 3 0
      packages/fcl-db/src/base/dbcoll.pp
  9. 10 10
      packages/fcl-db/src/base/dsparams.inc
  10. 2 2
      packages/fcl-db/src/base/fieldmap.pp
  11. 89 28
      packages/fcl-db/src/base/fields.inc
  12. 4 1
      packages/fcl-db/src/base/sqltypes.pp
  13. 1 1
      packages/fcl-db/src/base/xmldatapacketreader.pp
  14. 8 6
      packages/fcl-db/src/datadict/fpdatadict.pp
  15. 37 37
      packages/fcl-db/src/dbase/dbf.pas
  16. 2 2
      packages/fcl-db/src/dbase/dbf_collate.pas
  17. 3 1
      packages/fcl-db/src/dbase/dbf_common.inc
  18. 4 5
      packages/fcl-db/src/dbase/dbf_common.pas
  19. 87 87
      packages/fcl-db/src/dbase/dbf_dbffile.pas
  20. 10 9
      packages/fcl-db/src/dbase/dbf_fields.pas
  21. 2 2
      packages/fcl-db/src/dbase/dbf_idxcur.pas
  22. 89 89
      packages/fcl-db/src/dbase/dbf_idxfile.pas
  23. 4 4
      packages/fcl-db/src/dbase/dbf_lang.pas
  24. 4 4
      packages/fcl-db/src/dbase/dbf_memo.pas
  25. 4 4
      packages/fcl-db/src/dbase/dbf_parser.pas
  26. 2 2
      packages/fcl-db/src/dbase/dbf_pgcfile.pas
  27. 4 4
      packages/fcl-db/src/dbase/dbf_pgfile.pas
  28. 147 143
      packages/fcl-db/src/dbase/dbf_prscore.pas
  29. 127 127
      packages/fcl-db/src/dbase/dbf_prsdef.pas
  30. 14 14
      packages/fcl-db/src/dbase/dbf_prssupp.pas
  31. 1 1
      packages/fcl-db/src/dbase/dbf_reg.pas
  32. 9 9
      packages/fcl-db/src/dbase/dbf_struct.inc
  33. 7 7
      packages/fcl-db/src/dbase/dbf_wnix.inc
  34. 14 14
      packages/fcl-db/src/dbase/dbf_wos2.inc
  35. 5 5
      packages/fcl-db/src/dbase/dbf_wtil.pas
  36. 3 3
      packages/fcl-db/src/export/fpcsvexport.pp
  37. 3 3
      packages/fcl-db/src/export/fpdbexport.pp
  38. 2 2
      packages/fcl-db/src/export/fpsimplejsonexport.pp
  39. 3 3
      packages/fcl-db/src/export/fptexexport.pp
  40. 9 9
      packages/fcl-db/src/paradox/paradox.pp
  41. 26 26
      packages/fcl-db/src/sdf/sdfdata.pp
  42. 1 1
      packages/fcl-db/src/sqldb/examples/bcreatetable.pp
  43. 4 4
      packages/fcl-db/src/sqldb/interbase/fbadmin.pp
  44. 6 6
      packages/fcl-db/src/sqldb/interbase/fbeventmonitor.pp
  45. 19 20
      packages/fcl-db/src/sqldb/interbase/ibconnection.pp
  46. 5 6
      packages/fcl-db/src/sqldb/mssql/mssqlconn.pp
  47. 75 45
      packages/fcl-db/src/sqldb/mysql/mysqlconn.inc
  48. 12 12
      packages/fcl-db/src/sqldb/odbc/odbcconn.pas
  49. 5 5
      packages/fcl-db/src/sqldb/oracle/oracleconnection.pp
  50. 34 13
      packages/fcl-db/src/sqldb/postgres/pqconnection.pp
  51. 3 3
      packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp
  52. 32 21
      packages/fcl-db/src/sqldb/sqldb.pp
  53. 2 2
      packages/fcl-db/src/sqldb/sqlite/sqlite3backup.pas
  54. 13 13
      packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp
  55. 13 8
      packages/fcl-db/tests/bufdatasettoolsunit.pas
  56. 6 6
      packages/fcl-db/tests/dbftoolsunit.pas
  57. 6 2
      packages/fcl-db/tests/dbtestframework.lpi
  58. 11 7
      packages/fcl-db/tests/sqldbtoolsunit.pas
  59. 2 2
      packages/fcl-db/tests/testdatasources.pas
  60. 13 11
      packages/fcl-db/tests/testdbbasics.pas
  61. 12 10
      packages/fcl-db/tests/testdbexport.pas
  62. 27 29
      packages/fcl-db/tests/testfieldtypes.pas
  63. 2 2
      packages/fcl-db/tests/testsqlscript.pas
  64. 10 2
      packages/fcl-db/tests/toolsunit.pas

+ 10 - 6
packages/fcl-db/examples/dbftool.lpi

@@ -1,14 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <CONFIG>
   <ProjectOptions>
-    <Version Value="9"/>
+    <Version Value="12"/>
     <PathDelim Value="\"/>
     <General>
       <Flags>
         <MainUnitHasCreateFormStatements Value="False"/>
+        <CompatibilityMode Value="True"/>
       </Flags>
       <SessionStorage Value="InProjectDir"/>
-      <MainUnit Value="0"/>
       <Title Value="DBFTool"/>
       <UseAppBundle Value="False"/>
       <ResourceType Value="res"/>
@@ -16,9 +16,6 @@
     <i18n>
       <EnableI18N LFM="False"/>
     </i18n>
-    <VersionInfo>
-      <StringTable ProductVersion=""/>
-    </VersionInfo>
     <BuildModes Count="1">
       <Item1 Name="Default" Default="True"/>
     </BuildModes>
@@ -27,9 +24,16 @@
     </PublishOptions>
     <RunParams>
       <local>
-        <FormatVersion Value="1"/>
         <CommandLineParams Value="--createdemo"/>
       </local>
+      <FormatVersion Value="2"/>
+      <Modes Count="1">
+        <Mode0 Name="default">
+          <local>
+            <CommandLineParams Value="--createdemo"/>
+          </local>
+        </Mode0>
+      </Modes>
     </RunParams>
     <Units Count="1">
       <Unit0>

+ 2 - 0
packages/fcl-db/examples/dbftool.lpr

@@ -19,9 +19,11 @@ uses {$IFDEF UNIX} {$IFDEF UseCThreads}
   dbf,
   dbf_fields,
   dbf_common,
+  dbf_prscore,
   dateutils,
   fpdbexport,
   fpcsvexport,
+  bufdataset,
   fpdbfexport,
   fpfixedexport,
   fprtfexport,

+ 1 - 1
packages/fcl-db/fpmake.pp

@@ -82,7 +82,7 @@ begin
     P.Dependencies.Add('pxlib',ParadoxOSes);
     P.Dependencies.Add('fcl-json');
 
-    P.Options.Add('-S2h');
+//    P.Options.Add('-S2h');
 
     // base
     T:=P.Targets.AddUnit('bufdataset.pas');

+ 33 - 18
packages/fcl-db/src/base/bufdataset.pas

@@ -426,9 +426,10 @@ type
     const
       FpcBinaryIdent1 = 'BinBufDataset'; // Old version 1; support for transient period;
       FpcBinaryIdent2 = 'BinBufDataSet';
-      StringFieldTypes = [ftString,ftFixedChar,ftWideString,ftFixedWideChar];
+      AnsiStringFieldTypes = [ftString,ftFixedChar];
+      UnicodeStringFieldTypes = [ftWideString,ftFixedWideChar];
       BlobFieldTypes = [ftBlob,ftMemo,ftGraphic,ftWideMemo];
-      VarLenFieldTypes = StringFieldTypes + BlobFieldTypes + [ftBytes,ftVarBytes];
+      VarLenFieldTypes = AnsiStringFieldTypes + UnicodeStringFieldTypes + BlobFieldTypes + [ftBytes,ftVarBytes];
     var
       FNullBitmapSize: integer;
       FNullBitmap: TBytes;
@@ -779,13 +780,13 @@ function DBCompareText(subValue, aValue: pointer; size: integer; options: TLocat
 
 begin
   if [loCaseInsensitive,loPartialKey]=options then
-    Result := AnsiStrLIComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
+    Result := AnsiStrLIComp(PAnsiChar(subValue),PAnsiChar(aValue),length(PAnsiChar(subValue)))
   else if [loPartialKey] = options then
-    Result := AnsiStrLComp(pchar(subValue),pchar(aValue),length(pchar(subValue)))
+    Result := AnsiStrLComp(PAnsiChar(subValue),PAnsiChar(aValue),length(PAnsiChar(subValue)))
   else if [loCaseInsensitive] = options then
-    Result := AnsiCompareText(pchar(subValue),pchar(aValue))
+    Result := AnsiCompareText(PAnsiChar(subValue),PAnsiChar(aValue))
   else
-    Result := AnsiCompareStr(pchar(subValue),pchar(aValue));
+    Result := AnsiCompareStr(PAnsiChar(subValue),PAnsiChar(aValue));
 end;
 
 function DBCompareWideText(subValue, aValue: pointer; size: integer; options: TLocateOptions): LargeInt;
@@ -1059,8 +1060,8 @@ end;
     for b := 0 to ALength-1 do
       begin
       s1 := s1 + ' ' + hexStr(pbyte(Data)[b],2);
-      if pchar(Data)[b] in ['a'..'z','A'..'Z','1'..'9',' '..'/',':'..'@'] then
-        s2 := s2 + pchar(Data)[b]
+      if PAnsiChar(Data)[b] in ['a'..'z','A'..'Z','1'..'9',' '..'/',':'..'@'] then
+        s2 := s2 + PAnsiChar(Data)[b]
       else
         s2 := s2 + '.';
       if length(s2)=16 then
@@ -4344,14 +4345,14 @@ end;
 constructor TFpcBinaryDatapacketHandler.Create(ADataSet: TCustomBufDataset; AStream: TStream);
 begin
   inherited;
-  FVersion := 20; // default version 2.0
+  FVersion := 30; // default version 3.0
 end;
 
 procedure TFpcBinaryDatapacketHandler.LoadFieldDefs(var AnAutoIncValue: integer);
 
 var FldCount : word;
     i        : integer;
-    s        : string;
+    s        : ansistring;
 
 begin
   // Identify version
@@ -4388,8 +4389,10 @@ end;
 
 procedure TFpcBinaryDatapacketHandler.StoreFieldDefs(AnAutoIncValue: integer);
 var i : integer;
+    s : AnsiString;
 begin
-  Stream.Write(FpcBinaryIdent2[1], length(FpcBinaryIdent2));
+  S:=FpcBinaryIdent2;
+  Stream.Write(S[1], length(S));
   Stream.WriteByte(FVersion);
 
   Stream.WriteWord(DataSet.FieldDefs.Count);
@@ -4450,7 +4453,7 @@ begin
     case FVersion of
       10:
         Stream.ReadBuffer(GetCurrentBuffer^, FRecordSize);  // Ugly because private members of ADataset are used...
-      20:
+      20, 30:
         begin
         // Restore field's Null bitmap
         Stream.ReadBuffer(FNullBitmap[0], FNullBitmapSize);
@@ -4458,11 +4461,19 @@ begin
         for i:=0 to FieldDefs.Count-1 do
           begin
           AField := Fields.FieldByNumber(FieldDefs[i].FieldNo);
+          // This is actually wrong, because if there is data in the stream, we must read it.
           if AField=nil then continue;
           if GetFieldIsNull(PByte(FNullBitmap), i) then
             AField.SetData(nil)
-          else if AField.DataType in StringFieldTypes then
-            AField.AsString := Stream.ReadAnsiString
+          else if AField.DataType in AnsiStringFieldTypes then
+            AField.AsAnsiString := Stream.ReadAnsiString
+          else if AField.DataType in UnicodeStringFieldTypes then
+            begin
+            if FVersion=20 then
+              AField.AsUnicodeString := Stream.ReadAnsiString
+            else
+              AField.AsUnicodeString := Stream.ReadUnicodeString
+            end
           else
             begin
             if AField.DataType in VarLenFieldTypes then
@@ -4474,6 +4485,8 @@ begin
               Stream.ReadBuffer(B[0], L);
             if AField.DataType in BlobFieldTypes then
               RestoreBlobField(AField, @B[0], L)
+            else if aField.DataType=ftVarBytes then
+              aField.AsBytes:=B // Treats data specially, so we set bytes
             else
               AField.SetData(@B[0], False);  // set it to the FilterBuffer
             end;
@@ -4500,7 +4513,7 @@ begin
     case FVersion of
       10:
         Stream.WriteBuffer(GetCurrentBuffer^, FRecordSize); // Old 1.0 version
-      20:
+      20,30:
         begin
         // store fields Null bitmap
         FillByte(FNullBitmap[0], FNullBitmapSize, 0);
@@ -4516,8 +4529,10 @@ begin
           begin
           AField := Fields.FieldByNumber(FieldDefs[i].FieldNo);
           if not assigned(AField) or AField.IsNull then continue;
-          if AField.DataType in StringFieldTypes then
-            Stream.WriteAnsiString(AField.AsString)
+          if AField.DataType in AnsiStringFieldTypes then
+            Stream.WriteAnsiString(AField.AsAnsiString)
+          else if AField.DataType in UnicodeStringFieldTypes then
+            Stream.WriteUnicodeString(AField.AsUnicodeString)
           else
             begin
             B := AField.AsBytes;
@@ -4538,7 +4553,7 @@ begin
 end;
 
 class function TFpcBinaryDatapacketHandler.RecognizeStream(AStream: TStream): boolean;
-var s : string;
+var s : ansistring;
 begin
   SetLength(s, 13);
   if (AStream.Read(s[1], 13) = 13) then

+ 22 - 20
packages/fcl-db/src/base/bufdataset_parser.pp

@@ -15,8 +15,8 @@ unit bufdataset_parser;
 
  **********************************************************************}
 
-{$h+}
 {$mode delphi}
+{$h+}
 
 
 interface
@@ -41,12 +41,12 @@ type
     FPartialMatch: boolean;
 
   protected
-    FCurrentExpression: string;
+    FCurrentExpression: AnsiString;
 
     procedure FillExpressList; override;
-    procedure HandleUnknownVariable(VarName: string); override;
-    function  GetVariableInfo(const VarName: string): TField;
-    function  CurrentExpression: string; override;
+    procedure HandleUnknownVariable(VarName: AnsiString); override;
+    function  GetVariableInfo(const VarName: AnsiString): TField;
+    function  CurrentExpression: AnsiString; override;
     function  GetResultType: TExpressionType; override;
 
     procedure SetCaseInsensitive(NewInsensitive: Boolean);
@@ -57,11 +57,11 @@ type
 
     procedure ClearExpressions; override;
 
-    procedure ParseExpression(const AExpression: string); virtual;
-    function ExtractFromBuffer(Buffer: TRecordBuffer): PChar; virtual;
+    procedure ParseExpression(const AExpression: AnsiString); virtual;
+    function ExtractFromBuffer(Buffer: TRecordBuffer): PAnsiChar; virtual;
 
     property Dataset: TDataSet read FDataset; // write FDataset;
-    property Expression: string read FCurrentExpression;
+    property Expression: AnsiString read FCurrentExpression;
     property ResultLen: Integer read FResultLen;
 
     property CaseInsensitive: Boolean read FCaseInsensitive write SetCaseInsensitive;
@@ -79,7 +79,7 @@ type
   TFieldVar = class(TObject)
   private
     FField: TField;
-    FFieldName: string;
+    FFieldName: AnsiString;
     FFieldIsNull: boolean;
     FExprWord: TExprWord;
   protected
@@ -94,13 +94,13 @@ type
     property FieldVal: Pointer read GetFieldVal;
     property FieldDef: TField read FField;
     property FieldType: TExpressionType read GetFieldType;
-    property FieldName: string read FFieldName;
+    property FieldName: AnsiString read FFieldName;
     property FieldIsNull: PBoolean read GetFieldIsNull;
   end;
 
   TStringFieldVar = class(TFieldVar)
   protected
-    FFieldVal: PChar;
+    FFieldVal: PAnsiChar;
 
     function GetFieldVal: Pointer; override;
     function GetFieldType: TExpressionType; override;
@@ -366,7 +366,7 @@ end;
 
 procedure TBufDatasetParser.FillExpressList;
 var
-  lExpression: string;
+  lExpression: AnsiString;
 begin
   lExpression := FCurrentExpression;
   ClearExpressions;
@@ -394,17 +394,18 @@ begin
     ParseExpression(lExpression);
 end;
 
-function TBufDatasetParser.GetVariableInfo(const VarName: string): TField;
+function TBufDatasetParser.GetVariableInfo(const VarName: AnsiString): TField;
+
 begin
   Result := FDataset.FindField(VarName);
 end;
 
-function TBufDatasetParser.CurrentExpression: string;
+function TBufDatasetParser.CurrentExpression: AnsiString;
 begin
   Result := FCurrentExpression;
 end;
 
-procedure TBufDatasetParser.HandleUnknownVariable(VarName: string);
+procedure TBufDatasetParser.HandleUnknownVariable(VarName: AnsiString);
 var
   FieldInfo: TField;
   TempFieldVar: TFieldVar;
@@ -483,7 +484,8 @@ begin
   FCurrentExpression := EmptyStr;
 end;
 
-procedure TBufDatasetParser.ParseExpression(const AExpression: string);
+procedure TBufDatasetParser.ParseExpression(const AExpression: AnsiString);
+
 var
   TempBuffer: TRecordBuffer;
 begin
@@ -497,7 +499,7 @@ begin
     // parse requested
     CompileExpression(AExpression);
 
-    // determine length of string length expressions
+    // determine length of AnsiString length expressions
     if ResultType = etString then
     begin
       // make empty record
@@ -534,7 +536,7 @@ begin
   FCurrentExpression := AExpression;
 end;
 
-function TBufDatasetParser.ExtractFromBuffer(Buffer: TRecordBuffer): PChar;
+function TBufDatasetParser.ExtractFromBuffer(Buffer: TRecordBuffer): PAnsiChar;
 var
   I: Integer;
 begin
@@ -551,9 +553,9 @@ begin
   end else begin
     // simple field, get field result
     Result := TFieldVar(FFieldVarList.Objects[0]).FieldVal;
-    // if string then dereference
+    // if AnsiString then dereference
     if FFieldType = etString then
-      Result := PPChar(Result)^;
+      Result := PPAnsiChar(Result)^;
   end;
 end;
 

+ 6 - 6
packages/fcl-db/src/base/dataset.inc

@@ -585,8 +585,8 @@ function TDataSet.GetFieldData(Field: TField; Buffer: Pointer;
   NativeFormat: Boolean): Boolean;
 
 Var
-  AStatBuffer : Array[0..dsMaxStringSize] of Char;
-  ADynBuffer : pchar;
+  AStatBuffer : Array[0..dsMaxStringSize] of AnsiChar;
+  ADynBuffer : PAnsiChar;
 
 begin
   If NativeFormat then
@@ -663,8 +663,8 @@ procedure TDataSet.SetFieldData(Field: TField; Buffer: Pointer;
   NativeFormat: Boolean);
 
 Var
-  AStatBuffer : Array[0..dsMaxStringSize] of Char;
-  ADynBuffer : pchar;
+  AStatBuffer : Array[0..dsMaxStringSize] of AnsiChar;
+  ADynBuffer : PAnsiChar;
 
 begin
   if NativeFormat then
@@ -729,7 +729,7 @@ begin
       end
     else
       begin
-      ExtractStrings([';'],[' '],pchar(result[i].Fields),Indexfields);
+      ExtractStrings([';'],[' '],PAnsiChar(result[i].Fields),Indexfields);
       for f := 0 to IndexFields.Count-1 do if FindField(Indexfields[f]) = nil then
         begin
         result.Delete(i);
@@ -2211,7 +2211,7 @@ begin
     Fields[I].AssignValue(Values[I]);
 end;
 
-function TDataSet.Translate(Src, Dest: PChar; ToOem: Boolean): Integer;
+function TDataSet.Translate(Src, Dest: PAnsiChar; ToOem: Boolean): Integer;
 
 begin
   strcopy(dest,src);

+ 12 - 8
packages/fcl-db/src/base/db.pas

@@ -31,7 +31,7 @@ const
 
   // Used in AsBoolean for string fields to determine
   // whether it's true or false.
-  YesNoChars : Array[Boolean] of char = ('N', 'Y');
+  YesNoChars : Array[Boolean] of AnsiChar = ('N', 'Y');
 
   SQLDelimiterCharacters = [';',',',' ','(',')',#13,#10,#9];
 
@@ -254,7 +254,7 @@ type
     DisplayText: Boolean) of object;
   TFieldSetTextEvent = procedure(Sender: TField; const aText: string) of object;
   TFieldRef = ^TField;
-  TFieldChars = set of Char;
+  TFieldChars = set of AnsiChar;
 
   PLookupListRec = ^TLookupListRec;
   TLookupListRec = record
@@ -416,7 +416,7 @@ type
     function GetData(Buffer: Pointer): Boolean; overload;
     function GetData(Buffer: Pointer; NativeFormat : Boolean): Boolean; overload;
     class function IsBlob: Boolean; virtual;
-    function IsValidChar(InputChar: Char): Boolean; virtual;
+    function IsValidChar(InputChar: AnsiChar): Boolean; virtual;
     procedure RefreshLookupList;
     procedure SetData(Buffer: Pointer); overload;
     procedure SetData(Buffer: Pointer; NativeFormat : Boolean); overload;
@@ -938,11 +938,15 @@ type
   protected
     class procedure CheckTypeSize(AValue: Longint); override;
     function GetAsBytes: TBytes; override;
-    function GetAsString: string; override;
+    function GetAsUnicodeString: Unicodestring; override;
+    function GetAsAnsiString: Ansistring; override;
     function GetAsVariant: Variant; override;
     function GetValue(var AValue: TBytes): Boolean;
+    function GetAsString : String; override;
+    Procedure SetAsString(const S : String); override;
     procedure SetAsBytes(const AValue: TBytes); override;
-    procedure SetAsString(const AValue: string); override;
+    procedure SetAsAnsiString(const AValue: ansistring); override;
+    procedure SetAsUnicodeString(const AValue: unicodestring); override;
     procedure SetVarValue(const AValue: Variant); override;
   public
     constructor Create(AOwner: TComponent); override;
@@ -1558,12 +1562,12 @@ type
   PBookmarkFlag = ^TBookmarkFlag;
   TBookmarkFlag = (bfCurrent, bfBOF, bfEOF, bfInserted);
 
-{ These types are used by Delphi/Unicode to replace the ambiguous "pchar" buffer types.
+{ These types are used by Delphi/Unicode to replace the ambiguous "PAnsiChar" buffer types.
   For now, they are just aliases to PAnsiChar, but in Delphi/Unicode it is pbyte. This will
   be changed later (2.8?), to allow a grace period for descendents to catch up.
   
   Testing with TRecordBuffer=PByte will turn up typing problems. TRecordBuffer=pansichar is backwards
-  compatible, even if overriden with "pchar" variants.
+  compatible, even if overriden with "PAnsiChar" variants.
 }
   TRecordBufferBaseType = AnsiChar; // must match TRecordBuffer. 
   TRecordBuffer = PAnsiChar;
@@ -1926,7 +1930,7 @@ type
     procedure Refresh;
     procedure Resync(Mode: TResyncMode); virtual;
     procedure SetFields(const Values: array of const);
-    function  Translate(Src, Dest: PChar; ToOem: Boolean): Integer; virtual;
+    function  Translate(Src, Dest: PAnsiChar; ToOem: Boolean): Integer; virtual;
     procedure UpdateCursorPos;
     procedure UpdateRecord;
     function UpdateStatus: TUpdateStatus; virtual;

+ 3 - 0
packages/fcl-db/src/base/dbcoll.pp

@@ -15,6 +15,9 @@
  **********************************************************************}
 unit DBColl;
 
+{$mode objfpc}
+{$H+}
+
 interface
 
 uses db, classes, sysutils, fieldmap;

+ 10 - 10
packages/fcl-db/src/base/dsparams.inc

@@ -14,7 +14,7 @@
 
  **********************************************************************}
 
-procedure SkipQuotesString(var p : pchar; QuoteChar : char; EscapeSlash, EscapeRepeat : Boolean);
+procedure SkipQuotesString(var p : PChar; QuoteChar : Char; EscapeSlash, EscapeRepeat : Boolean);
 var notRepeatEscaped : boolean;
 begin
   Inc(p);
@@ -355,7 +355,7 @@ var
   NewQueryLength:integer;
   NewQuery:string;
   NewQueryIndex,BufIndex,CopyLen,i:integer;    // Parambinding will have length ParamCount in the end
-  ParamDelim : Set of char;
+  ParamDelim : Set of Char;
   b:integer;
   tmpParam:TParam;
 
@@ -489,7 +489,7 @@ begin
     for i:=0 to High(ParamPart) do
     begin
       CopyLen:=ParamPart[i].Start-BufIndex;
-      System.Move(SQL[BufIndex],NewQuery[NewQueryIndex],CopyLen);
+      System.Move(SQL[BufIndex],NewQuery[NewQueryIndex],CopyLen*SizeOf(Char));
       Inc(NewQueryIndex,CopyLen);
       case ParameterStyle of
         psInterbase : begin
@@ -515,7 +515,7 @@ begin
     end;
     CopyLen:=Length(SQL)+1-BufIndex;
     if CopyLen > 0 then
-      System.Move(SQL[BufIndex],NewQuery[NewQueryIndex],CopyLen);
+      System.Move(SQL[BufIndex],NewQuery[NewQueryIndex],CopyLen*SizeOf(Char));
   end
   else
     NewQuery:=SQL;
@@ -1149,15 +1149,15 @@ begin
     ftAdt,
     ftFixedChar:
       begin
-      S:=AsString;
-      StrMove(PChar(Buffer),PChar(S),Length(S)+1);
+      S:=AsAnsiString;
+      StrMove(PAnsiChar(Buffer),PAnsiChar(S),Length(S)+1);
       end;
     ftWideString,
     ftWideMemo: begin
       ws := GetAsWideString;
       l := Length(ws);
       if l > 0 then
-        Move(ws[1], Buffer, Succ(l)*2)
+        Move(ws[1], Buffer^, Succ(l)*2)
       else
         PWideChar(Buffer)^ := #0
     end;
@@ -1169,8 +1169,8 @@ begin
     ftOraBlob,
     ftOraClob  :
       begin
-      S:=GetAsString;
-      Move(PChar(S)^, Buffer^, Length(S));
+      S:=GetAsAnsiString;
+      Move(PAnsiChar(S)^, Buffer^, Length(S));
       end;
     ftBytes, ftVarBytes:
       begin
@@ -1313,7 +1313,7 @@ begin
     ftBlob,
     ftGraphic..ftTypedBinary,
     ftOraBlob,
-    ftOraClob  : SetBlobData(Buffer, StrLen(PChar(Buffer)));
+    ftOraClob  : SetBlobData(Buffer, StrLen(PAnsiChar(Buffer)));
     ftFmtBCD   : AsFMTBCD:=PBCD(Buffer)^;
     ftShortInt : AsShortInt:=PShortInt(Buffer)^;
     ftByte     : AsByte:=PByte(Buffer)^;

+ 2 - 2
packages/fcl-db/src/base/fieldmap.pp

@@ -46,7 +46,7 @@ type
     Procedure LoadObject(AObject : TObject); virtual;
     Function GetFromField(F : TField; ADefault : TBCD) : TBCD; overload;
     Function GetFromField(F : TField; ADefault : Integer) : Integer; overload;
-    Function GetFromField(F : TField; const ADefault : String) : String; overload;
+    Function GetFromField(F : TField; const ADefault : AnsiString) : AnsiString; overload;
     Function GetFromField(F : TField; ADefault : Boolean) : Boolean; overload;
     Function GetFromDateTimeField(F : TField; ADefault : TDateTime) : TDateTime; overload;
     Function GetFromField(F : TField; ADefault : Double) : Double; overload;
@@ -553,7 +553,7 @@ begin
     Result:=ADefault;
 end;
 
-function TFieldMap.GetFromField(F: TField; const ADefault: String): String;
+function TFieldMap.GetFromField(F: TField; const ADefault: AnsiString): AnsiString;
 begin
   If Assigned(F) then
     Result:=F.AsString

+ 89 - 28
packages/fcl-db/src/base/fields.inc

@@ -613,7 +613,11 @@ end;
 
 function TField.GetAsUTF8String: UTF8String;
 begin
-  Result := GetAsString;
+{$IF SIZEOF(CHAR)=2}
+  Result := UTF8Encode(GetAsUnicodeString);
+{$ELSE}
+  Result := GetAsAnsiString;
+{$ENDIF}
 end;
 
 function TField.GetAsWideString: WideString;
@@ -829,7 +833,7 @@ begin
   HasParent:=True;
 end;
 
-function TField.IsValidChar(InputChar: Char): Boolean;
+function TField.IsValidChar(InputChar: AnsiChar): Boolean;
 
 begin
   // FValidChars must be set in Create.
@@ -1250,7 +1254,8 @@ end;
 
 function TStringField.GetAsString: String;
 begin
-{$IFDEF UNICODE}
+{$IF SIZEOF(Char)=2}
+  // Not GetAsWideString, because in TStringField AsWideString calls GetAsString
   Result := GetAsAnsiString;
 {$ELSE}
   if GetValue(RawByteString(Result)) then
@@ -1316,12 +1321,13 @@ function TStringField.GetValue(out AValue: RawByteString): Boolean;
 
 var Buf, TBuf : TStringFieldBuffer;
     DynBuf, TDynBuf : Array of AnsiChar;
-
+    DS : Integer;
 begin
-  if DataSize <= dsMaxStringSize then
+  DS:=DataSize;
+  if DS <= dsMaxStringSize then
     begin
     Result:=GetData(@Buf);
-    Buf[DataSize-1]:=#0;  //limit string to Size
+    Buf[DS-1]:=#0;  //limit string to Size
     If Result then
       begin
       if Transliterate then
@@ -1335,14 +1341,14 @@ begin
     end
   else
     begin
-    SetLength(DynBuf,DataSize);
+    SetLength(DynBuf,DS);
     Result:=GetData(@DynBuf[0]);
-    DynBuf[DataSize-1]:=#0;  //limit string to Size
+    DynBuf[DS-1]:=#0;  //limit string to Size
     If Result then
       begin
       if Transliterate then
         begin
-        SetLength(TDynBuf,DataSize);
+        SetLength(TDynBuf,DS);
         DataSet.Translate(@DynBuf[0],@TDynBuf[0],False);
         AValue:=PAnsiChar(TDynBuf);
         end
@@ -1394,7 +1400,10 @@ end;
 procedure TStringField.SetValue(AValue: RawByteString);
 var Buf      : TStringFieldBuffer;
     DynBuf   : array of AnsiChar;
+    DS : Integer;
+
 begin
+  DS:=DataSize;
   if AValue='' then
     begin
     Buf := #0;
@@ -1404,16 +1413,16 @@ begin
     begin
     if StringCodePage(AValue) <> FCodePage then
       SetCodePage(AValue, FCodePage, FCodePage<>CP_NONE);
-    if DataSize <= dsMaxStringSize then
+    if DS <= dsMaxStringSize then
       begin
       if FTransliterate then
         DataSet.Translate(@AValue[1],Buf,True)
       else
         // The data is copied into the buffer, since some TDataset descendents copy
         // the whole buffer-length in SetData. (See bug 8477)
-        StrPLCopy(PAnsiChar(Buf), AValue, DataSize-1);
+        StrPLCopy(PAnsiChar(@Buf), AValue, DS-1);
       // If length(AValue) > Size the buffer isn't terminated properly ?
-      Buf[DataSize-1] := #0;
+      Buf[DS-1] := #0;
       SetData(@Buf);
       end
     else
@@ -1422,7 +1431,7 @@ begin
       if FTransliterate then
         DataSet.Translate(@AValue[1],@DynBuf[0],True)
       else
-        StrPLCopy(PAnsiChar(DynBuf), AValue, DataSize-1);
+        StrPLCopy(PAnsiChar(DynBuf), AValue, DS-1);
       SetData(@DynBuf[0]);
       end;
     end;
@@ -1430,7 +1439,7 @@ end;
 
 procedure TStringField.SetAsString(const AValue: String);
 begin
-{$IFDEF UNICODE}
+{$IF SIZEOF(CHAR)=2}
   SetAsAnsiString(AValue);
 {$ELSE}
   SetValue(AValue);
@@ -1501,7 +1510,7 @@ end;
 
 function TWideStringField.GetAsString: string;
 begin
-{$IFDEF UNICODE}
+{$IF SIZEOF(CHAR)=2}
   if not GetValue(Result) then
     Result := '';
 {$ELSE}
@@ -3016,14 +3025,30 @@ begin
     SetLength(Result, 0);
 end;
 
+function TBinaryField.GetAsUnicodeString: Unicodestring;
+var
+  B: TBytes;
+  L : Integer;
+begin
+  if not GetValue(B) then
+    Result := ''
+  else
+    begin
+    L:=Length(B);
+    SetLength(Result,((L+1) div 2));
+    if L>0 then
+      Move(B[0],PWideChar(Result)^,L);
+    end;
+end;
+
 
-function TBinaryField.GetAsString: string;
+function TBinaryField.GetAsAnsiString: Ansistring;
 var B: TBytes;
 begin
   if not GetValue(B) then
     Result := ''
   else
-    SetString(Result, @B[0], length(B) div SizeOf(Char));
+    SetString(Result, @B[0], length(B) div SizeOf(AnsiChar));
 end;
 
 
@@ -3047,20 +3072,42 @@ end;
 
 
 function TBinaryField.GetValue(var AValue: TBytes): Boolean;
-var B: TBytes;
+var
+   B: TBytes;
+   Len : word;
 begin
   SetLength(B, DataSize);
   Result := assigned(B) and GetData(Pointer(B), True);
   if Result then
     if DataType = ftVarBytes then
       begin
-      SetLength(AValue, PWord(B)^);
-      Move(B[sizeof(Word)], AValue[0], Length(AValue));
+      Len:=PWord(B)^;
+      SetLength(AValue, Len);
+      if Len>0 then
+        Move(B[sizeof(Word)], AValue[0], Length(AValue));
       end
     else // ftBytes
       AValue := B;
 end;
 
+function TBinaryField.GetAsString: String;
+begin
+{$IF SIZEOF(CHAR)=2}
+  Result:=GetAsUnicodeString;
+{$ELSE}
+  Result:=GetAsAnsiString;
+{$ENDIF}
+end;
+
+procedure TBinaryField.SetAsString(Const S: String);
+begin
+{$IF SIZEOF(CHAR)=2}
+  SetAsUnicodeString(S);
+{$ELSE}
+  SetAsAnsiString(S);
+{$ENDIF}
+end;
+
 
 procedure TBinaryField.SetAsBytes(const AValue: TBytes);
 var Buf: array[0..dsMaxStringSize] of byte;
@@ -3078,10 +3125,10 @@ begin
       SetLength(DynBuf, DataSize);
       P := @DynBuf[0];
     end;
-
     if DataType = ftVarBytes then begin
       PWord(P)^ := Len;
-      Move(AValue[0], P[sizeof(Word)], Len);
+      if Len>0 then
+        Move(AValue[0], P[sizeof(Word)], Len);
     end
     else begin // ftBytes
       Move(AValue[0], P^, Len);
@@ -3092,19 +3139,33 @@ begin
 end;
 
 
-procedure TBinaryField.SetAsString(const AValue: string);
+procedure TBinaryField.SetAsAnsiString(const AValue: ansistring);
 var B : TBytes;
 begin
   If Length(AValue) = DataSize then
-    SetData(PChar(AValue))
+    SetData(PAnsiChar(AValue))
   else
   begin
-    SetLength(B, Length(AValue) * SizeOf(Char));
+    SetLength(B, Length(AValue) * SizeOf(AnsiChar));
     Move(AValue[1], B[0], Length(B));
     SetAsBytes(B);
   end;
 end;
 
+procedure TBinaryField.SetAsUnicodeString(const AValue: unicodestring);
+
+Var
+  B : TBytes;
+  Len: Integer;
+
+begin
+  B:=TEncoding.Unicode.GetBytes(aValue);
+  Len:=Length(B);
+  if Len>Size then
+    B:=Copy(B,0,Size);
+  SetAsBytes(B);
+end;
+
 
 procedure TBinaryField.SetVarValue(const AValue: Variant);
 var P: Pointer;
@@ -3588,7 +3649,7 @@ end;
 
 function TBlobField.GetAsString: string;
 begin
-{$IFDEF UNICODE}
+{$IF SIZEOF(CHAR)=2}
   Result := GetAsUnicodeString;
 {$ELSE}
   Result := GetAsAnsiString;
@@ -3650,7 +3711,7 @@ end;
 function TBlobField.GetAsVariant: Variant;
 begin
   if not GetIsNull then
-    Result := GetAsString
+    Result := GetAsAnsiString
   else
     Result := Null;
 end;
@@ -3710,7 +3771,7 @@ end;
 
 procedure TBlobField.SetAsString(const AValue: string);
 begin
-{$IFDEF UNICODE}
+{$IF SIZEOF(CHAR)=2}
   SetAsUnicodeString(AValue);
 {$ELSE}
   SetAsAnsiString(AValue);

+ 4 - 1
packages/fcl-db/src/base/sqltypes.pp

@@ -15,6 +15,9 @@
  **********************************************************************}
 unit SQLTypes;
 
+{$mode objfpc}
+{$H+}
+
 interface
 
 uses classes, sysutils;
@@ -31,7 +34,7 @@ type
   TDBEventType = (detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack, detParamValue, detActualSQL);
   TDBEventTypes = set of TDBEventType;
 
-  TQuoteChars = array[0..1] of char;
+  TQuoteChars = array[0..1] of AnsiChar;
 
   TSqlObjectIdentifierList = class;
 

+ 1 - 1
packages/fcl-db/src/base/xmldatapacketreader.pp

@@ -420,7 +420,7 @@ end;
 
 class function TXMLDatapacketReader.RecognizeStream(AStream: TStream): boolean;
 const XmlStart = '<?xml';
-var s        : string;
+var s        : ansistring;
     len      : integer;
 begin
   Len := length(XmlStart);

+ 8 - 6
packages/fcl-db/src/datadict/fpdatadict.pp

@@ -754,12 +754,6 @@ Resourcestring
   SErrGetTableIndexDefsNotSupported = 'Getting index definitions of a table is not supported by the "%s" engine.';
   SSavingFieldsFrom           = 'Saving fields from %s';
   SLoadingFieldsFrom          = 'Loading fields from %s';
-  SIndexOptionPrimary         = 'Primary key';
-  SIndexOptionUnique          = 'Unique';
-  SIndexOptionDescending      = 'Descending';
-  SIndexOptionCaseInsensitive = 'Case insensitive';
-  SIndexOptionExpression      = 'Expression';
-  SIndexOptionNonMaintained   = 'Not maintained';
   SWarnFieldNotFound          = 'Could not find field "%s".';
   SLogFieldFoundIn            = 'Field "%s" found in table "%s".';
   SErrSequenceNotFound        = 'Sequence "%s" not found.';
@@ -768,6 +762,14 @@ Resourcestring
   SErrDomainNotFound          = 'Domain "%s" not found.';
   SErrNoDataDict              = '%s : No data dictionary available';
   SErrResolveDomain           = 'Cannot resolve domain';
+  
+Const
+  SIndexOptionPrimary         = 'Primary key';
+  SIndexOptionUnique          = 'Unique';
+  SIndexOptionDescending      = 'Descending';
+  SIndexOptionCaseInsensitive = 'Case insensitive';
+  SIndexOptionExpression      = 'Expression';
+  SIndexOptionNonMaintained   = 'Not maintained';
 
 Const
   IndexOptionNames : Array [TIndexOption] of String

+ 37 - 37
packages/fcl-db/src/dbase/dbf.pas

@@ -16,10 +16,10 @@ unit dbf;
  **********************************************************************}
 { design info in dbf_reg.pas }
 
-interface
-
 {$I dbf_common.inc}
 
+interface
+
 uses
   Classes,
   Db,
@@ -50,7 +50,7 @@ type
     BookmarkData: TBookmarkData;
     BookmarkFlag: TBookmarkFlag;
     SequentialRecNo: Integer;
-    DeletedFlag: Char;
+    DeletedFlag: AnsiChar;
   end;
 //====================================================================
   TDbf = class;
@@ -64,7 +64,7 @@ type
   TDbfFileNames = set of TDbfFileName;
 //====================================================================
   TCompareRecordEvent = procedure(Dbf: TDbf; var Accept: Boolean) of object;
-  TTranslateEvent = function(Dbf: TDbf; Src, Dest: PChar; ToOem: Boolean): Integer of object;
+  TTranslateEvent = function(Dbf: TDbf; Src, Dest: PAnsiChar; ToOem: Boolean): Integer of object;
   TLanguageWarningEvent = procedure(Dbf: TDbf; var Action: TDbfLanguageAction) of object;
   TConvertFieldEvent = procedure(Dbf: TDbf; DstField, SrcField: TField) of object;
   TBeforeAutoCreateEvent = procedure(Dbf: TDbf; var DoCreate: Boolean) of object;
@@ -246,8 +246,8 @@ type
     procedure ParseFilter(const AFilter: string);
     function  GetDbfFieldDefs: TDbfFieldDefs;
     function  ReadCurrentRecord(Buffer: TRecordBuffer; var Acceptable: Boolean): TGetResult;
-    function  SearchKeyBuffer(Buffer: PChar; SearchType: TSearchKeyType): Boolean;
-    procedure SetRangeBuffer(LowRange: PChar; HighRange: PChar);
+    function  SearchKeyBuffer(Buffer: PAnsiChar; SearchType: TSearchKeyType): Boolean;
+    procedure SetRangeBuffer(LowRange: PAnsiChar; HighRange: PAnsiChar);
 
   protected
     function GetDefaultBufferCount : Cardinal; override;
@@ -320,9 +320,9 @@ type
     procedure Resync(Mode: TResyncMode); override;
     function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; override; {virtual}
 {$ifdef SUPPORT_NEW_TRANSLATE}
-    function Translate(Src, Dest: PChar; ToOem: Boolean): Integer; override; {virtual}
+    function Translate(Src, Dest: PAnsiChar; ToOem: Boolean): Integer; override; {virtual}
 {$else}
-    procedure Translate(Src, Dest: PChar; ToOem: Boolean); override; {virtual}
+    procedure Translate(Src, Dest: PAnsiChar; ToOem: Boolean); override; {virtual}
 {$endif}
 
 {$ifdef SUPPORT_OVERLOAD}
@@ -364,13 +364,13 @@ type
     procedure SetRange(LowRange: Variant; HighRange: Variant; KeyIsANSI: boolean
       {$ifdef SUPPORT_DEFAULT_PARAMS}= false{$endif});
 {$endif}
-    function  PrepareKey(Buffer: Pointer; BufferType: TExpressionType): PChar;
-    function  SearchKeyPChar(Key: PChar; SearchType: TSearchKeyType; KeyIsANSI: boolean
+    function  PrepareKey(Buffer: Pointer; BufferType: TExpressionType): PAnsiChar;
+    function  SearchKeyPChar(Key: PAnsiChar; SearchType: TSearchKeyType; KeyIsANSI: boolean
       {$ifdef SUPPORT_DEFAULT_PARAMS}= false{$endif}): Boolean;
-    procedure SetRangePChar(LowRange: PChar; HighRange: PChar; KeyIsANSI: boolean
+    procedure SetRangePChar(LowRange: PAnsiChar; HighRange: PAnsiChar; KeyIsANSI: boolean
       {$ifdef SUPPORT_DEFAULT_PARAMS}= false{$endif});
     function  GetCurrentBuffer: TRecordBuffer;
-    procedure ExtractKey(KeyBuffer: PChar);
+    procedure ExtractKey(KeyBuffer: PAnsiChar);
     procedure UpdateIndexDefs; override;
     procedure GetFileNames(Strings: TStrings; Files: TDbfFileNames); {$ifdef SUPPORT_DEFAULT_PARAMS} overload; {$endif}
 {$ifdef SUPPORT_DEFAULT_PARAMS}
@@ -630,8 +630,8 @@ end;
 procedure TDbfBlobStream.Translate(ToOem: Boolean);
 var
   bytesToDo, numBytes: Integer;
-  bufPos: PChar;
-  saveChar: Char;
+  bufPos: PAnsiChar;
+  saveChar: AnsiChar;
 begin
   if (Transliterate) and (Size > 0) then
   begin
@@ -650,7 +650,7 @@ begin
       bufPos[numBytes] := #0;
       // translate memory
       TDbf(FBlobField.DataSet).Translate(bufPos, bufPos, ToOem);
-      // restore char
+      // restore AnsiChar
       bufPos[numBytes] := saveChar;
       // numBytes bytes translated
       Dec(bytesToDo, numBytes);
@@ -802,7 +802,7 @@ begin
   begin
     Result := FDbfFile.GetFieldData(Field.FieldNo-1, Field.DataType, Src, Buffer, NativeFormat);
   end else begin { weird calculated fields voodoo (from dbtables).... }
-    Inc(PChar(Src), Field.Offset + GetRecordSize);
+    Inc(PAnsiChar(Src), Field.Offset + GetRecordSize);
     Result := Boolean(Src[0]);
     if Result and (Buffer <> nil) then
       Move(Src[1], Buffer^, Field.DataSize);
@@ -847,7 +847,7 @@ const
   NativeFormat = true;
 {$endif}
 var
-  Dst: PChar;
+  Dst: PAnsiChar;
 begin
   if (Field.FieldNo >= 0) then
   begin
@@ -857,7 +857,7 @@ begin
     FDbfFile.SetFieldData(Field.FieldNo - 1, Field.DataType, Buffer, Dst, NativeFormat);
   end else begin    { ***** fkCalculated, fkLookup ***** }
     Dst := @PDbfRecord(CalcBuffer)^.DeletedFlag;
-    Inc(PChar(Dst), RecordSize + Field.Offset);
+    Inc(PAnsiChar(Dst), RecordSize + Field.Offset);
     Boolean(Dst[0]) := Buffer <> nil;
     if Buffer <> nil then
       Move(Buffer^, Dst[1], Field.DataSize)
@@ -876,7 +876,7 @@ begin
     Acceptable := Boolean((FParser.ExtractFromBuffer(GetCurrentBuffer))^);
 {$else}
     // strange problem
-    // dbf.pas(716,19) Error: Incompatible types: got "CHAR" expected "BOOLEAN"
+    // dbf.pas(716,19) Error: Incompatible types: got "AnsiChar" expected "BOOLEAN"
     Acceptable := not ((FParser.ExtractFromBuffer(GetCurrentBuffer))^ = #0);
 {$endif}
   end;
@@ -1532,7 +1532,7 @@ var
   I: Integer;
   TempDef: TDbfFieldDef;
 
-    function FieldTypeStr(const FieldType: char): string;
+    function FieldTypeStr(const FieldType: AnsiChar): string;
     begin
       if FieldType = #0 then
         Result := 'NULL'
@@ -1979,7 +1979,7 @@ function TDbf.LocateRecordIndex(const KeyFields: String; const KeyValues: Varian
 var
   searchFlag: TSearchKeyType;
   matchRes: Integer;
-  lTempBuffer: array [0..100] of Char;
+  lTempBuffer: array [0..100] of AnsiChar;
   acceptable, checkmatch: boolean;
 begin
   // Only honor loPartialKey for string types; for others, search for equal
@@ -2158,7 +2158,7 @@ end;
 
 {$ifdef SUPPORT_NEW_TRANSLATE}
 
-function TDbf.Translate(Src, Dest: PChar; ToOem: Boolean): Integer; {override virtual}
+function TDbf.Translate(Src, Dest: PAnsiChar; ToOem: Boolean): Integer; {override virtual}
 var
   FromCP, ToCP: Cardinal;
 begin
@@ -2192,7 +2192,7 @@ end;
 
 {$else}
 
-procedure TDbf.Translate(Src, Dest: PChar; ToOem: Boolean); {override virtual}
+procedure TDbf.Translate(Src, Dest: PAnsiChar; ToOem: Boolean); {override virtual}
 var
   FromCP, ToCP: Cardinal;
 begin
@@ -2222,7 +2222,7 @@ end;
 
 procedure TDbf.ClearCalcFields(Buffer: TRecordBuffer);
 var
-  lRealBuffer, lCalcBuffer: PChar;
+  lRealBuffer, lCalcBuffer: PAnsiChar;
 begin
   lRealBuffer := @pDbfRecord(Buffer)^.DeletedFlag;
   lCalcBuffer := lRealBuffer + FDbfFile.RecordSize;
@@ -2816,7 +2816,7 @@ begin
   Refresh;
 end;
 
-procedure TDbf.SetRangeBuffer(LowRange: PChar; HighRange: PChar);
+procedure TDbf.SetRangeBuffer(LowRange: PAnsiChar; HighRange: PAnsiChar);
 begin
   if FIndexFile = nil then
     exit;
@@ -2831,7 +2831,7 @@ end;
 
 procedure TDbf.SetRange(LowRange: Variant; HighRange: Variant; KeyIsANSI: boolean);
 var
-  LowBuf, HighBuf: array[0..100] of Char;
+  LowBuf, HighBuf: array[0..100] of AnsiChar;
 begin
   if (FIndexFile = nil) or VarIsNull(LowRange) or VarIsNull(HighRange) then
     exit;
@@ -2846,10 +2846,10 @@ end;
 
 {$endif}
 
-procedure TDbf.SetRangePChar(LowRange: PChar; HighRange: PChar; KeyIsANSI: boolean);
+procedure TDbf.SetRangePChar(LowRange: PAnsiChar; HighRange: PAnsiChar; KeyIsANSI: boolean);
 var
-  LowBuf, HighBuf: array [0..100] of Char;
-  LowPtr, HighPtr: PChar;
+  LowBuf, HighBuf: array [0..100] of AnsiChar;
+  LowPtr, HighPtr: PAnsiChar;
 begin
   if FIndexFile = nil then
     exit;
@@ -2867,7 +2867,7 @@ begin
   SetRangeBuffer(LowPtr, HighPtr);
 end;
 
-procedure TDbf.ExtractKey(KeyBuffer: PChar);
+procedure TDbf.ExtractKey(KeyBuffer: PAnsiChar);
 begin
   if FIndexFile <> nil then
     StrCopy(FIndexFile.ExtractKeyFromBuffer(GetCurrentBuffer), KeyBuffer)
@@ -2887,7 +2887,7 @@ end;
 
 function TDbf.SearchKey(Key: Variant; SearchType: TSearchKeyType; KeyIsANSI: boolean): Boolean;
 var
-  TempBuffer: array [0..100] of Char;
+  TempBuffer: array [0..100] of AnsiChar;
 begin
   if (FIndexFile = nil) or VarIsNull(Key) then
   begin
@@ -2903,7 +2903,7 @@ end;
 
 {$endif}
 
-function  TDbf.PrepareKey(Buffer: Pointer; BufferType: TExpressionType): PChar;
+function  TDbf.PrepareKey(Buffer: Pointer; BufferType: TExpressionType): PAnsiChar;
 begin
   if FIndexFile = nil then
   begin
@@ -2914,9 +2914,9 @@ begin
   Result := TIndexCursor(FCursor).IndexFile.PrepareKey(Buffer, BufferType);
 end;
 
-function TDbf.SearchKeyPChar(Key: PChar; SearchType: TSearchKeyType; KeyIsANSI: boolean): Boolean;
+function TDbf.SearchKeyPChar(Key: PAnsiChar; SearchType: TSearchKeyType; KeyIsANSI: boolean): Boolean;
 var
-  StringBuf: array [0..100] of Char;
+  StringBuf: array [0..100] of AnsiChar;
 begin
   if FCursor = nil then
   begin
@@ -2932,7 +2932,7 @@ begin
   Result := SearchKeyBuffer(TIndexCursor(FCursor).CheckUserKey(Key, @StringBuf[0]), SearchType);
 end;
 
-function TDbf.SearchKeyBuffer(Buffer: PChar; SearchType: TSearchKeyType): Boolean;
+function TDbf.SearchKeyBuffer(Buffer: PAnsiChar; SearchType: TSearchKeyType): Boolean;
 var
   matchRes: Integer;
 begin
@@ -2987,7 +2987,7 @@ end;
 procedure TDbf.UpdateRange;
 var
   fieldsVal: TRecordBuffer;
-  tempBuffer: array[0..300] of char;
+  tempBuffer: array[0..300] of AnsiChar;
 begin
   fieldsVal := FMasterLink.FieldsVal;
   if (TDbf(FMasterLink.DataSet).DbfFile.UseCodePage <> FDbfFile.UseCodePage)
@@ -2998,7 +2998,7 @@ begin
     Translate(pansichar(fieldsVal), pansichar(fieldsVal), true);
   end;
   // preparekey, setrangebuffer and updatekeyfrom* are functions which arguments
-  // are not entirely classified in pchar<>trecordbuffer terms.
+  // are not entirely classified in PAnsiChar<>trecordbuffer terms.
   // so we typecast for now.
   fieldsVal := TRecordBuffer(TIndexCursor(FCursor).IndexFile.PrepareKey((fieldsVal), FMasterLink.Parser.ResultType));
   SetRangeBuffer(pansichar(fieldsVal), pansichar(fieldsVal)); 

+ 2 - 2
packages/fcl-db/src/dbase/dbf_collate.pas

@@ -43,7 +43,7 @@ const
 
 
 function GetCollationTable( DbfLangId :integer ) :PCollationTable;
-function DbfCompareString( CollationTable :PCollationTable; String1 :PChar; nLength1 :integer; String2 :PChar; nLength2 :integer ) :integer;
+function DbfCompareString( CollationTable :PCollationTable; String1 :PAnsiChar; nLength1 :integer; String2 :PAnsiChar; nLength2 :integer ) :integer;
 function RegisterCollation( DbfLangId :integer; CollationTable :PCollationTable; BDEName :TCollationBDEName ) :Boolean;
 
 
@@ -78,7 +78,7 @@ begin
     end;
 end;
 
-function DbfCompareString( CollationTable :PCollationTable; String1 :PChar; nLength1 :integer; String2 :PChar; nLength2 :integer ) :integer;
+function DbfCompareString( CollationTable :PCollationTable; String1 :PAnsiChar; nLength1 :integer; String2 :PAnsiChar; nLength2 :integer ) :integer;
 var
   nCnt, nMax, nVal1, nVal2 :integer;
 const

+ 3 - 1
packages/fcl-db/src/dbase/dbf_common.inc

@@ -213,10 +213,12 @@
 //--- Conclude supported features in FreePascal      ---
 //------------------------------------------------------
 
-{$ifdef FPC_VERSION}
+{$ifdef FPC}
 
   {$mode delphi}
+{$ifndef unicodertl}
   {$h+}
+{$ENDIF}
 
 {$ifndef CPUI386}
   {$undef USE_ASSEMBLER_486_UP}

+ 4 - 5
packages/fcl-db/src/dbase/dbf_common.pas

@@ -29,7 +29,7 @@ type
   EDbfError = class (EDatabaseError);
   EDbfWriteError = class (EDbfError);
 
-  TDbfFieldType = char;
+  TDbfFieldType = AnsiChar;
 
   TXBaseVersion   = (xUnknown, xClipper, xBaseIII, xBaseIV, xBaseV, xFoxPro, xBaseVII, xVisualFoxPro);
   TSearchKeyType = (stEqual, stGreaterEqual, stGreater);
@@ -46,7 +46,6 @@ type
   PSmallInt = ^SmallInt;
   PCardinal = ^Cardinal;
   PDouble = ^Double;
-  PString = ^String;
 
 {$ifdef DELPHI_3}
   dword = cardinal;
@@ -107,7 +106,7 @@ procedure SwapInt64LE(Value, Result: Pointer); register;
 {$endif}
 
 // Translate string between codepages
-function TranslateString(FromCP, ToCP: Cardinal; Src, Dest: PChar; Length: Integer): Integer;
+function TranslateString(FromCP, ToCP: Cardinal; Src, Dest: PAnsiChar; Length: Integer): Integer;
 
 // Returns a pointer to the first occurence of Chr in Str within the first Length characters
 // Does not stop at null (#0) terminator!
@@ -371,7 +370,7 @@ end;
 
 {$endif}
 
-function TranslateString(FromCP, ToCP: Cardinal; Src, Dest: PChar; Length: Integer): Integer;
+function TranslateString(FromCP, ToCP: Cardinal; Src, Dest: PAnsiChar; Length: Integer): Integer;
 var
   WideCharStr: array[0..1023] of WideChar;
   wideBytes: Cardinal;
@@ -416,7 +415,7 @@ function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer): Pointer;
 var
   I: Integer;
 begin
-  // Make sure we pass a buffer of bytes instead of a pchar otherwise
+  // Make sure we pass a buffer of bytes instead of a PAnsiChar otherwise
   // the call will always fail
   I := System.IndexByte(PByte(Buffer)^, Length, Chr);
   if I = -1 then

+ 87 - 87
packages/fcl-db/src/dbase/dbf_dbffile.pas

@@ -271,11 +271,11 @@ const
 // thanks to Bruno Depero from Italy
 // and Andreas W\F6llenstein from Denmark
 //====================================================================
-function DbfStrToFloat(const Src: PChar; const Size: Integer): Extended;
+function DbfStrToFloat(const Src: PAnsiChar; const Size: Integer): Extended;
 var
-  iPos: PChar;
+  iPos: PAnsiChar;
   eValue: extended;
-  endChar: Char;
+  endChar: AnsiChar;
 begin
   // temp null-term string
   endChar := (Src + Size)^;
@@ -298,15 +298,15 @@ begin
   // restore dec sep
   if iPos <> nil then
     iPos^ := sDBF_DEC_SEP;
-  // restore Char of null-term
+  // restore AnsiChar of null-term
   (Src + Size)^ := endChar;
 end;
 
-procedure FloatToDbfStr(const Val: Extended; const Size, Precision: Integer; const Dest: PChar);
+procedure FloatToDbfStr(const Val: Extended; const Size, Precision: Integer; const Dest: PAnsiChar);
 var
-  Buffer: array [0..24] of Char;
+  Buffer: array [0..24] of AnsiChar;
   resLen: Integer;
-  iPos: PChar;
+  iPos: PAnsiChar;
 begin
   // convert to temporary buffer
   resLen := FloatToText(@Buffer[0], Val, {$ifndef FPC_VERSION}fvExtended,{$endif} ffFixed, Size, Precision);
@@ -330,19 +330,19 @@ end;
 
 function GetIntFromStrLength(Src: Pointer; Size: Integer; Default: Integer): Integer;
 var
-  endChar: Char;
+  endChar: AnsiChar;
   Code: Integer;
 begin
-  // save Char at pos term. null
-  endChar := (PChar(Src) + Size)^;
-  (PChar(Src) + Size)^ := #0;
+  // save AnsiChar at pos term. null
+  endChar := (PAnsiChar(Src) + Size)^;
+  (PAnsiChar(Src) + Size)^ := #0;
   // convert
-  Val(PChar(Src), Result, Code);
+  Val(PAnsiChar(Src), Result, Code);
   // check success
   if Code <> 0 then
     Result := Default;
-  // restore prev. ending Char
-  (PChar(Src) + Size)^ := endChar;
+  // restore prev. ending AnsiChar
+  (PAnsiChar(Src) + Size)^ := endChar;
 end;
 
 //====================================================================
@@ -438,14 +438,14 @@ var
 
   procedure GetCodePage;
   var
-    LangStr: PChar;
+    LangStr: PAnsiChar;
   begin
     // determine codepage
     case FDbfVersion of
       xBaseVII:
       begin
         // cache language str
-        LangStr := @PEndFixedHdrVII(PChar(Header) + SizeOf(rDbfHdr))^.LanguageDriverName;
+        LangStr := @PEndFixedHdrVII(PAnsiChar(Header) + SizeOf(rDbfHdr))^.LanguageDriverName;
         // VdBase 7 Language strings
         //  'DBWIN...' -> Charset 1252 (ansi)
         //  'DB999...' -> Code page 999, 9 any digit
@@ -496,7 +496,7 @@ var
     FBackLink:='';
     if FDBFVersion=xVisualFoxPro then //only format that supports it
     begin
-      FBackLink:= StrPas(@PEndHdrVFP(PChar(Header) + FBackLinkOffset)^.Backlink);
+      FBackLink:= StrPas(@PEndHdrVFP(PAnsiChar(Header) + FBackLinkOffset)^.Backlink);
     end;
   end;
 
@@ -722,10 +722,10 @@ begin
       RecordSize := SizeOf(rFieldDescVII);
       FillChar(Header^, HeaderSize, #0);
       PDbfHdr(Header)^.VerDBF := $04;
-      // write language string. FPC needs an explicit cast to pchar to avoid calling widestring version of StrPLCopy
+      // write language string. FPC needs an explicit cast to PAnsiChar to avoid calling widestring version of StrPLCopy
       StrPLCopy(
-        PChar(@PEndFixedHdrVII(PChar(Header)+SizeOf(rDbfHdr))^.LanguageDriverName[32]),
-        PChar(ConstructLangName(FFileCodePage, lLocaleID, false)),
+        PAnsiChar(@PEndFixedHdrVII(PAnsiChar(Header)+SizeOf(rDbfHdr))^.LanguageDriverName[32]),
+        PAnsiChar(ConstructLangName(FFileCodePage, lLocaleID, false)),
         63-32);
       lFieldDescPtr := @lFieldDescVII;
     end else begin
@@ -1137,8 +1137,8 @@ var
   lSize,lPrec,I, lColumnCount: Integer;
   lAutoInc: Cardinal;
   lAutoIncStep: Byte;
-  dataPtr: PChar;
-  lNativeFieldType: Char;
+  dataPtr: PAnsiChar;
+  lNativeFieldType: AnsiChar;
   lFieldName: string;
   lCanHoldNull: boolean; //Can the field store nulls, i.e. is it nullable?
   lIsVFPSystemField: boolean; //Is this a Visual FoxPro system/hidden field?
@@ -1194,7 +1194,7 @@ begin
       if FDbfVersion = xBaseVII then
       begin
         ReadRecord(I, @lFieldDescVII);
-        lFieldName := AnsiUpperCase(PChar(@lFieldDescVII.FieldName[0]));
+        lFieldName := AnsiUpperCase(PAnsiChar(@lFieldDescVII.FieldName[0]));
         lSize := lFieldDescVII.FieldSize;
         lPrec := lFieldDescVII.FieldPrecision;
         lNativeFieldType := lFieldDescVII.FieldType;
@@ -1204,7 +1204,7 @@ begin
       end else begin
         // DBase III..V, FoxPro, Visual FoxPro
         ReadRecord(I, @lFieldDescIII);
-        lFieldName := AnsiUpperCase(PChar(@lFieldDescIII.FieldName[0]));
+        lFieldName := AnsiUpperCase(PAnsiChar(@lFieldDescIII.FieldName[0]));
         lSize := lFieldDescIII.FieldSize;
         lPrec := lFieldDescIII.FieldPrecision;
         lNativeFieldType := lFieldDescIII.FieldType;
@@ -1375,7 +1375,7 @@ end;
 function TDbfFile.GetLanguageStr: string;
 begin
   if FDbfVersion = xBaseVII then
-    Result := PEndFixedHdrVII(PChar(Header) + SizeOf(rDbfHdr))^.LanguageDriverName
+    Result := PEndFixedHdrVII(PAnsiChar(Header) + SizeOf(rDbfHdr))^.LanguageDriverName
   else
     Result := '';  // Only supported in DbaseVII
 end;
@@ -1394,7 +1394,7 @@ begin
         // go to _NULLFLAGS byte that has this field's null flag
         // Find out the byte where the null bit for the field is stored by doing
         // NullPosition shr3 (= NullPosition div 8)...
-        NullFlagByte := PChar(Src) + FNullField.Offset + (AFieldDef.NullPosition shr 3);
+        NullFlagByte := PAnsiChar(Src) + FNullField.Offset + (AFieldDef.NullPosition shr 3);
         // ... get the correct bit in the byte by the equivalent of getting the bit number in that byte:
         // NullPosition and $7 (=mod 8)... and going to the bit value in the byte (by shl)
         // The result is true if the field is null.
@@ -1407,7 +1407,7 @@ begin
         result:=false //field *never* has a varlength byte
       else
       begin
-        NullFlagByte := PChar(Src) + FNullField.Offset + (AFieldDef.VarLengthPosition shr 3);
+        NullFlagByte := PAnsiChar(Src) + FNullField.Offset + (AFieldDef.VarLengthPosition shr 3);
         Result := (PByte(NullFlagByte)^ and (1 shl (AFieldDef.VarLengthPosition and $7))) <> 0
       end;
     end;
@@ -1421,14 +1421,14 @@ end;
 procedure TDbfFile.FastPackTable;
 var
   iDel,iNormal: Integer;
-  pDel,pNormal: PChar;
+  pDel,pNormal: PAnsiChar;
 
   function FindFirstDel: Boolean;
   begin
     while iDel<=iNormal do
     begin
       ReadRecord(iDel, pDel);
-      if (PChar(pDel)^ <> ' ') then
+      if (PAnsiChar(pDel)^ <> ' ') then
       begin
         Result := true;
         exit;
@@ -1443,7 +1443,7 @@ var
     while iNormal>=iDel do
     begin
       ReadRecord(iNormal, pNormal);
-      if (PChar(pNormal)^= ' ') then
+      if (PAnsiChar(pNormal)^= ' ') then
       begin
         Result := true;
         exit;
@@ -1469,7 +1469,7 @@ begin
       begin
         // but is not anymore
         WriteRecord(iDel, pNormal);
-        PChar(pNormal)^ := '*';
+        PAnsiChar(pNormal)^ := '*';
         WriteRecord(iNormal, pNormal);
       end else begin
         // Cannot find a record after iDel so iDel must be deleted
@@ -1838,18 +1838,18 @@ var
 {$ifdef SUPPORT_INT64}
   function GetInt64FromStrLength(Src: Pointer; Size: Integer; Default: Int64): Int64;
   var
-    endChar: Char;
+    endChar: AnsiChar;
     Code: Integer;
   begin
-    // save Char at pos term. null
-    endChar := (PChar(Src) + Size)^;
-    (PChar(Src) + Size)^ := #0;
+    // save AnsiChar at pos term. null
+    endChar := (PAnsiChar(Src) + Size)^;
+    (PAnsiChar(Src) + Size)^ := #0;
     // convert
-    Val(PChar(Src), Result, Code);
+    Val(PAnsiChar(Src), Result, Code);
     // check success
     if Code <> 0 then Result := Default;
-    // restore prev. ending Char
-    (PChar(Src) + Size)^ := endChar;
+    // restore prev. ending AnsiChar
+    (PAnsiChar(Src) + Size)^ := endChar;
   end;
 {$endif}
 
@@ -1909,7 +1909,7 @@ begin
   FieldOffset := AFieldDef.Offset;
   FieldSize := AFieldDef.Size;
   SrcRecord := Src;
-  Src := PChar(Src) + FieldOffset;
+  Src := PAnsiChar(Src) + FieldOffset;
   asciiContents := false;
   Result := true;
   // field types that are binary and of which the fieldsize should not be truncated
@@ -1947,7 +1947,7 @@ begin
       end;
     '@':
       begin
-        Result := (Unaligned(PInteger(Src)^) <> 0) and (Unaligned(PInteger(PChar(Src)+4)^) <> 0);
+        Result := (Unaligned(PInteger(Src)^) <> 0) and (Unaligned(PInteger(PAnsiChar(Src)+4)^) <> 0);
         if Result and (Dst <> nil) then
         begin
           SwapInt64BE(Src, Dst);
@@ -1964,12 +1964,12 @@ begin
 {$ifdef SUPPORT_INT64}        
         Result := Unaligned(PInt64(Src)^) <> 0;
 {$else}        
-        Result := (Unaligned(PInteger(Src)^) <> 0) or (Unaligned(PInteger(PChar(Src)+4)^) <> 0);
+        Result := (Unaligned(PInteger(Src)^) <> 0) or (Unaligned(PInteger(PAnsiChar(Src)+4)^) <> 0);
 {$endif}        
         if Result and (Dst <> nil) then
         begin
           timeStamp.Date := SwapIntLE(Unaligned(PInteger(Src)^)) - JulianDateDelta;
-          timeStamp.Time := SwapIntLE(Unaligned(PInteger(PChar(Src)+4)^));
+          timeStamp.Time := SwapIntLE(Unaligned(PInteger(PAnsiChar(Src)+4)^));
           date := TimeStampToDateTime(timeStamp);
           SaveDateToDst;
         end;
@@ -2053,16 +2053,16 @@ begin
   end;
   if asciiContents then
   begin
-    //    SetString(s, PChar(Src) + FieldOffset, FieldSize );
+    //    SetString(s, PAnsiChar(Src) + FieldOffset, FieldSize );
     //    s := {TrimStr(s)} TrimRight(s);
     // truncate spaces at end by shortening fieldsize
-    while (FieldSize > 0) and ((PChar(Src) + FieldSize - 1)^ = ' ') do
+    while (FieldSize > 0) and ((PAnsiChar(Src) + FieldSize - 1)^ = ' ') do
       dec(FieldSize);
     // if not string field, truncate spaces at beginning too
     if DataType <> ftString then
-      while (FieldSize > 0) and (PChar(Src)^ = ' ') do
+      while (FieldSize > 0) and (PAnsiChar(Src)^ = ' ') do
       begin
-        inc(PChar(Src));
+        inc(PAnsiChar(Src));
         dec(FieldSize);
       end;
     // return if field is empty
@@ -2074,7 +2074,7 @@ begin
           // in DBase- FileDescription lowercase t is allowed too
           // with asking for Result= true s must be longer then 0
           // else an AV occurs, maybe field is NULL
-          if (PChar(Src)^ = 'T') or (PChar(Src)^ = 't') then
+          if (PAnsiChar(Src)^ = 'T') or (PAnsiChar(Src)^ = 't') then
             PWord(Dst)^ := 1
           else
             PWord(Dst)^ := 0;
@@ -2092,14 +2092,14 @@ begin
       ftDate, ftDateTime:
         begin
           // get year, month, day
-          ldy := GetIntFromStrLength(PChar(Src) + 0, 4, 1);
-          ldm := GetIntFromStrLength(PChar(Src) + 4, 2, 1);
-          ldd := GetIntFromStrLength(PChar(Src) + 6, 2, 1);
+          ldy := GetIntFromStrLength(PAnsiChar(Src) + 0, 4, 1);
+          ldm := GetIntFromStrLength(PAnsiChar(Src) + 4, 2, 1);
+          ldd := GetIntFromStrLength(PAnsiChar(Src) + 6, 2, 1);
           //if (ly<1900) or (ly>2100) then ly := 1900;
           //Year from 0001 to 9999 is possible
           //everyting else is an error, an empty string too
           //Do DateCorrection with Delphis possibillities for one or two digits
-          if (ldy < 100) and (PChar(Src)[0] = #32) and (PChar(Src)[1] = #32) then
+          if (ldy < 100) and (PAnsiChar(Src)[0] = #32) and (PAnsiChar(Src)[1] = #32) then
             CorrectYear(ldy);
           try
             date := EncodeDate(ldy, ldm, ldd);
@@ -2111,9 +2111,9 @@ begin
           if (AFieldDef.FieldType = ftDateTime) and (DataType = ftDateTime) then
           begin
             // get hour, minute, second
-            lth := GetIntFromStrLength(PChar(Src) + 8,  2, 1);
-            ltm := GetIntFromStrLength(PChar(Src) + 10, 2, 1);
-            lts := GetIntFromStrLength(PChar(Src) + 12, 2, 1);
+            lth := GetIntFromStrLength(PAnsiChar(Src) + 8,  2, 1);
+            ltm := GetIntFromStrLength(PAnsiChar(Src) + 10, 2, 1);
+            lts := GetIntFromStrLength(PAnsiChar(Src) + 12, 2, 1);
             // encode
             try
               date := date + EncodeTime(lth, ltm, lts, 0);
@@ -2130,7 +2130,7 @@ begin
       case DataType of
       ftString:
         if Dst <> nil then
-          PChar(Dst)[0] := #0;
+          PAnsiChar(Dst)[0] := #0;
       end;
     end;
   end;
@@ -2149,7 +2149,7 @@ begin
     begin
       // Find out the byte where the length bit for the field is stored by doing
       // NullPosition shr3 (= NullPosition div 8)...
-      NullDst := PByte(PChar(Buffer) + FNullField.Offset + (AFieldDef.NullPosition shr 3));
+      NullDst := PByte(PAnsiChar(Buffer) + FNullField.Offset + (AFieldDef.NullPosition shr 3));
       // ... get the correct bit in the byte by the equivalent of
       // getting the bit number in that byte:
       // NullPosition and $7 (=mod 8)...
@@ -2158,7 +2158,7 @@ begin
     end;
   nfVarlengthFlag:
     begin
-      NullDst := PByte(PChar(Buffer) + FNullField.Offset + (AFieldDef.VarLengthPosition shr 3));
+      NullDst := PByte(PAnsiChar(Buffer) + FNullField.Offset + (AFieldDef.VarLengthPosition shr 3));
       Mask := 1 shl (AFieldDef.VarLengthPosition and $7);
     end;
   end;
@@ -2176,7 +2176,7 @@ end;
 procedure TDbfFile.SetFieldData(Column: Integer; DataType: TFieldType; 
   Src, Dst: Pointer; NativeFormat: boolean);
 const
-  IsBlobFieldToPadChar: array[Boolean] of Char = (#32, '0');
+  IsBlobFieldToPadChar: array[Boolean] of AnsiChar = (#32, '0');
   SrcNilToUpdateNullField: array[boolean] of TUpdateNullField = (unfClear, unfSet);
 var
   DstRecord: Pointer;
@@ -2217,7 +2217,7 @@ begin
   FieldPrec := TempFieldDef.Precision;
 
   DstRecord:=Dst; //beginning of record
-  Dst := PChar(Dst) + TempFieldDef.Offset; //beginning of field
+  Dst := PAnsiChar(Dst) + TempFieldDef.Offset; //beginning of field
 
   // if src = nil then write empty field
   // symmetry with above loading code
@@ -2268,7 +2268,7 @@ begin
           Unaligned(PInt64(Dst)^) := 0;
 {$else}          
           Unaligned(PInteger(Dst)^) := 0;
-          Unaligned(PInteger(PChar(Dst)+4)^) := 0;
+          Unaligned(PInteger(PAnsiChar(Dst)+4)^) := 0;
 {$endif}
         end else begin
           LoadDateFromSrc;
@@ -2286,13 +2286,13 @@ begin
           Unaligned(PInt64(Dst)^) := 0;
 {$else}          
           Unaligned(PInteger(Dst)^) := 0;
-          Unaligned(PInteger(PChar(Dst)+4)^) := 0;
+          Unaligned(PInteger(PAnsiChar(Dst)+4)^) := 0;
 {$endif}          
         end else begin
           LoadDateFromSrc;
           timeStamp := DateTimeToTimeStamp(date);
           Unaligned(PInteger(Dst)^) := SwapIntLE(timeStamp.Date + JulianDateDelta);
-          Unaligned(PInteger(PChar(Dst)+4)^) := SwapIntLE(timeStamp.Time);
+          Unaligned(PInteger(PAnsiChar(Dst)+4)^) := SwapIntLE(timeStamp.Time);
         end;
       end;
     'Y':
@@ -2348,7 +2348,7 @@ begin
         if Len < FieldSize then
         begin
           // Clear flag and store actual size byte in last data byte
-          PByte(PChar(Dst)+TempFieldDef.Size-1)^:=Len;
+          PByte(PAnsiChar(Dst)+TempFieldDef.Size-1)^:=Len;
           UpdateNullField(DstRecord, TempFieldDef, unfSet, nfVarlengthFlag);
         end
         else
@@ -2359,9 +2359,9 @@ begin
         Move((Src+sizeof(word))^, Dst^, Len);
         // fill remaining data area with spaces, keeping room for size indicator if needed
         if Len=FieldSize then
-          FillChar((PChar(Dst)+Len)^, FieldSize - Len, ' ')
+          FillChar((PAnsiChar(Dst)+Len)^, FieldSize - Len, ' ')
         else
-          FillChar((PChar(Dst)+Len)^, FieldSize - Len - 1, ' ');
+          FillChar((PAnsiChar(Dst)+Len)^, FieldSize - Len - 1, ' ');
       end;
     'V': //Visual FoxPro varchar
       begin
@@ -2372,7 +2372,7 @@ begin
         if Len < FieldSize then
         begin
           // Clear flag and store actual size byte in last data byte
-          PByte(PChar(Dst)+TempFieldDef.Size-1)^:=Len;
+          PByte(PAnsiChar(Dst)+TempFieldDef.Size-1)^:=Len;
           UpdateNullField(DstRecord, TempFieldDef, unfSet, nfVarlengthFlag);
         end
         else
@@ -2383,9 +2383,9 @@ begin
         Move(Src^, Dst^, Len);
         // fill remaining data area with spaces, keeping room for size indicator if needed
         if Len=FieldSize then
-          FillChar((PChar(Dst)+Len)^, FieldSize - Len, ' ')
+          FillChar((PAnsiChar(Dst)+Len)^, FieldSize - Len, ' ')
         else
-          FillChar((PChar(Dst)+Len)^, FieldSize - Len - 1, ' ');
+          FillChar((PAnsiChar(Dst)+Len)^, FieldSize - Len - 1, ' ');
       end
   else
     asciiContents := true;
@@ -2400,20 +2400,20 @@ begin
         ftBoolean:
           begin
             if PWord(Src)^ <> 0 then
-              PChar(Dst)^ := 'T'
+              PAnsiChar(Dst)^ := 'T'
             else
-              PChar(Dst)^ := 'F';
+              PAnsiChar(Dst)^ := 'F';
           end;
         ftSmallInt:
-          GetStrFromInt_Width(PSmallInt(Src)^, FieldSize, PChar(Dst), #32);
+          GetStrFromInt_Width(PSmallInt(Src)^, FieldSize, PAnsiChar(Dst), #32);
 {$ifdef SUPPORT_INT64}
         ftLargeInt:
-          GetStrFromInt64_Width(PLargeInt(Src)^, FieldSize, PChar(Dst), #32);
+          GetStrFromInt64_Width(PLargeInt(Src)^, FieldSize, PAnsiChar(Dst), #32);
 {$endif}
         ftFloat, ftCurrency:
-          FloatToDbfStr(PDouble(Src)^, FieldSize, FieldPrec, PChar(Dst));
+          FloatToDbfStr(PDouble(Src)^, FieldSize, FieldPrec, PAnsiChar(Dst));
         ftInteger:
-          GetStrFromInt_Width(PInteger(Src)^, FieldSize, PChar(Dst),
+          GetStrFromInt_Width(PInteger(Src)^, FieldSize, PAnsiChar(Dst),
             IsBlobFieldToPadChar[TempFieldDef.IsBlob]);
         ftDate, ftDateTime:
           begin
@@ -2421,17 +2421,17 @@ begin
             // decode
             DecodeDate(date, year, month, day);
             // format is yyyymmdd
-            GetStrFromInt_Width(year,  4, PChar(Dst),   '0');
-            GetStrFromInt_Width(month, 2, PChar(Dst)+4, '0');
-            GetStrFromInt_Width(day,   2, PChar(Dst)+6, '0');
+            GetStrFromInt_Width(year,  4, PAnsiChar(Dst),   '0');
+            GetStrFromInt_Width(month, 2, PAnsiChar(Dst)+4, '0');
+            GetStrFromInt_Width(day,   2, PAnsiChar(Dst)+6, '0');
             // do time too if datetime
             if DataType = ftDateTime then
             begin
               DecodeTime(date, hour, minute, sec, msec);
               // format is hhmmss
-              GetStrFromInt_Width(hour,   2, PChar(Dst)+8,  '0');
-              GetStrFromInt_Width(minute, 2, PChar(Dst)+10, '0');
-              GetStrFromInt_Width(sec,    2, PChar(Dst)+12, '0');
+              GetStrFromInt_Width(hour,   2, PAnsiChar(Dst)+8,  '0');
+              GetStrFromInt_Width(minute, 2, PAnsiChar(Dst)+10, '0');
+              GetStrFromInt_Width(sec,    2, PAnsiChar(Dst)+12, '0');
             end;
           end;
         ftString:
@@ -2442,7 +2442,7 @@ begin
               Len := FieldSize;
             Move(Src^, Dst^, Len);
             // fill remaining space with spaces
-            FillChar((PChar(Dst)+Len)^, FieldSize - Len, ' ');
+            FillChar((PAnsiChar(Dst)+Len)^, FieldSize - Len, ' ');
           end;
       end;  // case datatype
     end;
@@ -2463,7 +2463,7 @@ begin
   
   // set nullflags field so that all fields are null (and var* fields marked as full)
   if FNullField <> nil then
-    FillChar(PChar(FDefaultBuffer+FNullField.Offset)^, FNullField.Size, $FF);
+    FillChar(PAnsiChar(FDefaultBuffer+FNullField.Offset)^, FNullField.Size, $FF);
 
   // check binary and default fields
   for I := 0 to FFieldDefs.Count-1 do
@@ -2473,7 +2473,7 @@ begin
     if (TempFieldDef.NativeFieldType in ['I', 'O', '@', '+', '0', 'W', 'Y'])
         or ((TempFieldDef.NativeFieldType = 'M') and (TempFieldDef.Size = 4) {Visual FoxPro?})
         or ((TempFieldDef.NativeFieldType = 'B') and (FDbfVersion in [xFoxPro, xVisualFoxPro])) then
-      FillChar(PChar(FDefaultBuffer+TempFieldDef.Offset)^, TempFieldDef.Size, 0);
+      FillChar(PAnsiChar(FDefaultBuffer+TempFieldDef.Offset)^, TempFieldDef.Size, 0);
     // copy default value?
     if TempFieldDef.HasDefault then
     begin
@@ -2490,7 +2490,7 @@ begin
             // Set flag and store actual size byte in last data byte
             UpdateNullField(FDefaultBuffer, TempFieldDef, unfSet, nfVarlengthFlag);
             //todo: verify pointer use
-            PByte(PChar(FDefaultBuffer)+TempFieldDef.Size)^:=strlen(FDefaultBuffer);
+            PByte(PAnsiChar(FDefaultBuffer)+TempFieldDef.Size)^:=strlen(FDefaultBuffer);
           end;
     end;
   end;
@@ -3267,9 +3267,9 @@ end;
 var
   TempCodePageList: TList;
 
-// LPTSTR = PChar ok?
+// LPTSTR = PAnsiChar ok?
 
-function CodePagesProc(CodePageString: PChar): Cardinal; stdcall;
+function CodePagesProc(CodePageString: PAnsiChar): Cardinal; stdcall;
 begin
   // add codepage to list
   TempCodePageList.Add(Pointer(GetIntFromStrLength(CodePageString, StrLen(CodePageString), -1)));
@@ -3312,7 +3312,7 @@ begin
 {$else}
   FUserNameLen := MAX_COMPUTERNAME_LENGTH+1;
   SetLength(FUserName, FUserNameLen);
-  Windows.GetComputerName(PChar(FUserName), 
+  Windows.GetComputerName(PAnsiChar(FUserName), 
     {$ifdef DELPHI_3}Windows.DWORD({$endif}
       FUserNameLen
     {$ifdef DELPHI_3}){$endif}

+ 10 - 9
packages/fcl-db/src/dbase/dbf_fields.pas

@@ -14,13 +14,14 @@ unit dbf_fields;
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
  **********************************************************************}
+{$I dbf_common.inc}
+
 interface
 
-{$I dbf_common.inc}
 
 uses
-  Classes,
   SysUtils,
+  Classes,
   db,
   dbf_common,
   dbf_str;
@@ -38,9 +39,9 @@ type
     FIsSystemField: Boolean;
     FVarLengthPosition: integer;
     FNativeFieldType: TDbfFieldType;
-    FDefaultBuf: PChar;
-    FMinBuf: PChar;
-    FMaxBuf: PChar;
+    FDefaultBuf: PAnsiChar;
+    FMinBuf: PAnsiChar;
+    FMaxBuf: PAnsiChar;
     FSize: Integer;
     FPrecision: Integer;
     FHasDefault: Boolean;
@@ -65,7 +66,7 @@ type
     procedure NativeToVCL;
     procedure FreeBuffers;
   protected
-    function  GetDisplayName: string; override;
+    function  GetDisplayName: String; override;
     procedure AssignTo(Dest: TPersistent); override;
     // File is compatible with this database product
     property DbfVersion: TXBaseVersion read GetDbfVersion;
@@ -83,9 +84,9 @@ type
     // Yes if field is a blob/memo type field (storage in external file)
     function  IsBlob: Boolean;
 
-    property DefaultBuf: PChar read FDefaultBuf;
-    property MinBuf: PChar read FMinBuf;
-    property MaxBuf: PChar read FMaxBuf;
+    property DefaultBuf: PAnsiChar read FDefaultBuf;
+    property MinBuf: PAnsiChar read FMinBuf;
+    property MaxBuf: PAnsiChar read FMaxBuf;
     property HasDefault: Boolean read FHasDefault write FHasDefault;
     property HasMin: Boolean read FHasMin write FHasMin;
     property HasMax: Boolean read FHasMax write FHasMax;

+ 2 - 2
packages/fcl-db/src/dbase/dbf_idxcur.pas

@@ -61,7 +61,7 @@ type
 {$ifdef SUPPORT_VARIANTS}
     function  VariantToBuffer(Key: Variant; ABuffer: TRecordBuffer): TExpressionType;
 {$endif}
-    function  CheckUserKey(Key: PChar; StringBuf: PChar): PChar;
+    function  CheckUserKey(Key: PAnsiChar; StringBuf: PAnsiChar): PAnsiChar;
 
     property IndexFile: TIndexFile read FIndexFile;
   end;
@@ -183,7 +183,7 @@ end;
 
 {$endif}
 
-function TIndexCursor.CheckUserKey(Key: PChar; StringBuf: PChar): PChar;
+function TIndexCursor.CheckUserKey(Key: PAnsiChar; StringBuf: PAnsiChar): PAnsiChar;
 var
   keyLen, userLen: Integer;
 begin

+ 89 - 89
packages/fcl-db/src/dbase/dbf_idxfile.pas

@@ -61,7 +61,7 @@ type
   TIndexModifyMode = (mmNormal, mmDeleteRecall);
 
   TDbfLocaleErrorEvent = procedure(var Error: TLocaleError; var Solution: TLocaleSolution) of object;
-  TDbfCompareKeysEvent = function(Key1, Key2: PChar): Integer of object;
+  TDbfCompareKeysEvent = function(Key1, Key2: PAnsiChar): Integer of object;
 
   PDouble = ^Double;
   PInteger = ^Integer;
@@ -126,7 +126,7 @@ type
     FHighPage: Integer;
     FHighPageTemp: Integer;
 
-    procedure LocalInsert(RecNo: Integer; Buffer: PChar; LowerPageNo: Integer);
+    procedure LocalInsert(RecNo: Integer; Buffer: PAnsiChar; LowerPageNo: Integer);
     procedure LocalDelete;
     procedure Delete;
 
@@ -141,7 +141,7 @@ type
     procedure RecurFirst;
     procedure RecurLast;
 
-    procedure SetEntry(RecNo: Integer; AKey: PChar; LowerPageNo: Integer);
+    procedure SetEntry(RecNo: Integer; AKey: PAnsiChar; LowerPageNo: Integer);
     procedure SetEntryNo(value: Integer);
     procedure SetPageNo(NewPageNo: Integer);
     procedure SetLowPage(NewPage: Integer);
@@ -152,9 +152,9 @@ type
   protected
     function GetEntry(AEntryNo: Integer): Pointer; virtual; abstract;
     function GetLowerPageNo: Integer; virtual; abstract;
-    function GetKeyData: PChar; virtual; abstract;
+    function GetKeyData: PAnsiChar; virtual; abstract;
     function GetNumEntries: Integer; virtual; abstract;
-    function GetKeyDataFromEntry(AEntry: Integer): PChar; virtual; abstract;
+    function GetKeyDataFromEntry(AEntry: Integer): PAnsiChar; virtual; abstract;
     function GetRecNo: Integer; virtual; abstract;
     function GetIsInnerNode: Boolean; virtual; abstract;
     procedure IncNumEntries; virtual; abstract;
@@ -183,7 +183,7 @@ type
     procedure SaveBracket;
     procedure RestoreBracket;
 
-    property Key: PChar read GetKeyData;
+    property Key: PAnsiChar read GetKeyData;
     property Entry: Pointer read FEntry;
     property EntryNo: Integer read FEntryNo write SetEntryNo;
     property IndexFile: TIndexFile read FIndexFile;
@@ -214,7 +214,7 @@ type
     function  GetForwardTag2: Byte; virtual; abstract;
     function  GetBackwardTag: Byte; virtual; abstract;
     function  GetReserved: Byte; virtual; abstract;
-    function  GetKeyType: Char; virtual; abstract;
+    function  GetKeyType: AnsiChar; virtual; abstract;
     procedure SetHeaderPageNo(NewPageNo: Integer); virtual; abstract;
     procedure SetTagName(NewName: string); virtual; abstract;
     procedure SetKeyFormat(NewFormat: Byte); virtual; abstract;
@@ -222,7 +222,7 @@ type
     procedure SetForwardTag2(NewTag: Byte); virtual; abstract;
     procedure SetBackwardTag(NewTag: Byte); virtual; abstract;
     procedure SetReserved(NewReserved: Byte); virtual; abstract;
-    procedure SetKeyType(NewType: Char); virtual; abstract;
+    procedure SetKeyType(NewType: AnsiChar); virtual; abstract;
   public
     property HeaderPageNo: Integer read GetHeaderPageNo write SetHeaderPageNo;
     property TagName: string read GetTagName write SetTagName;
@@ -231,7 +231,7 @@ type
     property ForwardTag2: Byte read GetForwardTag2 write SetForwardTag2;
     property BackwardTag: Byte read GetBackwardTag write SetBackwardTag;
     property Reserved: Byte read GetReserved write SetReserved;
-    property KeyType: Char read GetKeyType write SetKeyType;
+    property KeyType: AnsiChar read GetKeyType write SetKeyType;
     property Tag: Pointer read FTag write FTag;
   end;
 //===========================================================================
@@ -266,9 +266,9 @@ type
     FUniqueMode: TIndexUniqueType;
     FModifyMode: TIndexModifyMode;
     FHeaderLocked: Integer;   // used to remember which header page we have locked
-    FKeyBuffer: array[0..100] of Char;
-    FLowBuffer: array[0..100] of Char;
-    FHighBuffer: array[0..100] of Char;
+    FKeyBuffer: array[0..100] of AnsiChar;
+    FLowBuffer: array[0..100] of AnsiChar;
+    FHighBuffer: array[0..100] of AnsiChar;
     FEntryBof: Pointer;
     FEntryEof: Pointer;
     FDbfFile: Pointer;
@@ -276,7 +276,7 @@ type
     FOpened: Boolean;
     FRangeActive: Boolean;
     FUpdateMode: TIndexUpdateMode;
-    FUserKey: PChar;        // find / insert key
+    FUserKey: PAnsiChar;        // find / insert key
     FUserRecNo: Integer;    // find / insert recno
     FUserBCD: array[0..10] of Byte;
     FUserNumeric: Double;
@@ -319,15 +319,15 @@ type
     function  WalkPrev: boolean;
     function  WalkNext: boolean;
     
-    function  CompareKeysNumericNDX(Key1, Key2: PChar): Integer;
-    function  CompareKeysNumericMDX(Key1, Key2: PChar): Integer;
-    function  CompareKeysString(Key1, Key2: PChar): Integer;
+    function  CompareKeysNumericNDX(Key1, Key2: PAnsiChar): Integer;
+    function  CompareKeysNumericMDX(Key1, Key2: PAnsiChar): Integer;
+    function  CompareKeysString(Key1, Key2: PAnsiChar): Integer;
 
     // property functions
     function  GetName: string;
     function  GetDbfLanguageId: Byte;
     function  GetKeyLen: Integer;
-    function  GetKeyType: Char;
+    function  GetKeyType: AnsiChar;
 //    function  GetIndexCount Integer;
     function  GetExpression: string;
     function  GetPhysicalRecNo: Integer;
@@ -363,9 +363,9 @@ type
     procedure PrepareRename(const NewFileName: string);
 
     procedure CreateIndex(FieldDesc, TagName: string; Options: TIndexOptions);
-    function  ExtractKeyFromBuffer(Buffer: TRecordBuffer): PChar;
-    function  SearchKey(Key: PChar; SearchType: TSearchKeyType): Boolean;
-    function  Find(RecNo: Integer; Buffer: PChar): Integer;
+    function  ExtractKeyFromBuffer(Buffer: TRecordBuffer): PAnsiChar;
+    function  SearchKey(Key: PAnsiChar; SearchType: TSearchKeyType): Boolean;
+    function  Find(RecNo: Integer; Buffer: PAnsiChar): Integer;
     function  IndexOf(const AIndexName: string): Integer;
     procedure DisableRange;
     procedure EnableRange;
@@ -380,17 +380,17 @@ type
     function  Next: Boolean;
     function  Prev: Boolean;
 
-    procedure SetRange(LowRange, HighRange: PChar);
+    procedure SetRange(LowRange, HighRange: PAnsiChar);
     procedure CancelRange;
-    function  MatchKey(UserKey: PChar): Integer;
-    function  CompareKey(Key: PChar): Integer;
-    function  CompareKeys(Key1, Key2: PChar): Integer;
-    function  PrepareKey(Buffer: TRecordBuffer; ResultType: TExpressionType): PChar;
+    function  MatchKey(UserKey: PAnsiChar): Integer;
+    function  CompareKey(Key: PAnsiChar): Integer;
+    function  CompareKeys(Key1, Key2: PAnsiChar): Integer;
+    function  PrepareKey(Buffer: TRecordBuffer; ResultType: TExpressionType): PAnsiChar;
 
     property KeyLen: Integer read GetKeyLen;
     property IndexVersion: TXBaseVersion read FIndexVersion;
     property EntryHeaderSize: Integer read FEntryHeaderSize;
-    property KeyType: Char read GetKeyType;
+    property KeyType: AnsiChar read GetKeyType;
 
     property SequentialRecordCount: Integer read GetSequentialRecordCount;
     property SequentialRecNo: Integer read GetSequentialRecNo write SetSequentialRecNo;
@@ -459,7 +459,7 @@ type
     Year       : Byte;     // 1
     Month      : Byte;     // 2
     Day        : Byte;     // 3
-    FileName   : array[0..15] of Char;   // 4..19
+    FileName   : array[0..15] of AnsiChar;   // 4..19
     BlockSize  : Word;     // 20..21
     BlockAdder : Word;     // 22..23
     ProdFlag   : Byte;     // 24
@@ -485,14 +485,14 @@ type
   PMdx4Tag = ^rMdx4Tag;
   rMdx4Tag = record
     HeaderPageNo   : Integer;      // 0..3
-    TagName        : array [0..10] of Char;  // 4..14 of Byte
+    TagName        : array [0..10] of AnsiChar;  // 4..14 of Byte
     KeyFormat      : Byte;         // 15     00h: Calculated
                                    //        10h: Data Field
     ForwardTag1    : Byte;         // 16
     ForwardTag2    : Byte;         // 17
     BackwardTag    : Byte;         // 18
     Reserved       : Byte;         // 19
-    KeyType        : Char;         // 20     C : Character
+    KeyType        : AnsiChar;         // 20     C : Character
                                    //        N : Numerical
                                    //        D : Date
   end;
@@ -500,14 +500,14 @@ type
   PMdx7Tag = ^rMdx7Tag;
   rMdx7Tag = record
     HeaderPageNo   : Integer;      // 0..3
-    TagName        : array [0..32] of Char;  // 4..36 of Byte
+    TagName        : array [0..32] of AnsiChar;  // 4..36 of Byte
     KeyFormat      : Byte;         // 37     00h: Calculated
                                    //        10h: Data Field
     ForwardTag1    : Byte;         // 38
     ForwardTag2    : Byte;         // 39
     BackwardTag    : Byte;         // 40
     Reserved       : Byte;         // 41
-    KeyType        : Char;         // 42     C : Character
+    KeyType        : AnsiChar;         // 42     C : Character
                                    //        N : Numerical
                                    //        D : Date
   end;
@@ -521,7 +521,7 @@ type
                                //        10h: String
                                //        20h: Distinct
                                //        40h: Unique
-    KeyType        : Char;     // 9      C : Character
+    KeyType        : AnsiChar;     // 9      C : Character
                                //        N : Numerical
                                //        D : Date
     Dummy          : Word;     // 10..11
@@ -533,7 +533,7 @@ type
     Version        : Word;     // 20..21
     Dummy2         : Byte;     // 22
     Unique         : Byte;     // 23
-    KeyDesc        : array [0..219] of Char; // 24..243
+    KeyDesc        : array [0..219] of AnsiChar; // 24..243
     Dummy3         : Byte;     // 244
     ForExist       : Byte;     // 245
     KeyExist       : Byte;     // 246
@@ -547,7 +547,7 @@ type
   PMdxEntry = ^rMdxEntry;
   rMdxEntry = record
     RecBlockNo: Longint;       // 0..3   either recno or blockno
-    KeyData   : Char;          // 4..    first byte of data, context => length
+    KeyData   : AnsiChar;          // 4..    first byte of data, context => length
   end;
 
   PMdxPage = ^rMdxPage;
@@ -561,7 +561,7 @@ type
   rNdxEntry  = record
     LowerPageNo: Integer;      //  0..3 lower page
     RecNo      : Integer;      //  4..7 recno
-    KeyData    : Char;
+    KeyData    : AnsiChar;
   end;
 
   PNdxPage  = ^rNdxPage;
@@ -575,9 +575,9 @@ type
   protected
     function GetEntry(AEntryNo: Integer): Pointer; override;
     function GetLowerPageNo: Integer; override;
-    function GetKeyData: PChar; override;
+    function GetKeyData: PAnsiChar; override;
     function GetNumEntries: Integer; override;
-    function GetKeyDataFromEntry(AEntry: Integer): PChar; override;
+    function GetKeyDataFromEntry(AEntry: Integer): PAnsiChar; override;
     function GetRecNo: Integer; override;
     function GetIsInnerNode: Boolean; override;
     procedure IncNumEntries; override;
@@ -593,9 +593,9 @@ type
   protected
     function GetEntry(AEntryNo: Integer): Pointer; override;
     function GetLowerPageNo: Integer; override;
-    function GetKeyData: PChar; override;
+    function GetKeyData: PAnsiChar; override;
     function GetNumEntries: Integer; override;
-    function GetKeyDataFromEntry(AEntry: Integer): PChar; override;
+    function GetKeyDataFromEntry(AEntry: Integer): PAnsiChar; override;
     function GetRecNo: Integer; override;
     function GetIsInnerNode: Boolean; override;
     procedure IncNumEntries; override;
@@ -613,7 +613,7 @@ type
     function  GetForwardTag2: Byte; override;
     function  GetBackwardTag: Byte; override;
     function  GetReserved: Byte; override;
-    function  GetKeyType: Char; override;
+    function  GetKeyType: AnsiChar; override;
     procedure SetHeaderPageNo(NewPageNo: Integer); override;
     procedure SetTagName(NewName: string); override;
     procedure SetKeyFormat(NewFormat: Byte); override;
@@ -621,7 +621,7 @@ type
     procedure SetForwardTag2(NewTag: Byte); override;
     procedure SetBackwardTag(NewTag: Byte); override;
     procedure SetReserved(NewReserved: Byte); override;
-    procedure SetKeyType(NewType: Char); override;
+    procedure SetKeyType(NewType: AnsiChar); override;
   end;
 //---------------------------------------------------------------------------
   TMdx7Tag = class(TIndexTag)
@@ -632,7 +632,7 @@ type
     function  GetForwardTag2: Byte; override;
     function  GetBackwardTag: Byte; override;
     function  GetReserved: Byte; override;
-    function  GetKeyType: Char; override;
+    function  GetKeyType: AnsiChar; override;
     procedure SetHeaderPageNo(NewPageNo: Integer); override;
     procedure SetTagName(NewName: string); override;
     procedure SetKeyFormat(NewFormat: Byte); override;
@@ -640,7 +640,7 @@ type
     procedure SetForwardTag2(NewTag: Byte); override;
     procedure SetBackwardTag(NewTag: Byte); override;
     procedure SetReserved(NewReserved: Byte); override;
-    procedure SetKeyType(NewType: Char); override;
+    procedure SetKeyType(NewType: AnsiChar); override;
   end;
 
 var
@@ -664,7 +664,7 @@ end;
 //==========================================================
 // Locale support for all versions of Delphi/C++Builder
 
-function LocaleCallBack(LocaleString: PChar): Integer; stdcall;
+function LocaleCallBack(LocaleString: PAnsiChar): Integer; stdcall;
 begin
   LCIDList.Add(Pointer(StrToInt('$'+LocaleString)));
   Result := 1;
@@ -704,7 +704,7 @@ end;
 
 procedure TIndexPage.Clear;
 begin
-  FillChar(PChar(FPageBuffer)^, FIndexFile.RecordSize, 0);
+  FillChar(PAnsiChar(FPageBuffer)^, FIndexFile.RecordSize, 0);
   FreeAndNil(FLowerPage);
   FUpperPage := nil;
   FPageNo := -1;
@@ -752,7 +752,7 @@ begin
   end;
 end;
 
-procedure TIndexPage.LocalInsert(RecNo: Integer; Buffer: PChar; LowerPageNo: Integer);
+procedure TIndexPage.LocalInsert(RecNo: Integer; Buffer: PAnsiChar; LowerPageNo: Integer);
   // *) assumes there is at least one entry free
 var
   source, dest: Pointer;
@@ -851,7 +851,7 @@ end;
 function TIndexPage.MatchKey: Integer;
   // assumes Buffer <> nil
 var
-  keyData: PChar;
+  keyData: PAnsiChar;
 begin
   // get key data
   keyData := GetKeyData;
@@ -957,11 +957,11 @@ begin
     FEntry := GetEntry(FEntryNo);
 end;
 
-procedure TIndexPage.SetEntry(RecNo: Integer; AKey: PChar; LowerPageNo: Integer);
+procedure TIndexPage.SetEntry(RecNo: Integer; AKey: PAnsiChar; LowerPageNo: Integer);
 var
-  keyData: PChar;
+  keyData: PAnsiChar;
 {$ifdef TDBF_INDEX_CHECK}
-  prevKeyData, curKeyData, nextKeyData: PChar;
+  prevKeyData, curKeyData, nextKeyData: PAnsiChar;
 {$endif}
 begin
   // get num entries
@@ -974,7 +974,7 @@ begin
     if AKey <> nil then
       Move(AKey^, keyData^, SwapWordLE(PIndexHdr(FIndexFile.IndexHeader)^.KeyLen))
     else
-      PChar(keyData)^ := #0;
+      PAnsiChar(keyData)^ := #0;
 {
   else
     if AKey <> nil then
@@ -1024,7 +1024,7 @@ procedure TIndexPage.Split;
 var
   NewPage: TIndexPage;
   source, dest: Pointer;
-  paKeyData: PChar;
+  paKeyData: PAnsiChar;
   size, oldEntryNo: Integer;
   splitRight, lNumEntries, numEntriesNew: Integer;
   saveLow, saveHigh: Integer;
@@ -1429,7 +1429,7 @@ end;
 function TMdxPage.GetEntry(AEntryNo: Integer): Pointer;
 begin
   // get base + offset
-  Result := PChar(@PMdxPage(PageBuffer)^.FirstEntry) + (SwapWordLE(PIndexHdr(
+  Result := PAnsiChar(@PMdxPage(PageBuffer)^.FirstEntry) + (SwapWordLE(PIndexHdr(
     IndexFile.IndexHeader)^.KeyRecLen) * AEntryNo);
 end;
 
@@ -1442,7 +1442,7 @@ begin
     Result := SwapIntLE(PMdxEntry(Entry)^.RecBlockNo);
 end;
 
-function TMdxPage.GetKeyData: PChar;
+function TMdxPage.GetKeyData: PAnsiChar;
 begin
   Result := @PMdxEntry(Entry)^.KeyData;
 end;
@@ -1452,7 +1452,7 @@ begin
   Result := SwapWordLE(PMdxPage(PageBuffer)^.NumEntries);
 end;
 
-function TMdxPage.GetKeyDataFromEntry(AEntry: Integer): PChar;
+function TMdxPage.GetKeyDataFromEntry(AEntry: Integer): PAnsiChar;
 begin
   Result := @PMdxEntry(GetEntry(AEntry))^.KeyData;
 end;
@@ -1504,7 +1504,7 @@ end;
 function TNdxPage.GetEntry(AEntryNo: Integer): Pointer;
 begin
   // get base + offset
-  Result := PChar(@PNdxPage(PageBuffer)^.FirstEntry) + 
+  Result := PAnsiChar(@PNdxPage(PageBuffer)^.FirstEntry) + 
     (SwapWordLE(PIndexHdr(FIndexFile.IndexHeader)^.KeyRecLen) * AEntryNo);
 end;
 
@@ -1522,12 +1522,12 @@ begin
   Result := SwapIntLE(PNdxEntry(Entry)^.RecNo);
 end;
 
-function TNdxPage.GetKeyData: PChar;
+function TNdxPage.GetKeyData: PAnsiChar;
 begin
   Result := @PNdxEntry(Entry)^.KeyData;
 end;
 
-function TNdxPage.GetKeyDataFromEntry(AEntry: Integer): PChar;
+function TNdxPage.GetKeyDataFromEntry(AEntry: Integer): PAnsiChar;
 begin
   Result := @PNdxEntry(GetEntry(AEntry))^.KeyData;
 end;
@@ -1598,7 +1598,7 @@ begin
   Result := PMdx4Tag(Tag)^.Reserved;
 end;
 
-function TMdx4Tag.GetKeyType: Char;
+function TMdx4Tag.GetKeyType: AnsiChar;
 begin
   Result := PMdx4Tag(Tag)^.KeyType;
 end;
@@ -1639,7 +1639,7 @@ begin
   PMdx4Tag(Tag)^.Reserved := NewReserved;
 end;
 
-procedure TMdx4Tag.SetKeyType(NewType: Char);
+procedure TMdx4Tag.SetKeyType(NewType: AnsiChar);
 begin
   PMdx4Tag(Tag)^.KeyType := NewType;
 end;
@@ -1683,7 +1683,7 @@ begin
   Result := PMdx7Tag(Tag)^.Reserved;
 end;
 
-function TMdx7Tag.GetKeyType: Char;
+function TMdx7Tag.GetKeyType: AnsiChar;
 begin
   Result := PMdx7Tag(Tag)^.KeyType;
 end;
@@ -1724,7 +1724,7 @@ begin
   PMdx7Tag(Tag)^.Reserved := NewReserved;
 end;
 
-procedure TMdx7Tag.SetKeyType(NewType: Char);
+procedure TMdx7Tag.SetKeyType(NewType: AnsiChar);
 begin
   PMdx7Tag(Tag)^.KeyType := NewType;
 end;
@@ -2039,7 +2039,7 @@ end;
 
 procedure WriteDBFileName(Header: PMdxHdr; const HdrFileName: string);
 var
-  FN,HdrFileExt: string;
+  FN,HdrFileExt: ansistring;
   lPos, lenFileName: integer;
 begin
   FN := ExtractFileName(HdrFileName);
@@ -2053,7 +2053,7 @@ begin
   if Length(FN) > 15 then
     SetLength(FN, 15);
   lenFileName := Length(FN);
-  Move(PChar(FN)^, PMdxHdr(Header)^.FileName[0], lenFileName);
+  Move(PAnsiChar(FN)^, PMdxHdr(Header)^.FileName[0], lenFileName);
   FillChar(PMdxHdr(Header)^.FileName[lenFileName], 15-lenFileName, 0);
 end;
 
@@ -2183,7 +2183,7 @@ end;
 procedure TIndexFile.CreateIndex(FieldDesc, TagName: string; Options: TIndexOptions);
 var
   tagNo: Integer;
-  fieldType: Char;
+  fieldType: AnsiChar;
   TempParser: TDbfIndexParser;
 begin
   // check if we have exclusive access to table
@@ -2574,7 +2574,7 @@ var
     if FIndexVersion >= xBaseIV then
     begin
       // calculate tag offset in tempfile header
-      FTempMdxTag.Tag := PChar(TempFile.Header) + (PChar(CalcTagOffset(I)) - Header);
+      FTempMdxTag.Tag := PAnsiChar(TempFile.Header) + (PAnsiChar(CalcTagOffset(I)) - Header);
       FTempMdxTag.HeaderPageNo := hdrPageNo;
     end;
   end;
@@ -2741,7 +2741,7 @@ var
     if FIndexVersion >= xBaseIV then
     begin
       // calculate tag offset in tempfile header
-      FTempMdxTag.Tag := PChar(TempFile.Header) + (PChar(CalcTagOffset(I)) - Header);
+      FTempMdxTag.Tag := PAnsiChar(TempFile.Header) + (PAnsiChar(CalcTagOffset(I)) - Header);
       FTempMdxTag.HeaderPageNo := hdrPageNo;
     end;
   end;
@@ -2902,7 +2902,7 @@ begin
   end;
 end;
 
-function TIndexFile.PrepareKey(Buffer: TRecordBuffer; ResultType: TExpressionType): PChar;
+function TIndexFile.PrepareKey(Buffer: TRecordBuffer; ResultType: TExpressionType): PAnsiChar;
 var
   FloatRec: TFloatRec;
   I, IntSrc, NumDecimals: Integer;
@@ -2914,7 +2914,7 @@ var
 
 begin
   // need to convert numeric?
-  Result := PChar(Buffer);
+  Result := PAnsiChar(Buffer);
   if PIndexHdr(FIndexHeader)^.KeyType in ['N', 'F'] then
   begin
     if FIndexVersion = xBaseIII then
@@ -2924,13 +2924,13 @@ begin
         etInteger:
           begin
             FUserNumeric := PInteger(Result)^;
-            Result := PChar(@FUserNumeric);
+            Result := PAnsiChar(@FUserNumeric);
           end;
 {$ifdef SUPPORT_INT64}
         etLargeInt:
           begin
             FUserNumeric := PLargeInt(Result)^;
-            Result := PChar(@FUserNumeric);
+            Result := PAnsiChar(@FUserNumeric);
           end;
 {$endif}
       end;
@@ -3011,12 +3011,12 @@ begin
       end;
 
       // set result pointer to BCD
-      Result := PChar(@FUserBCD[0]);
+      Result := PAnsiChar(@FUserBCD[0]);
     end;
   end;
 end;
 
-function TIndexFile.ExtractKeyFromBuffer(Buffer: TRecordBuffer): PChar;
+function TIndexFile.ExtractKeyFromBuffer(Buffer: TRecordBuffer): PAnsiChar;
 begin
   // execute expression to get key
   Result := PrepareKey(TRecordBuffer(FCurrentParser.ExtractFromBuffer(Buffer)), FCurrentParser.ResultType);
@@ -3193,8 +3193,8 @@ end;
 
 function TIndexFile.UpdateCurrent(PrevBuffer, NewBuffer: TRecordBuffer): boolean;
 var
-  InsertKey, DeleteKey: PChar;
-  TempBuffer: array [0..100] of Char;
+  InsertKey, DeleteKey: PAnsiChar;
+  TempBuffer: array [0..100] of AnsiChar;
 begin
   Result := true;
   if FCanEdit and (PIndexHdr(FIndexHeader)^.KeyLen <> 0) then
@@ -3224,7 +3224,7 @@ end;
 procedure TIndexFile.AddNewLevel;
 var
   lNewPage: TIndexPage;
-  pKeyData: PChar;
+  pKeyData: PAnsiChar;
 begin
   // create new page + space
   if FIndexVersion >= xBaseIV then
@@ -3284,7 +3284,7 @@ begin
   FRoot.PageNo := SwapIntLE(PIndexHdr(FIndexHeader)^.RootPage);
 end;
 
-function TIndexFile.SearchKey(Key: PChar; SearchType: TSearchKeyType): Boolean;
+function TIndexFile.SearchKey(Key: PAnsiChar; SearchType: TSearchKeyType): Boolean;
 var
   findres, currRecNo: Integer;
 begin
@@ -3319,7 +3319,7 @@ begin
     SequentialRecNo := currRecNo;
 end;
 
-function TIndexFile.Find(RecNo: Integer; Buffer: PChar): Integer;
+function TIndexFile.Find(RecNo: Integer; Buffer: PAnsiChar): Integer;
 begin
   // execute find
   FUserRecNo := RecNo;
@@ -3415,7 +3415,7 @@ begin
   until done = 0;
 end;
 
-function TIndexFile.MatchKey(UserKey: PChar): Integer;
+function TIndexFile.MatchKey(UserKey: PAnsiChar): Integer;
 begin
   // BOF and EOF always false
   if FLeaf.Entry = FEntryBof then
@@ -3429,7 +3429,7 @@ begin
   end;
 end;
 
-procedure TIndexFile.SetRange(LowRange, HighRange: PChar);
+procedure TIndexFile.SetRange(LowRange, HighRange: PAnsiChar);
 begin
   Move(LowRange^, FLowBuffer[0], KeyLen);
   Move(HighRange^, FHighBuffer[0], KeyLen);
@@ -3657,7 +3657,7 @@ begin
   Result := SwapWordLE(PIndexHdr(FIndexHeader)^.KeyLen);
 end;
 
-function TIndexFile.GetKeyType: Char;
+function TIndexFile.GetKeyType: AnsiChar;
 begin
   Result := PIndexHdr(FIndexHeader)^.KeyType;
 end;
@@ -3813,15 +3813,15 @@ begin
       exit;
     end;
     // go to next byte
-    Inc(PChar(P1));
-    Inc(PChar(P2));
+    Inc(PAnsiChar(P1));
+    Inc(PAnsiChar(P2));
   end;
 
   // memory equal
   Result := 0;
 end;
 
-function TIndexFile.CompareKeys(Key1, Key2: PChar): Integer;
+function TIndexFile.CompareKeys(Key1, Key2: PAnsiChar): Integer;
 begin
   // call compare routine
   Result := FCompareKeys(Key1, Key2);
@@ -3831,7 +3831,7 @@ begin
     Result := -Result;
 end;
 
-function TIndexFile.CompareKeysNumericNDX(Key1, Key2: PChar): Integer;
+function TIndexFile.CompareKeysNumericNDX(Key1, Key2: PAnsiChar): Integer;
 var
   v1,v2: Double;
 begin
@@ -3842,7 +3842,7 @@ begin
   else Result := 0;
 end;
 
-function TIndexFile.CompareKeysNumericMDX(Key1, Key2: PChar): Integer;
+function TIndexFile.CompareKeysNumericMDX(Key1, Key2: PAnsiChar): Integer;
 var
   neg1, neg2: Boolean;
 begin
@@ -3876,14 +3876,14 @@ begin
     Result := 1;
 end;
 
-function TIndexFile.CompareKeysString(Key1, Key2: PChar): Integer;
+function TIndexFile.CompareKeysString(Key1, Key2: PAnsiChar): Integer;
 begin
   Result := DbfCompareString(FCollation, Key1, KeyLen, Key2, KeyLen);
   if Result > 0 then
     Dec(Result, 2);
 end;
 
-function TIndexFile.CompareKey(Key: PChar): Integer;
+function TIndexFile.CompareKey(Key: PAnsiChar): Integer;
 begin
   Result := CompareKeys(FUserKey, Key);
 end;
@@ -3937,7 +3937,7 @@ end;
 
 function TIndexFile.CalcTagOffset(AIndex: Integer): Pointer;
 begin
-  Result := PChar(Header) + FTagOffset + AIndex * FTagSize;
+  Result := PAnsiChar(Header) + FTagOffset + AIndex * FTagSize;
 end;
 
 procedure TIndexFile.SelectIndexVars(AIndex: Integer);

+ 4 - 4
packages/fcl-db/src/dbase/dbf_lang.pas

@@ -546,7 +546,7 @@ begin
     // foxpro or dbase?
     if IsFoxPro then
     begin
-      Result := 'FOX' + PChar(@SubType);
+      Result := 'FOX' + PAnsiChar(@SubType);
       if CodePage = 1252 then
         Result := Result + 'WIN'
       else
@@ -565,7 +565,7 @@ begin
         else
           Result := Result + IntToStr(CodePage);
         // add subtype
-        Result := Result + PChar(@SubType);
+        Result := Result + PAnsiChar(@SubType);
       end;
     end;
   end;
@@ -614,7 +614,7 @@ begin
       // it seems delphi does not properly understand pointers?
       // what a mess :-(
       if ((LangId_To_CodePage[LangID] = CodePage) or (CodePage = 0)) and
-        (PCardinal(PChar(LanguageIDToLocaleTable)+(LangID*4))^ = DesiredLocale) then
+        (PCardinal(PAnsiChar(LanguageIDToLocaleTable)+(LangID*4))^ = DesiredLocale) then
         // Ignore (V)FP results
         if LangID <= dBase_Regions[Region+1] then
           result := Byte(LangID);
@@ -651,7 +651,7 @@ var
   CodePageStr: string;
 begin
   // determine foxpro/dbase
-  IsFoxPro := CompareMem(PChar('FOX'), PChar(LocaleStr), 3);
+  IsFoxPro := CompareMem(PAnsiChar('FOX'), PAnsiChar(LocaleStr), 3);
   // get codepage/locale subtype
   if IsFoxPro then
   begin

+ 4 - 4
packages/fcl-db/src/dbase/dbf_memo.pas

@@ -35,10 +35,10 @@ type
   protected
     FDbfFile: pointer;
     FDbfVersion: TXBaseVersion;
-    FEmptySpaceFiller: Char; //filler for unused header and memo data
+    FEmptySpaceFiller: AnsiChar; //filler for unused header and memo data
     FMemoRecordSize: Integer;
     FOpened: Boolean;
-    FBuffer: PChar;
+    FBuffer: PAnsiChar;
   protected
     function  GetBlockLen: Integer; virtual; abstract;
     function  GetMemoSize: Integer; virtual; abstract;
@@ -279,8 +279,8 @@ procedure TMemoFile.ReadMemo(BlockNo: Integer; DestStream: TStream);
 var
   bytesLeft,numBytes,dataStart: Integer;
   done: Boolean;
-  lastc: char;
-  endMemo: PChar;
+  lastc: AnsiChar;
+  endMemo: PAnsiChar;
 begin
   // clear dest
   DestStream.Position := 0;

+ 4 - 4
packages/fcl-db/src/dbase/dbf_parser.pas

@@ -69,7 +69,7 @@ type
     procedure ClearExpressions; override;
 
     procedure ParseExpression(AExpression: string); virtual;
-    function ExtractFromBuffer(Buffer: TRecordBuffer): PChar; virtual;
+    function ExtractFromBuffer(Buffer: TRecordBuffer): PAnsiChar; virtual;
 
     property DbfFile: Pointer read FDbfFile write FDbfFile;
     property Expression: string read FCurrentExpression;
@@ -121,7 +121,7 @@ type
 
   TStringFieldVar = class(TFieldVar)
   protected
-    FFieldVal: PChar;
+    FFieldVal: PAnsiChar;
     FMode: TStringFieldMode;
 
     function GetFieldVal: Pointer; override;
@@ -589,7 +589,7 @@ begin
   FCurrentExpression := AExpression;
 end;
 
-function TDbfParser.ExtractFromBuffer(Buffer: TRecordBuffer): PChar;
+function TDbfParser.ExtractFromBuffer(Buffer: TRecordBuffer): PAnsiChar;
 var
   I: Integer;
 begin
@@ -608,7 +608,7 @@ begin
     Result := TFieldVar(FFieldVarList.Objects[0]).FieldVal;
     // if string then dereference
     if FFieldType = etString then
-      Result := PPChar(Result)^;
+      Result := PPAnsiChar(Result)^;
   end;
 end;
 

+ 2 - 2
packages/fcl-db/src/dbase/dbf_pgcfile.pas

@@ -35,7 +35,7 @@ type
   TPageInfo = record
     TimeStamp: Cardinal;
     Modified: Boolean;
-    Data: Char;
+    Data: AnsiChar;
   end;
 
   TCachedFile = class(TPagedFile)
@@ -125,7 +125,7 @@ begin
   Flush;
 
   // calculate size of extra data of pagetree
-  FPageInfoSize := SizeOf(TPageInfo) - SizeOf(Char) + RecordSize;
+  FPageInfoSize := SizeOf(TPageInfo) - SizeOf(AnsiChar) + RecordSize;
   UpdateMaxPages;
 end;
 

+ 4 - 4
packages/fcl-db/src/dbase/dbf_pgfile.pas

@@ -57,7 +57,7 @@ type
     FPagesPerRecord: Integer;
     FCachedSize: Integer;
     FCachedRecordCount: Integer;
-    FHeader: PChar;
+    FHeader: PAnsiChar;
     FActive: Boolean;
     FNeedRecalc: Boolean;
     FHeaderModified: Boolean;
@@ -156,7 +156,7 @@ type
     property CachedRecordCount: Integer read FCachedRecordCount;
     property PageOffsetByHeader: Boolean read FPageOffsetbyHeader write SetPageOffsetByHeader;
     property FileLocked: Boolean read FFileLocked;
-    property Header: PChar read FHeader;
+    property Header: PAnsiChar read FHeader;
     property FileName: string read FFileName write SetFileName;
     property Stream: TStream read FStream write SetStream;
     property BufferAhead: Boolean read FBufferAhead write SetBufferAhead;
@@ -459,7 +459,7 @@ begin
       Offset := 0;
     end;
     // now we have this record in buffer
-    Move(PChar(FBufferPtr)[Offset], Buffer^, RecordSize);
+    Move(PAnsiChar(FBufferPtr)[Offset], Buffer^, RecordSize);
     // successful
     Result := RecordSize;
   end else begin
@@ -487,7 +487,7 @@ begin
       RecEnd := PagesPerRecord * PageSize;
     end;
     // we can write this record to buffer
-    Move(Buffer^, PChar(FBufferPtr)[RecEnd-RecordSize], RecordSize);
+    Move(Buffer^, PAnsiChar(FBufferPtr)[RecEnd-RecordSize], RecordSize);
     FBufferModified := true;
     // update cached size
     UpdateCachedSize(FBufferOffset+RecEnd);

+ 147 - 143
packages/fcl-db/src/dbase/dbf_prscore.pas

@@ -42,21 +42,21 @@ type
 
   TCustomExpressionParser = class(TObject)
   private
-    FHexChar: Char;
-    FArgSeparator: Char;
-    FDecimalSeparator: Char;
+    FHexChar: AnsiChar;
+    FArgSeparator: AnsiChar;
+    FDecimalSeparator: AnsiChar;
     FOptimize: Boolean;
     FConstantsList: TOCollection;
     FLastRec: PExpressionRec;
     FCurrentRec: PExpressionRec;
-    FExpResult: PChar;
-    FExpResultPos: PChar;
+    FExpResult: PAnsiChar;
+    FExpResultPos: PAnsiChar;
     FExpResultSize: Integer;
 
-    procedure ParseString(const AnExpression: string; DestCollection: TExprCollection);
+    procedure ParseString(const AnExpression: AnsiString; DestCollection: TExprCollection);
     function  MakeTree(Expr: TExprCollection; FirstItem, LastItem: Integer): PExpressionRec;
-    procedure MakeLinkedList(var ExprRec: PExpressionRec; Memory: PPChar;
-        MemoryPos: PPChar; MemSize: PInteger);
+    procedure MakeLinkedList(var ExprRec: PExpressionRec; Memory: PPAnsiChar;
+        MemoryPos: PPAnsiChar; MemSize: PInteger);
     procedure Check(AnExprList: TExprCollection);
     procedure CheckArguments(ExprRec: PExpressionRec);
     procedure RemoveConstants(var ExprRec: PExpressionRec);
@@ -66,43 +66,43 @@ type
 
     function MakeRec: PExpressionRec; virtual;
     procedure FillExpressList; virtual; abstract;
-    procedure HandleUnknownVariable(VarName: string); virtual; abstract;
+    procedure HandleUnknownVariable(VarName: AnsiString); virtual; abstract;
 
-    procedure CompileExpression(const AnExpression: string);
+    procedure CompileExpression(const AnExpression: AnsiString);
     procedure EvaluateCurrent;
     procedure DisposeList(ARec: PExpressionRec);
     procedure DisposeTree(ExprRec: PExpressionRec);
-    function CurrentExpression: string; virtual; abstract;
+    function CurrentExpression: AnsiString; virtual; abstract;
     function GetResultType: TExpressionType; virtual;
 
     property CurrentRec: PExpressionRec read FCurrentRec write FCurrentRec;
     property LastRec: PExpressionRec read FLastRec write FLastRec;
-    property ExpResult: PChar read FExpResult;
-    property ExpResultPos: PChar read FExpResultPos write FExpResultPos;
+    property ExpResult: PAnsiChar read FExpResult;
+    property ExpResultPos: PAnsiChar read FExpResultPos write FExpResultPos;
 
   public
     constructor Create;
     destructor Destroy; override;
 
-    function DefineFloatVariable(const AVarName: string; AValue: PDouble): TExprWord;
-    function DefineIntegerVariable(const AVarName: string; AValue: PInteger; AIsNull: PBoolean = nil): TExprWord;
-//    procedure DefineSmallIntVariable(AVarName: string; AValue: PSmallInt);
+    function DefineFloatVariable(const AVarName: AnsiString; AValue: PDouble): TExprWord;
+    function DefineIntegerVariable(const AVarName: AnsiString; AValue: PInteger; AIsNull: PBoolean = nil): TExprWord;
+//    procedure DefineSmallIntVariable(AVarName: AnsiString; AValue: PSmallInt);
 {$ifdef SUPPORT_INT64}
-    function DefineLargeIntVariable(const AVarName: string; AValue: PLargeInt): TExprWord;
+    function DefineLargeIntVariable(const AVarName: AnsiString; AValue: PLargeInt): TExprWord;
 {$endif}
-    function DefineDateTimeVariable(const AVarName: string; AValue: PDateTimeRec): TExprWord;
-    function DefineBooleanVariable(const AVarName: string; AValue: PBoolean): TExprWord;
-    function DefineStringVariable(const AVarName: string; AValue: PPChar; AIsNull: PBoolean = nil): TExprWord;
-    function DefineFunction(const AFunctName, AShortName, ADescription, ATypeSpec: string;
+    function DefineDateTimeVariable(const AVarName: AnsiString; AValue: PDateTimeRec): TExprWord;
+    function DefineBooleanVariable(const AVarName: AnsiString; AValue: PBoolean): TExprWord;
+    function DefineStringVariable(const AVarName: AnsiString; AValue: PPAnsiChar; AIsNull: PBoolean = nil): TExprWord;
+    function DefineFunction(const AFunctName, AShortName, ADescription, ATypeSpec: AnsiString;
         AMinFunctionArg: Integer; AResultType: TExpressionType; AFuncAddress: TExprFunc): TExprWord;
-    procedure Evaluate(const AnExpression: string);
-    function AddExpression(const AnExpression: string): Integer;
+    procedure Evaluate(const AnExpression: AnsiString);
+    function AddExpression(const AnExpression: AnsiString): Integer;
     procedure ClearExpressions; virtual;
 //    procedure GetGeneratedVars(AList: TList);
     procedure GetFunctionNames(AList: TStrings);
-    function GetFunctionDescription(const AFunction: string): string;
-    property HexChar: Char read FHexChar write FHexChar;
-    property ArgSeparator: Char read FArgSeparator write FArgSeparator;
+    function GetFunctionDescription(AFunction: AnsiString): AnsiString;
+    property HexChar: AnsiChar read FHexChar write FHexChar;
+    property ArgSeparator: AnsiChar read FArgSeparator write FArgSeparator;
     property Optimize: Boolean read FOptimize write FOptimize;
     property ResultType: TExpressionType read GetResultType;
 
@@ -112,7 +112,7 @@ type
 
 
 //--Expression functions-----------------------------------------------------
-//I: Integer; L: Large Integer (Int64); F: Double; S: String; B: Boolean
+//I: Integer; L: Large Integer (Int64); F: Double; S: AnsiString; B: Boolean
 
 procedure FuncFloatToStr(Param: PExpressionRec);
 procedure FuncIntToStr_Gen(Param: PExpressionRec; Val: {$ifdef SUPPORT_INT64}Int64{$else}Integer{$endif});
@@ -264,9 +264,9 @@ begin
       // copy pointer to variable
       Args[0] := ExprWord.AsPointer;
       // store length as second parameter
-      Args[1] := PChar(ExprWord.LenAsPointer);
+      Args[1] := PAnsiChar(ExprWord.LenAsPointer);
       // and NULL indicator as third parameter
-      Args[2] := PChar(ExprWord.IsNullAsPointer);
+      Args[2] := PAnsiChar(ExprWord.IsNullAsPointer);
     end;
   end;
 end;
@@ -323,7 +323,7 @@ begin
   inherited;
 end;
 
-procedure TCustomExpressionParser.CompileExpression(const AnExpression: string);
+procedure TCustomExpressionParser.CompileExpression(const AnExpression: ansistring);
 var
   ExpColl: TExprCollection;
   ExprTree: PExpressionRec;
@@ -566,7 +566,7 @@ begin
 end;
 
 procedure TCustomExpressionParser.MakeLinkedList(var ExprRec: PExpressionRec;
-  Memory: PPChar; MemoryPos: PPChar; MemSize: PInteger);
+  Memory: PPAnsiChar; MemoryPos: PPAnsiChar; MemSize: PInteger);
 var
   I: Integer;
 begin
@@ -780,16 +780,16 @@ begin
     raise EParserException.Create('Operator/function missing');
 end;
 
-procedure TCustomExpressionParser.ParseString(const AnExpression: string; DestCollection: TExprCollection);
+procedure TCustomExpressionParser.ParseString(const AnExpression: AnsiString; DestCollection: TExprCollection);
 const
   NullWord='NULL';
 var
   isConstant: Boolean;
   I, I1, I2, Len, DecSep: Integer;
-  W, S: string;
+  W, S: AnsiString;
   TempWord: TExprWord;
 
-  procedure ReadConstant(const AnExpr: string; isHex: Boolean);
+  procedure ReadConstant(const AnExpr: AnsiString; isHex: Boolean);
   begin
     isConstant := true;
     while (I2 <= Len) and ((AnExpr[I2] in ['0'..'9']) or
@@ -814,10 +814,11 @@ var
     end;
   end;
 
-  procedure ReadWord(const AnExpr: string);
+  procedure ReadWord(const AnExpr: AnsiString);
+
   var
     OldI2: Integer;
-    constChar: Char;
+    constChar: AnsiChar;
   begin
     isConstant := false;
     I1 := I2;
@@ -841,9 +842,9 @@ var
       else if AnExpr[I2] = FDecimalSeparator then
         ReadConstant(AnExpr, false)
       else
-        // String constants can be delimited by ' or "
+        // AnsiString constants can be delimited by ' or "
         // but need not be - see below
-        // To use a delimiter inside the string, double it up to escape it
+        // To use a delimiter inside the AnsiString, double it up to escape it
         case AnExpr[I2] of
           '''', '"':
             begin
@@ -866,7 +867,7 @@ var
                 end;
               end;
             end;
-          // However string constants can also appear without delimiters
+          // However AnsiString constants can also appear without delimiters
           'a'..'z', 'A'..'Z', '_':
             begin
               while (I2 <= Len) and (AnExpr[I2] in ['a'..'z', 'A'..'Z', '_', '0'..'9']) do
@@ -917,13 +918,13 @@ var
           '+':
             begin
               Inc(I2);
-              if (AnExpr[I2] = '+') and FWordsList.Search(PChar('++'), I) then
+              if (AnExpr[I2] = '+') and FWordsList.Search(PAnsiChar('++'), I) then
                 Inc(I2);
             end;
           '-':
             begin
               Inc(I2);
-              if (AnExpr[I2] = '-') and FWordsList.Search(PChar('--'), I) then
+              if (AnExpr[I2] = '-') and FWordsList.Search(PAnsiChar('--'), I) then
                 Inc(I2);
             end;
           '^', '/', '\', '*', '(', ')', '%', '~', '$':
@@ -984,14 +985,14 @@ begin
       FConstantsList.Add(TempWord);
     end
     else if Length(W) > 0 then
-      if FWordsList.Search(PChar(W), I) then
+      if FWordsList.Search(PAnsiChar(W), I) then
       begin
         DestCollection.Add(FWordsList.Items[I])
       end else begin
         // unknown variable -> fire event
         HandleUnknownVariable(W);
         // try to search again
-        if FWordsList.Search(PChar(W), I) then
+        if FWordsList.Search(PAnsiChar(W), I) then
         begin
           DestCollection.Add(FWordsList.Items[I])
         end else begin
@@ -1046,10 +1047,10 @@ begin
         end;
         if K = -1 then
         begin
-          if FWordsList.Search(pchar('-@'), J) then
+          if FWordsList.Search(PAnsiChar('-@'), J) then
             Items[I] := FWordsList.Items[J];
         end
-        else if FWordsList.Search(pchar('+@'), J) then
+        else if FWordsList.Search(PAnsiChar('+@'), J) then
           Items[I] := FWordsList.Items[J];
       end;
       {----CHECK ON DOUBLE NOT----}
@@ -1105,7 +1106,7 @@ begin
       {-----CHECK ON INTPOWER------}
       if (TExprWord(Items[I]).Name = '^') and ((I < Count - 1) and
           (TExprWord(Items[I + 1]).ClassType = TIntegerConstant)) then
-        if FWordsList.Search(PChar('^@'), J) then
+        if FWordsList.Search(PAnsiChar('^@'), J) then
           Items[I] := FWordsList.Items[J]; //use the faster intPower if possible
       Inc(I);
     end;
@@ -1137,14 +1138,14 @@ begin
   end;
 end;
 
-function TCustomExpressionParser.DefineFunction(const AFunctName, AShortName, ADescription, ATypeSpec: string;
+function TCustomExpressionParser.DefineFunction(const AFunctName, AShortName, ADescription, ATypeSpec: AnsiString;
   AMinFunctionArg: Integer; AResultType: TExpressionType; AFuncAddress: TExprFunc): TExprWord;
 begin
   Result := TFunction.Create(AFunctName, AShortName, ATypeSpec, AMinFunctionArg, AResultType, AFuncAddress, ADescription);
   FWordsList.Add(Result);
 end;
 
-function TCustomExpressionParser.DefineIntegerVariable(const AVarName: string; AValue: PInteger; AIsNull: PBoolean): TExprWord;
+function TCustomExpressionParser.DefineIntegerVariable(const AVarName: AnsiString; AValue: PInteger; AIsNull: PBoolean): TExprWord;
 begin
   Result := TIntegerVariable.Create(AVarName, AValue, AIsNull);
   FWordsList.Add(Result);
@@ -1152,7 +1153,7 @@ end;
 
 {$ifdef SUPPORT_INT64}
 
-function TCustomExpressionParser.DefineLargeIntVariable(const AVarName: string; AValue: PLargeInt): TExprWord;
+function TCustomExpressionParser.DefineLargeIntVariable(const AVarName: AnsiString; AValue: PLargeInt): TExprWord;
 begin
   Result := TLargeIntVariable.Create(AVarName, AValue);
   FWordsList.Add(Result);
@@ -1160,25 +1161,26 @@ end;
 
 {$endif}
 
-function TCustomExpressionParser.DefineDateTimeVariable(const AVarName: string; AValue: PDateTimeRec): TExprWord;
+function TCustomExpressionParser.DefineDateTimeVariable(const AVarName: AnsiString; AValue: PDateTimeRec): TExprWord;
 begin
   Result := TDateTimeVariable.Create(AVarName, AValue);
   FWordsList.Add(Result);
 end;
 
-function TCustomExpressionParser.DefineBooleanVariable(const AVarName: string; AValue: PBoolean): TExprWord;
+function TCustomExpressionParser.DefineBooleanVariable(const AVarName: AnsiString; AValue: PBoolean): TExprWord;
 begin
   Result := TBooleanVariable.Create(AVarName, AValue);
   FWordsList.Add(Result);
 end;
 
-function TCustomExpressionParser.DefineFloatVariable(const AVarName: string; AValue: PDouble): TExprWord;
+function TCustomExpressionParser.DefineFloatVariable(const AVarName: AnsiString; AValue: PDouble): TExprWord;
 begin
   Result := TFloatVariable.Create(AVarName, AValue);
   FWordsList.Add(Result);
 end;
 
-function TCustomExpressionParser.DefineStringVariable(const AVarName: string; AValue: PPChar; AIsNull: PBoolean): TExprWord;
+function TCustomExpressionParser.DefineStringVariable(const AVarName: AnsiString; AValue: PPAnsiChar; AIsNull: PBoolean): TExprWord;
+
 begin
   Result := TStringVariable.Create(AVarName, AValue, AIsNull);
   FWordsList.Add(Result);
@@ -1234,7 +1236,7 @@ begin
   Result^.ResetDest := false;
 end;
 
-procedure TCustomExpressionParser.Evaluate(const AnExpression: string);
+procedure TCustomExpressionParser.Evaluate(const AnExpression: AnsiString);
 begin
   if Length(AnExpression) > 0 then
   begin
@@ -1243,7 +1245,7 @@ begin
   end;
 end;
 
-function TCustomExpressionParser.AddExpression(const AnExpression: string): Integer;
+function TCustomExpressionParser.AddExpression(const AnExpression: AnsiString): Integer;
 begin
   if Length(AnExpression) > 0 then
   begin
@@ -1261,17 +1263,17 @@ begin
   FLastRec := nil;
 end;
 
-function TCustomExpressionParser.GetFunctionDescription(const AFunction: string):
-  string;
+function TCustomExpressionParser.GetFunctionDescription(const AFunction: AnsiString): AnsiString;
+
 var
-  S: string;
+  S: AnsiString;
   p, I: Integer;
 begin
   S := AFunction;
   p := Pos('(', S);
   if p > 0 then
     S := Copy(S, 1, p - 1);
-  if FWordsList.Search(pchar(S), I) then
+  if FWordsList.Search(PAnsiChar(S), I) then
     Result := TExprWord(FWordsList.Items[I]).Description
   else
     Result := EmptyStr;
@@ -1280,7 +1282,7 @@ end;
 procedure TCustomExpressionParser.GetFunctionNames(AList: TStrings);
 var
   I, J: Integer;
-  S: string;
+  S: AnsiString;
 begin
   with FWordsList do
     for I := 0 to Count - 1 do
@@ -1317,7 +1319,7 @@ begin
       width := 18;
     if Args[2] <> nil then
       numDigits := PInteger(Args[2])^;
-    // convert to string
+    // convert to AnsiString
     Res.AssureSpace(width);
     extVal := PDouble(Args[0])^;
     resWidth := FloatToText(Res.MemoryPos^, extVal, {$ifndef FPC_VERSION}fvExtended,{$endif} ffFixed, 18, numDigits);
@@ -1327,7 +1329,7 @@ begin
     // result width smaller than requested width? -> add space to compensate
     if (Args[1] <> nil) and (resWidth < width) then
     begin
-      // move string so that it's right-aligned
+      // move AnsiString so that it's right-aligned
       Move(Res.MemoryPos^^, (Res.MemoryPos^)[width-resWidth], resWidth);
       // fill gap with spaces
       FillChar(Res.MemoryPos^^, width-resWidth, ' ');
@@ -1353,7 +1355,7 @@ begin
     // width specified?
     if Args[1] <> nil then
     begin
-      // convert to string
+      // convert to AnsiString
       width := PInteger(Args[1])^;
 {$ifdef SUPPORT_INT64}
       GetStrFromInt64_Width
@@ -1377,7 +1379,7 @@ begin
         Inc(Res.MemoryPos^, width);
       end;
     end else begin
-      // convert to string
+      // convert to AnsiString
       width := 
 {$ifdef SUPPORT_INT64}
         GetStrFromInt64
@@ -1409,14 +1411,16 @@ end;
 
 procedure FuncDateToStr(Param: PExpressionRec);
 var
-  TempStr: string;
+  TempStr: RTLstring;
+  lStr : AnsiString;
 begin
   with Param^ do
   begin
-    // create in temporary string
+    // create in temporary AnsiString
     DateTimeToString(TempStr, 'yyyymmdd', PDateTimeRec(Args[0])^.DateTime);
     // copy to buffer
-    Res.Append(PChar(TempStr), Length(TempStr));
+    lStr:=TempStr;
+    Res.Append(PAnsiChar(lStr), Length(lStr));
   end;
 end;
 
@@ -1452,7 +1456,7 @@ end;
 
 procedure FuncUppercase(Param: PExpressionRec);
 var
-  dest: PChar;
+  dest: PAnsiChar;
 begin
   with Param^ do
   begin
@@ -1466,7 +1470,7 @@ end;
 
 procedure FuncLowercase(Param: PExpressionRec);
 var
-  dest: PChar;
+  dest: PAnsiChar;
 begin
   with Param^ do
   begin
@@ -1733,14 +1737,14 @@ end;
 procedure FuncStrI_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) = 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrIComp(Args[0], Args[1]) = 0);
 end;
 
 procedure FuncStrIP_EQ(Param: PExpressionRec);
 var
   arg0len, arg1len: integer;
   match: boolean;
-  str0, str1: string;
+  str0, str1: AnsiString;
 begin
   with Param^ do
   begin
@@ -1770,38 +1774,38 @@ begin
     end else begin
       match := AnsiStrIComp(Args[0], Args[1]) = 0;
     end;
-    Res.MemoryPos^^ := Char(match);
+    Res.MemoryPos^^ := AnsiChar(match);
   end;
 end;
 
 procedure FuncStrI_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) <> 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrIComp(Args[0], Args[1]) <> 0);
 end;
 
 procedure FuncStrI_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) < 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrIComp(Args[0], Args[1]) < 0);
 end;
 
 procedure FuncStrI_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) > 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrIComp(Args[0], Args[1]) > 0);
 end;
 
 procedure FuncStrI_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) <= 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrIComp(Args[0], Args[1]) <= 0);
 end;
 
 procedure FuncStrI_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) >= 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrIComp(Args[0], Args[1]) >= 0);
 end;
 
 procedure FuncStrP_EQ(Param: PExpressionRec);
@@ -1836,199 +1840,199 @@ begin
     end else begin
       match := AnsiStrComp(Args[0], Args[1]) = 0;
     end;
-    Res.MemoryPos^^ := Char(match);
+    Res.MemoryPos^^ := AnsiChar(match);
   end;
 end;
 
 procedure FuncStr_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) = 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrComp(Args[0], Args[1]) = 0);
 end;
 
 procedure FuncStr_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) <> 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrComp(Args[0], Args[1]) <> 0);
 end;
 
 procedure FuncStr_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) < 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrComp(Args[0], Args[1]) < 0);
 end;
 
 procedure FuncStr_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) > 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrComp(Args[0], Args[1]) > 0);
 end;
 
 procedure FuncStr_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) <= 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrComp(Args[0], Args[1]) <= 0);
 end;
 
 procedure FuncStr_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) >= 0);
+    Res.MemoryPos^^ := AnsiChar(AnsiStrComp(Args[0], Args[1]) >= 0);
 end;
 
 procedure Func_SU_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PBoolean(Args[0]+StrLen(Args[0])+1)^);
+    Res.MemoryPos^^ := AnsiChar(PBoolean(Args[0]+StrLen(Args[0])+1)^);
 end;
 
 procedure Func_FF_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   =  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   =  PDouble(Args[1])^);
 end;
 
 procedure Func_FF_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <> PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <> PDouble(Args[1])^);
 end;
 
 procedure Func_FF_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <  PDouble(Args[1])^);
 end;
 
 procedure Func_FF_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   >  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   >  PDouble(Args[1])^);
 end;
 
 procedure Func_FF_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <= PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <= PDouble(Args[1])^);
 end;
 
 procedure Func_FF_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   >= PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   >= PDouble(Args[1])^);
 end;
 
 procedure Func_FI_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   =  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   =  PInteger(Args[1])^);
 end;
 
 procedure Func_FI_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <> PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <> PInteger(Args[1])^);
 end;
 
 procedure Func_FI_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <  PInteger(Args[1])^);
 end;
 
 procedure Func_FI_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   >  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   >  PInteger(Args[1])^);
 end;
 
 procedure Func_FI_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <= PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <= PInteger(Args[1])^);
 end;
 
 procedure Func_FI_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   >= PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   >= PInteger(Args[1])^);
 end;
 
 procedure Func_II_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  =  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  =  PInteger(Args[1])^);
 end;
 procedure Func_IU_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PBoolean(Args[0]+8)^);
+    Res.MemoryPos^^ := AnsiChar(PBoolean(Args[0]+8)^);
 end;
 
 procedure Func_II_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <> PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <> PInteger(Args[1])^);
 end;
 
 procedure Func_II_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <  PInteger(Args[1])^);
 end;
 
 procedure Func_II_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  >  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  >  PInteger(Args[1])^);
 end;
 
 procedure Func_II_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <= PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <= PInteger(Args[1])^);
 end;
 
 procedure Func_II_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  >= PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  >= PInteger(Args[1])^);
 end;
 
 procedure Func_IF_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  =  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  =  PDouble(Args[1])^);
 end;
 
 procedure Func_IF_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <> PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <> PDouble(Args[1])^);
 end;
 
 procedure Func_IF_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <  PDouble(Args[1])^);
 end;
 
 procedure Func_IF_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  >  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  >  PDouble(Args[1])^);
 end;
 
 procedure Func_IF_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <= PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <= PDouble(Args[1])^);
 end;
 
 procedure Func_IF_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  >= PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  >= PDouble(Args[1])^);
 end;
 
 {$ifdef SUPPORT_INT64}
@@ -2036,181 +2040,181 @@ end;
 procedure Func_LL_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    =  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    =  PInt64(Args[1])^);
 end;
 
 procedure Func_LL_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <> PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <> PInt64(Args[1])^);
 end;
 
 procedure Func_LL_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <  PInt64(Args[1])^);
 end;
 
 procedure Func_LL_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    >  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    >  PInt64(Args[1])^);
 end;
 
 procedure Func_LL_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <= PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <= PInt64(Args[1])^);
 end;
 
 procedure Func_LL_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    >= PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    >= PInt64(Args[1])^);
 end;
 
 procedure Func_LF_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    =  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    =  PDouble(Args[1])^);
 end;
 
 procedure Func_LF_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <> PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <> PDouble(Args[1])^);
 end;
 
 procedure Func_LF_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <  PDouble(Args[1])^);
 end;
 
 procedure Func_LF_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    >  PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    >  PDouble(Args[1])^);
 end;
 
 procedure Func_LF_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <= PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <= PDouble(Args[1])^);
 end;
 
 procedure Func_LF_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    >= PDouble(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    >= PDouble(Args[1])^);
 end;
 
 procedure Func_FL_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   =  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   =  PInt64(Args[1])^);
 end;
 
 procedure Func_FL_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <> PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <> PInt64(Args[1])^);
 end;
 
 procedure Func_FL_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <  PInt64(Args[1])^);
 end;
 
 procedure Func_FL_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   >  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   >  PInt64(Args[1])^);
 end;
 
 procedure Func_FL_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   <= PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   <= PInt64(Args[1])^);
 end;
 
 procedure Func_FL_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PDouble(Args[0])^   >= PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PDouble(Args[0])^   >= PInt64(Args[1])^);
 end;
 
 procedure Func_LI_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    =  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    =  PInteger(Args[1])^);
 end;
 
 procedure Func_LI_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <> PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <> PInteger(Args[1])^);
 end;
 
 procedure Func_LI_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <  PInteger(Args[1])^);
 end;
 
 procedure Func_LI_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    >  PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    >  PInteger(Args[1])^);
 end;
 
 procedure Func_LI_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    <= PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    <= PInteger(Args[1])^);
 end;
 
 procedure Func_LI_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInt64(Args[0])^    >= PInteger(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInt64(Args[0])^    >= PInteger(Args[1])^);
 end;
 
 procedure Func_IL_EQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  =  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  =  PInt64(Args[1])^);
 end;
 
 procedure Func_IL_NEQ(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <> PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <> PInt64(Args[1])^);
 end;
 
 procedure Func_IL_LT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <  PInt64(Args[1])^);
 end;
 
 procedure Func_IL_GT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  >  PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  >  PInt64(Args[1])^);
 end;
 
 procedure Func_IL_LTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  <= PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  <= PInt64(Args[1])^);
 end;
 
 procedure Func_IL_GTE(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(PInteger(Args[0])^  >= PInt64(Args[1])^);
+    Res.MemoryPos^^ := AnsiChar(PInteger(Args[0])^  >= PInt64(Args[1])^);
 end;
 
 {$endif}
@@ -2218,19 +2222,19 @@ end;
 procedure Func_AND(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(Boolean(Args[0]^) and Boolean(Args[1]^));
+    Res.MemoryPos^^ := AnsiChar(Boolean(Args[0]^) and Boolean(Args[1]^));
 end;
 
 procedure Func_OR(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(Boolean(Args[0]^) or Boolean(Args[1]^));
+    Res.MemoryPos^^ := AnsiChar(Boolean(Args[0]^) or Boolean(Args[1]^));
 end;
 
 procedure Func_NOT(Param: PExpressionRec);
 begin
   with Param^ do
-    Res.MemoryPos^^ := Char(not Boolean(Args[0]^));
+    Res.MemoryPos^^ := AnsiChar(not Boolean(Args[0]^));
 end;
 
 initialization

+ 127 - 127
packages/fcl-db/src/dbase/dbf_prsdef.pas

@@ -48,20 +48,20 @@ type
 
   TDynamicType = class(TObject)
   private
-    FMemory: PPChar;
-    FMemoryPos: PPChar;
+    FMemory: PPAnsiChar;
+    FMemoryPos: PPAnsiChar;
     FSize: PInteger;
   public
-    constructor Create(DestMem, DestPos: PPChar; ASize: PInteger);
+    constructor Create(DestMem, DestPos: PPAnsiChar; ASize: PInteger);
 
     procedure AssureSpace(ASize: Integer);
     procedure Resize(NewSize: Integer; Exact: Boolean);
     procedure Rewind;
-    procedure Append(Source: PChar; Length: Integer);
+    procedure Append(Source: PAnsiChar; Length: Integer);
     procedure AppendInteger(Source: Integer);
 
-    property Memory: PPChar read FMemory;
-    property MemoryPos: PPChar read FMemoryPos;
+    property Memory: PPAnsiChar read FMemory;
+    property MemoryPos: PPAnsiChar read FMemoryPos;
     property Size: PInteger read FSize;
   end;
 
@@ -74,8 +74,8 @@ type
     AuxData: pointer;
     ResetDest: boolean;
     WantsFunction: boolean;
-    Args: array[0..MaxArg-1] of PChar;
-    ArgsPos: array[0..MaxArg-1] of PChar;
+    Args: array[0..MaxArg-1] of PAnsiChar;
+    ArgsPos: array[0..MaxArg-1] of PAnsiChar;
     ArgsSize: array[0..MaxArg-1] of Integer;
     ArgsType: array[0..MaxArg-1] of TExpressionType;
     ArgList: array[0..MaxArg-1] of PExpressionRec;
@@ -88,8 +88,8 @@ type
   end;
 
   TExprWordRec = record
-    Name: PChar;
-    ShortName: PChar;
+    Name: PAnsiChar;
+    ShortName: PAnsiChar;
     IsOperator: Boolean;
     IsVariable: Boolean;
     IsFunction: Boolean;
@@ -99,8 +99,8 @@ type
     ResultType: TExpressionType;
     MinArg: Integer;
     MaxArg: Integer;
-    TypeSpec: PChar;
-    Description: PChar;
+    TypeSpec: PAnsiChar;
+    Description: PAnsiChar;
     ExprFunc: TExprFunc;
   end;
 
@@ -108,7 +108,7 @@ type
 
   TExprWord = class(TObject)
   private
-    FName: string;
+    FName: AnsiString;
     FExprFunc: TExprFunc;
   protected
     FRefCount: Cardinal;
@@ -121,14 +121,14 @@ type
     function GetResultType: TExpressionType; virtual;
     function GetMinFunctionArg: Integer; virtual;
     function GetMaxFunctionArg: Integer; virtual;
-    function GetDescription: string; virtual;
-    function GetTypeSpec: string; virtual;
-    function GetShortName: string; virtual;
+    function GetDescription: AnsiString; virtual;
+    function GetTypeSpec: AnsiString; virtual;
+    function GetShortName: AnsiString; virtual;
     procedure SetFixedLen(NewLen: integer); virtual;
   public
-    constructor Create(const AName: string; AExprFunc: TExprFunc);
+    constructor Create(const AName: AnsiString; AExprFunc: TExprFunc);
 
-    function AsPointer: PChar; virtual;
+    function AsPointer: PAnsiChar; virtual;
     function LenAsPointer: PInteger; virtual;
     function IsNullAsPointer: PBoolean; virtual;
     function IsFunction: Boolean; virtual;
@@ -142,10 +142,10 @@ type
     property ResultType: TExpressionType read GetResultType;
     property MinFunctionArg: Integer read GetMinFunctionArg;
     property MaxFunctionArg: Integer read GetMaxFunctionArg;
-    property Name: string read FName;
-    property ShortName: string read GetShortName;
-    property Description: string read GetDescription;
-    property TypeSpec: string read GetTypeSpec;
+    property Name: AnsiString read FName;
+    property ShortName: AnsiString read GetShortName;
+    property Description: AnsiString read GetDescription;
+    property TypeSpec: AnsiString read GetTypeSpec;
   end;
 
   TExpressShortList = class(TSortedCollection)
@@ -174,7 +174,7 @@ type
   protected
     function GetResultType: TExpressionType; override;
   public
-    constructor Create(const AName: string; AVarType: TExpressionType; AExprFunc: TExprFunc);
+    constructor Create(const AName: AnsiString; AVarType: TExpressionType; AExprFunc: TExprFunc);
   end;
 
   TFloatConstant = class(TConstant)
@@ -182,32 +182,32 @@ type
     FValue: Double;
   public
     // not overloaded to support older Delphi versions
-    constructor Create(const AName: string; const AValue: string);
-    constructor CreateAsDouble(const AName: string; AValue: Double);
+    constructor Create(const AName: AnsiString; AValue: AnsiString);
+    constructor CreateAsDouble(const AName: AnsiString; AValue: Double);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
 
     property Value: Double read FValue write FValue;
   end;
 
   TUserConstant = class(TFloatConstant)
   private
-    FDescription: string;
+    FDescription: AnsiString;
   protected
-    function GetDescription: string; override;
+    function GetDescription: AnsiString; override;
   public
-    constructor CreateAsDouble(Const AName, Descr: string; AValue: Double);
+    constructor CreateAsDouble(const AName, Descr: AnsiString; AValue: Double);
   end;
 
   TStringConstant = class(TConstant)
   private
-    FValue: string;
+    FValue: ansistring;
   public
     // Allow undelimited, delimited by single quotes, delimited by double quotes
-    // If delimited, allow escaping inside string with double delimiters
-    constructor Create(const AValue: string);
+    // If delimited, allow escaping inside AnsiString with double delimiters
+    constructor Create(const AValue: ansistring);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
   TIntegerConstant = class(TConstant)
@@ -216,7 +216,7 @@ type
   public
     constructor Create(AValue: Integer);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
 {$ifdef SUPPORT_INT64}
@@ -226,7 +226,7 @@ type
   public
     constructor Create(AValue: Int64);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 {$endif}
 
@@ -235,9 +235,9 @@ type
     FValue: Boolean;
   public
     // not overloaded to support older Delphi versions
-    constructor Create(const AName: string; AValue: Boolean);
+    constructor Create(const AName: AnsiString; AValue: Boolean);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
 
     property Value: Boolean read FValue write FValue;
   end;
@@ -260,7 +260,7 @@ type
     function GetCanVary: Boolean; override;
     function GetResultType: TExpressionType; override;
   public
-    constructor Create(const AName: string; AVarType: TExpressionType; AExprFunc: TExprFunc);
+    constructor Create(const AName: AnsiString; AVarType: TExpressionType; AExprFunc: TExprFunc);
     function IsNullAsPointer: PBoolean; override;
   end;
 
@@ -268,23 +268,23 @@ type
   private
     FValue: PDouble;
   public
-    constructor Create(const AName: string; AValue: PDouble);
+    constructor Create(const AName: AnsiString; AValue: PDouble);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
   TStringVariable = class(TVariable)
   private
-    FValue: PPChar;
+    FValue: PPAnsiChar;
     FFixedLen: Integer;
   protected
     function GetFixedLen: Integer; override;
     procedure SetFixedLen(NewLen: integer); override;
   public
-    constructor Create(const AName: string; AValue: PPChar; AIsNull: PBoolean);
+    constructor Create(const AName: AnsiString; AValue: PPAnsiChar; AIsNull: PBoolean);
 
     function LenAsPointer: PInteger; override;
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
 
     property FixedLen: Integer read FFixedLen;
   end;
@@ -293,18 +293,18 @@ type
   private
     FValue: PDateTimeRec;
   public
-    constructor Create(const AName: string; AValue: PDateTimeRec);
+    constructor Create(const AName: AnsiString; AValue: PDateTimeRec);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
   TIntegerVariable = class(TVariable)
   private
     FValue: PInteger;
   public
-    constructor Create(const AName: string; AValue: PInteger; AIsNull: PBoolean);
+    constructor Create(const AName: AnsiString; AValue: PInteger; AIsNull: PBoolean);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
 {$ifdef SUPPORT_INT64}
@@ -313,9 +313,9 @@ type
   private
     FValue: PLargeInt;
   public
-    constructor Create(const AName: string; AValue: PLargeInt);
+    constructor Create(const AName: AnsiString; AValue: PLargeInt);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
 {$endif}
@@ -324,9 +324,9 @@ type
   private
     FValue: PBoolean;
   public
-    constructor Create(const AName: string; AValue: PBoolean);
+    constructor Create(const AName: AnsiString; AValue: PBoolean);
 
-    function AsPointer: PChar; override;
+    function AsPointer: PAnsiChar; override;
   end;
 
   TLeftBracket = class(TExprWord)
@@ -349,30 +349,30 @@ type
     FOperPrec: Integer;
     FMinFunctionArg: Integer;
     FMaxFunctionArg: Integer;
-    FDescription: string;
-    FTypeSpec: string;
-    FShortName: string;
+    FDescription: AnsiString;
+    FTypeSpec: AnsiString;
+    FShortName: AnsiString;
     FResultType: TExpressionType;
   protected
-    function GetDescription: string; override;
+    function GetDescription: AnsiString; override;
     function GetIsOperator: Boolean; override;
     function GetMinFunctionArg: Integer; override;
     function GetMaxFunctionArg: Integer; override;
     function GetResultType: TExpressionType; override;
-    function GetTypeSpec: string; override;
-    function GetShortName: string; override;
+    function GetTypeSpec: AnsiString; override;
+    function GetShortName: AnsiString; override;
 
-    procedure InternalCreate(const AName, ATypeSpec: string; AMinFuncArg: Integer; AResultType: TExpressionType;
+    procedure InternalCreate(const AName, ATypeSpec: AnsiString; AMinFuncArg: Integer; AResultType: TExpressionType;
       AExprFunc: TExprFunc; AIsOperator: Boolean; AOperPrec: Integer);
   public
-    constructor Create(const AName, AShortName, ATypeSpec: string; AMinFuncArg: Integer; AResultType: TExpressionType; AExprFunc: TExprFunc; const Descr: string);
+    constructor Create(const AName, AShortName, ATypeSpec: AnsiString; AMinFuncArg: Integer; AResultType: TExpressionType; AExprFunc: TExprFunc; const Descr: AnsiString);
     // Create operator: name, param types used, result type, func addr, operator precedence
-    constructor CreateOper(const AName, ATypeSpec: string; AResultType: TExpressionType; AExprFunc: TExprFunc; AOperPrec: Integer);
+    constructor CreateOper(const AName, ATypeSpec: AnsiString; AResultType: TExpressionType; AExprFunc: TExprFunc; AOperPrec: Integer);
 
     function IsFunction: Boolean; override;
 
     property OperPrec: Integer read FOperPrec;
-    property TypeSpec: string read FTypeSpec;
+    property TypeSpec: AnsiString read FTypeSpec;
   end;
 
   TVaryingFunction = class(TFunction)
@@ -388,11 +388,11 @@ const
   ('a' in 'a,b') =True
   ('c' in 'a,b') =False}
 
-function ExprCharToExprType(ExprChar: Char): TExpressionType;
+function ExprCharToExprType(ExprChar: AnsiChar): TExpressionType;
 
 implementation
 
-function ExprCharToExprType(ExprChar: Char): TExpressionType;
+function ExprCharToExprType(ExprChar: AnsiChar): TExpressionType;
 begin
   case ExprChar of
     'B': Result := etBoolean;
@@ -433,10 +433,10 @@ begin
   begin
     length := PInteger(Args[1])^;
     if length = -1 then
-      length := StrLen(PPChar(Args[0])^);
-    Res.Append(PPChar(Args[0])^, length);
-    // NULL indicator (placed after NULL terminated string)
-    length := StrLen(PPChar(Args[0])^)+1;
+      length := StrLen(PPAnsiChar(Args[0])^);
+    Res.Append(PPAnsiChar(Args[0])^, length);
+    // NULL indicator (placed after NULL terminated AnsiString)
+    length := StrLen(PPAnsiChar(Args[0])^)+1;
     Res.AssureSpace(length+1);
     PBoolean(Res.Memory^+length)^ := Assigned(Args[2]) and PBoolean(Args[2])^;
   end;
@@ -479,7 +479,7 @@ end;
 
 { TExpressionWord }
 
-constructor TExprWord.Create(const AName: string; AExprFunc: TExprFunc);
+constructor TExprWord.Create(const AName: AnsiString; AExprFunc: TExprFunc);
 begin
   FName := AName;
   FExprFunc := AExprFunc;
@@ -490,12 +490,12 @@ begin
   Result := False;
 end;
 
-function TExprWord.GetDescription: string;
+function TExprWord.GetDescription: AnsiString;
 begin
   Result := EmptyStr;
 end;
 
-function TExprWord.GetShortName: string;
+function TExprWord.GetShortName: AnsiString;
 begin
   Result := EmptyStr;
 end;
@@ -526,7 +526,7 @@ begin
   Result := (@FExprFunc <> @_StringConstant)         and
 //            (@FExprFunc <> @_StringVariable)         and
 //            (@FExprFunc <> @_StringVariableFixedLen) and
-// string variable cannot be used as normal parameter
+// AnsiString variable cannot be used as normal parameter
 // because it is indirectly referenced and possibly
 // not null-terminated (fixed len)
             (@FExprFunc <> @_FloatVariable)          and
@@ -560,12 +560,12 @@ begin
   Result := etUnknown;
 end;
 
-function TExprWord.GetTypeSpec: string;
+function TExprWord.GetTypeSpec: AnsiString;
 begin
   Result := EmptyStr;
 end;
 
-function TExprWord.AsPointer: PChar;
+function TExprWord.AsPointer: PAnsiChar;
 begin
   Result := nil;
 end;
@@ -591,7 +591,7 @@ end;
 
 { TConstant }
 
-constructor TConstant.Create(const AName: string; AVarType: TExpressionType; AExprFunc: TExprFunc);
+constructor TConstant.Create(const AName: AnsiString; AVarType: TExpressionType; AExprFunc: TExprFunc);
 begin
   inherited Create(AName, AExprFunc);
 
@@ -605,7 +605,7 @@ end;
 
 { TFloatConstant }
 
-constructor TFloatConstant.Create(const AName, AValue: string);
+constructor TFloatConstant.Create(const AName, AValue: AnsiString);
 begin
   inherited Create(AName, etFloat, _FloatVariable);
 
@@ -615,36 +615,36 @@ begin
     FValue := 0.0;
 end;
 
-constructor TFloatConstant.CreateAsDouble(const AName: string; AValue: Double);
+constructor TFloatConstant.CreateAsDouble(const AName: AnsiString; AValue: Double);
 begin
   inherited Create(AName, etFloat, _FloatVariable);
 
   FValue := AValue;
 end;
 
-function TFloatConstant.AsPointer: PChar;
+function TFloatConstant.AsPointer: PAnsiChar;
 begin
-  Result := PChar(@FValue);
+  Result := PAnsiChar(@FValue);
 end;
 
 { TUserConstant }
 
-constructor TUserConstant.CreateAsDouble(const AName, Descr: string; AValue: Double);
+constructor TUserConstant.CreateAsDouble(const AName, Descr: AnsiString; AValue: Double);
 begin
   FDescription := Descr;
   inherited CreateAsDouble(AName, AValue);
 end;
 
-function TUserConstant.GetDescription: string;
+function TUserConstant.GetDescription: AnsiString;
 begin
   Result := FDescription;
 end;
 
 { TStringConstant }
 
-constructor TStringConstant.Create(const AValue: string);
+constructor TStringConstant.Create(const AValue: AnsiString);
 var
-  firstChar, lastChar: Char;
+  firstChar, lastChar: AnsiChar;
 begin
   inherited Create(AValue, etString, _StringConstant);
 
@@ -659,23 +659,23 @@ begin
     FValue := AValue;
 end;
 
-function TStringConstant.AsPointer: PChar;
+function TStringConstant.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 { TBooleanConstant }
 
-constructor TBooleanConstant.Create(const AName: string; AValue: Boolean);
+constructor TBooleanConstant.Create(const AName: AnsiString; AValue: Boolean);
 begin
   inherited Create(AName, etBoolean, _BooleanVariable);
 
   FValue := AValue;
 end;
 
-function TBooleanConstant.AsPointer: PChar;
+function TBooleanConstant.AsPointer: PAnsiChar;
 begin
-  Result := PChar(@FValue);
+  Result := PAnsiChar(@FValue);
 end;
 
 { TIntegerConstant }
@@ -687,9 +687,9 @@ begin
   FValue := AValue;
 end;
 
-function TIntegerConstant.AsPointer: PChar;
+function TIntegerConstant.AsPointer: PAnsiChar;
 begin
-  Result := PChar(@FValue);
+  Result := PAnsiChar(@FValue);
 end;
 
 {$ifdef SUPPORT_INT64}
@@ -702,9 +702,9 @@ begin
   FValue := AValue;
 end;
 
-function TLargeIntConstant.AsPointer: PChar;
+function TLargeIntConstant.AsPointer: PAnsiChar;
 begin
-  Result := PChar(@FValue);
+  Result := PAnsiChar(@FValue);
 end;
 {$endif}
 
@@ -717,7 +717,7 @@ end;
 
 { TVariable }
 
-constructor TVariable.Create(const AName: string; AVarType: TExpressionType; AExprFunc: TExprFunc);
+constructor TVariable.Create(const AName: AnsiString; AVarType: TExpressionType; AExprFunc: TExprFunc);
 begin
   inherited Create(AName, AExprFunc);
 
@@ -741,33 +741,33 @@ end;
 
 { TFloatVariable }
 
-constructor TFloatVariable.Create(const AName: string; AValue: PDouble);
+constructor TFloatVariable.Create(const AName: AnsiString; AValue: PDouble);
 begin
   inherited Create(AName, etFloat, _FloatVariable);
   FValue := AValue;
 end;
 
-function TFloatVariable.AsPointer: PChar;
+function TFloatVariable.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 { TStringVariable }
 
-constructor TStringVariable.Create(const AName: string; AValue: PPChar; AIsNull: PBoolean);
+constructor TStringVariable.Create(const AName: AnsiString; AValue: PPAnsiChar; AIsNull: PBoolean);
 begin
   // variable or fixed length?
   inherited Create(AName, etString, _StringVariable);
 
-  // store pointer to string
+  // store pointer to AnsiString
   FValue := AValue;
   FFixedLen := -1;
   FIsNull := AIsNull;
 end;
 
-function TStringVariable.AsPointer: PChar;
+function TStringVariable.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 function TStringVariable.GetFixedLen: Integer;
@@ -787,59 +787,59 @@ end;
 
 { TDateTimeVariable }
 
-constructor TDateTimeVariable.Create(const AName: string; AValue: PDateTimeRec);
+constructor TDateTimeVariable.Create(const AName: AnsiString; AValue: PDateTimeRec);
 begin
   inherited Create(AName, etDateTime, _DateTimeVariable);
   FValue := AValue;
 end;
 
-function TDateTimeVariable.AsPointer: PChar;
+function TDateTimeVariable.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 { TIntegerVariable }
 
-constructor TIntegerVariable.Create(const AName: string; AValue: PInteger; AIsNull: PBoolean);
+constructor TIntegerVariable.Create(const AName: AnsiString; AValue: PInteger; AIsNull: PBoolean);
 begin
   inherited Create(AName, etInteger, _IntegerVariable);
   FValue := AValue;
   FIsNull := AIsNull;
 end;
 
-function TIntegerVariable.AsPointer: PChar;
+function TIntegerVariable.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 {$ifdef SUPPORT_INT64}
 
 { TLargeIntVariable }
 
-constructor TLargeIntVariable.Create(const AName: string; AValue: PLargeInt);
+constructor TLargeIntVariable.Create(const AName: AnsiString; AValue: PLargeInt);
 begin
   inherited Create(AName, etLargeInt, _LargeIntVariable);
   FValue := AValue;
 end;
 
-function TLargeIntVariable.AsPointer: PChar;
+function TLargeIntVariable.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 {$endif}
 
 { TBooleanVariable }
 
-constructor TBooleanVariable.Create(const AName: string; AValue: PBoolean);
+constructor TBooleanVariable.Create(const AName: AnsiString; AValue: PBoolean);
 begin
   inherited Create(AName, etBoolean, _BooleanVariable);
   FValue := AValue;
 end;
 
-function TBooleanVariable.AsPointer: PChar;
+function TBooleanVariable.AsPointer: PAnsiChar;
 begin
-  Result := PChar(FValue);
+  Result := PAnsiChar(FValue);
 end;
 
 { TLeftBracket }
@@ -897,12 +897,12 @@ end;
 
 function TExpressList.Compare(Key1, Key2: Pointer): Integer;
 begin
-  Result := StrIComp(PChar(Key1), PChar(Key2));
+  Result := StrIComp(PAnsiChar(Key1), PAnsiChar(Key2));
 end;
 
 function TExpressList.KeyOf(Item: Pointer): Pointer;
 begin
-  Result := PChar(TExprWord(Item).Name);
+  Result := PAnsiChar(TExprWord(Item).Name);
 end;
 
 procedure TExpressList.FreeItem(Item: Pointer);
@@ -928,12 +928,12 @@ end;
 
 function TExpressShortList.Compare(Key1, Key2: Pointer): Integer;
 begin
-  Result := StrIComp(PChar(Key1), PChar(Key2));
+  Result := StrIComp(PAnsiChar(Key1), PAnsiChar(Key2));
 end;
 
 function TExpressShortList.KeyOf(Item: Pointer): Pointer;
 begin
-  Result := PChar(TExprWord(Item).ShortName);
+  Result := PAnsiChar(TExprWord(Item).ShortName);
 end;
 
 procedure TExpressShortList.FreeItem(Item: Pointer);
@@ -988,8 +988,8 @@ end;
 
 { TFunction }
 
-constructor TFunction.Create(const AName, AShortName, ATypeSpec: string; AMinFuncArg: Integer; AResultType: TExpressionType;
-  AExprFunc: TExprFunc; const Descr: string);
+constructor TFunction.Create(const AName, AShortName, ATypeSpec: AnsiString; AMinFuncArg: Integer; AResultType: TExpressionType;
+  AExprFunc: TExprFunc; const Descr: AnsiString);
 begin
   //to increase compatibility don't use default parameters
   FDescription := Descr;
@@ -997,13 +997,13 @@ begin
   InternalCreate(AName, ATypeSpec, AMinFuncArg, AResultType, AExprFunc, false, 0);
 end;
 
-constructor TFunction.CreateOper(const AName, ATypeSpec: string; AResultType: TExpressionType;
+constructor TFunction.CreateOper(const AName, ATypeSpec: AnsiString; AResultType: TExpressionType;
   AExprFunc: TExprFunc; AOperPrec: Integer);
 begin
   InternalCreate(AName, ATypeSpec, -1, AResultType, AExprFunc, true, AOperPrec);
 end;
 
-procedure TFunction.InternalCreate(const AName, ATypeSpec: string; AMinFuncArg: Integer; AResultType: TExpressionType;
+procedure TFunction.InternalCreate(const AName, ATypeSpec: AnsiString; AMinFuncArg: Integer; AResultType: TExpressionType;
   AExprFunc: TExprFunc; AIsOperator: Boolean; AOperPrec: Integer);
 begin
   inherited Create(AName, AExprFunc);
@@ -1022,7 +1022,7 @@ begin
     raise EParserException.Create('Too many arguments');
 end;
 
-function TFunction.GetDescription: string;
+function TFunction.GetDescription: AnsiString;
 begin
   Result := FDescription;
 end;
@@ -1047,12 +1047,12 @@ begin
   Result := FResultType;
 end;
 
-function TFunction.GetShortName: string;
+function TFunction.GetShortName: AnsiString;
 begin
   Result := FShortName;
 end;
 
-function TFunction.GetTypeSpec: string;
+function TFunction.GetTypeSpec: AnsiString;
 begin
   Result := FTypeSpec;
 end;
@@ -1071,7 +1071,7 @@ end;
 
 { TDynamicType }
 
-constructor TDynamicType.Create(DestMem, DestPos: PPChar; ASize: PInteger);
+constructor TDynamicType.Create(DestMem, DestPos: PPAnsiChar; ASize: PInteger);
 begin
   inherited Create;
 
@@ -1094,7 +1094,7 @@ end;
 
 procedure TDynamicType.Resize(NewSize: Integer; Exact: Boolean);
 var
-  tempBuf: PChar;
+  tempBuf: PAnsiChar;
   bytesCopy, pos: Integer;
 begin
   // if not exact requested make newlength a multiple of ArgAllocSize
@@ -1107,7 +1107,7 @@ begin
   if bytesCopy > NewSize then
     bytesCopy := NewSize;
   Move(FMemory^^, tempBuf^, bytesCopy);
-  // save position in string
+  // save position in AnsiString
   pos := FMemoryPos^ - FMemory^;
   // delete old mem
   FreeMem(FMemory^);
@@ -1118,9 +1118,9 @@ begin
   FMemoryPos^ := FMemory^ + pos;
 end;
 
-procedure TDynamicType.Append(Source: PChar; Length: Integer);
+procedure TDynamicType.Append(Source: PAnsiChar; Length: Integer);
 begin
-  // make room for string plus null-terminator
+  // make room for AnsiString plus null-terminator
   AssureSpace(Length+4);
   // copy
   Move(Source^, FMemoryPos^^, Length);

+ 14 - 14
packages/fcl-db/src/dbase/dbf_prssupp.pas

@@ -62,11 +62,11 @@ type
     procedure FreeItem(Item: Pointer); override;
   end;
 
-function GetStrFromInt(Val: Integer; const Dst: PChar): Integer;
-procedure GetStrFromInt_Width(Val: Integer; const Width: Integer; const Dst: PChar; const PadChar: Char);
+function GetStrFromInt(Val: Integer; const Dst: PAnsiChar): Integer;
+procedure GetStrFromInt_Width(Val: Integer; const Width: Integer; const Dst: PAnsiChar; const PadChar: AnsiChar);
 {$ifdef SUPPORT_INT64}
-function  GetStrFromInt64(Val: Int64; const Dst: PChar): Integer;
-procedure GetStrFromInt64_Width(Val: Int64; const Width: Integer; const Dst: PChar; const PadChar: Char);
+function  GetStrFromInt64(Val: Int64; const Dst: PAnsiChar): Integer;
+procedure GetStrFromInt64_Width(Val: Int64; const Width: Integer; const Dst: PAnsiChar; const PadChar: AnsiChar);
 {$endif}
 
 implementation
@@ -199,12 +199,12 @@ begin
   StrDispose(Item);
 end;
 
-// it seems there is no pascal function to convert an integer into a PChar???
+// it seems there is no pascal function to convert an integer into a PAnsiChar???
 // NOTE: in dbf_dbffile.pas there is also a convert routine, but is slightly different
 
-function GetStrFromInt(Val: Integer; const Dst: PChar): Integer;
+function GetStrFromInt(Val: Integer; const Dst: PAnsiChar): Integer;
 var
-  Temp: array[0..10] of Char;
+  Temp: array[0..10] of AnsiChar;
   I, J: Integer;
 begin
   Val := Abs(Val);
@@ -228,11 +228,11 @@ begin
   // done!
 end;
 
-// it seems there is no pascal function to convert an integer into a PChar???
+// it seems there is no pascal function to convert an integer into a PAnsiChar???
 
-procedure GetStrFromInt_Width(Val: Integer; const Width: Integer; const Dst: PChar; const PadChar: Char);
+procedure GetStrFromInt_Width(Val: Integer; const Width: Integer; const Dst: PAnsiChar; const PadChar: AnsiChar);
 var
-  Temp: array[0..10] of Char;
+  Temp: array[0..10] of AnsiChar;
   I, J: Integer;
   NegSign: boolean;
 begin
@@ -241,18 +241,18 @@ end;
 
 {$ifdef SUPPORT_INT64}
 
-procedure GetStrFromInt64_Width(Val: Int64; const Width: Integer; const Dst: PChar; const PadChar: Char);
+procedure GetStrFromInt64_Width(Val: Int64; const Width: Integer; const Dst: PAnsiChar; const PadChar: AnsiChar);
 var
-  Temp: array[0..19] of Char;
+  Temp: array[0..19] of AnsiChar;
   I, J: Integer;
   NegSign: boolean;
 begin
   {$I getstrfromint.inc}
 end;
 
-function GetStrFromInt64(Val: Int64; const Dst: PChar): Integer;
+function GetStrFromInt64(Val: Int64; const Dst: PAnsiChar): Integer;
 var
-  Temp: array[0..19] of Char;
+  Temp: array[0..19] of AnsiChar;
   I, J: Integer;
 begin
   Val := Abs(Val);

+ 1 - 1
packages/fcl-db/src/dbase/dbf_reg.pas

@@ -348,7 +348,7 @@ begin
   RegisterPropertyEditor(TypeInfo(string), TDbf, 'IndexName', TIndexNameProperty);
   RegisterPropertyEditor(TypeInfo(string), TDbfIndexDef, 'IndexFile', TIndexFileNameProperty);
   RegisterPropertyEditor(TypeInfo(string), TDbfIndexDef, 'SortField', TSortFieldProperty);
-  RegisterPropertyEditor(TypeInfo(char), TDbfFieldDef, 'NativeFieldType', TNativeFieldTypeProperty);
+  RegisterPropertyEditor(TypeInfo(AnsiChar), TDbfFieldDef, 'NativeFieldType', TNativeFieldTypeProperty);
 end;
 
 {$ifdef FPC}

+ 9 - 9
packages/fcl-db/src/dbase/dbf_struct.inc

@@ -58,7 +58,7 @@ type
   // before the variable length part (e.g. the field descriptor array)
   PEndFixedHdrVII = ^rEndFixedHdrVII;
   rEndFixedHdrVII = packed record
-    LanguageDriverName  : array[32..63] of Char; //starting position 32 of header
+    LanguageDriverName  : array[32..63] of AnsiChar; //starting position 32 of header
     Dummy               : array[64..67] of Byte;
   end;
 //====================================================================
@@ -68,14 +68,14 @@ type
     { Relative path of an associated database (.dbc) file or filled with $00.
       If the first byte is $00, the file is a "free table", not associated with
       a database file. Therefore, database files always contain $00. }
-    Backlink  : array[0..262] of Char; //263 bytees
+    Backlink  : array[0..262] of AnsiChar; //263 bytees
   end;
 //====================================================================
 // DBase III,IV,FoxPro,VisualFoxPro field description
   PFieldDescIII = ^rFieldDescIII;
   rFieldDescIII = packed record
-    FieldName         : array[0..10] of Char;
-    FieldType         : Char;    // 11
+    FieldName         : array[0..10] of AnsiChar;
+    FieldType         : AnsiChar;    // 11
     // FieldOffset: (V)FoxPro only: displacement of field in record
     // DBase III uses it for address in memory
     FieldOffset       : Integer; // 12..15
@@ -83,7 +83,7 @@ type
     FieldPrecision    : Byte;    // 17, also known as decimal count
     // $01: system solumn (not user-visible)
     // $02: column can store null values
-    // $04: binary column, e.g. don't interpret codepage (char/memo fields)
+    // $04: binary column, e.g. don't interpret codepage (AnsiChar/memo fields)
     // $0C: column is autoincrementing (only integer fields)
     VisualFoxProFlags : Byte;    // 18 Field Flags; flags can be combined
     // (!!not the next value for a new record!!); the next is calculated by
@@ -104,8 +104,8 @@ type
 //====================================================================
 // OH 2000-11-15 dBase7 support. Header Update (add fields like Next AutoInc Value)
   rFieldDescVII = packed record
-    FieldName      : array [0..31] of Char;
-    FieldType      : Char;  // 32
+    FieldName      : array [0..31] of AnsiChar;
+    FieldType      : AnsiChar;  // 32
     FieldSize      : Byte;  // 33
     FieldPrecision : Byte;  // 34
     Reserved1      : Word;  // 35-36
@@ -142,7 +142,7 @@ type
                           //            06 Database constraint
     FieldType    : Byte;  // 5      ; Field Type:
                           //            00 No type - constraint
-                          //            01 Char
+                          //            01 AnsiChar
                           //            02 Numeric
                           //            03 Memo
                           //            04 Logical
@@ -155,7 +155,7 @@ type
                           //            13 Double
                           //            14 AutoIncrement (not settable from the Inspector)
     IsConstraint : Byte;  // 6      ; 0x00 if the array element is a constraint, 0x02 otherwise.
-    Reserved     : array[7..10] of Char;
+    Reserved     : array[7..10] of AnsiChar;
     DataOffset   : Word;  // 11..12 ; Offset from the start of this structure to the data for the property. The Required property has no data associated with it, so it is always 0.
     DataSize     : Word;  // 13..14 ; Width of database field associated with the property, and hence size of the data (includes 0 terminator in the case of a constraint).
   end;

+ 7 - 7
packages/fcl-db/src/dbase/dbf_wnix.inc

@@ -222,7 +222,7 @@ end;
 
 {$ifdef HUNGARIAN}
 
-procedure OemHunHun(AnsiDst: PChar; cchDstLength: DWORD);
+procedure OemHunHun(AnsiDst: PAnsiChar; cchDstLength: DWORD);
 var
   Count: DWORD;
 begin
@@ -255,7 +255,7 @@ begin
   end;
 end;
 
-procedure AnsiHunHun(AnsiDst: PChar; cchDstLength: DWORD);
+procedure AnsiHunHun(AnsiDst: PAnsiChar; cchDstLength: DWORD);
 var
   Count: DWORD;
 begin
@@ -290,21 +290,21 @@ end;
 
 {$endif}
 
-function OemToChar(lpszSrc: PChar; lpszDst: PChar): BOOL;
+function OemToChar(lpszSrc: PAnsiChar; lpszDst: PAnsiChar): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrCopy(lpszDst, lpszSrc);
   Result := true;
 end;
 
-function CharToOem(lpszSrc: PChar; lpszDst: PChar): BOOL;
+function CharToOem(lpszSrc: PAnsiChar; lpszDst: PAnsiChar): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrCopy(lpszDst, lpszSrc);
   Result := true;
 end;
 
-function OemToCharBuffA(lpszSrc: PChar; lpszDst: PChar; cchDstLength: DWORD): BOOL;
+function OemToCharBuffA(lpszSrc: PAnsiChar; lpszDst: PAnsiChar; cchDstLength: DWORD): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrLCopy(lpszDst, lpszSrc, cchDstLength);
@@ -314,7 +314,7 @@ begin
   Result := true;
 end;
 
-function CharToOemBuffA(lpszSrc: PChar; lpszDst: PChar; cchDstLength: DWORD): BOOL;
+function CharToOemBuffA(lpszSrc: PAnsiChar; lpszDst: PAnsiChar; cchDstLength: DWORD): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrLCopy(lpszDst, lpszSrc, cchDstLength);
@@ -346,7 +346,7 @@ begin
   System.Move(TempA, lpMultiByteStr^, Result);
 end;
 
-function CompareString(Locale: LCID; dwCmpFlags: DWORD; lpString1: PChar; cchCount1: Integer; lpString2: PChar; cchCount2: Integer): Integer;
+function CompareString(Locale: LCID; dwCmpFlags: DWORD; lpString1: PAnsiChar; cchCount1: Integer; lpString2: PAnsiChar; cchCount2: Integer): Integer;
 begin
   Result := StrLComp(lpString1, lpString2, cchCount1) + 2;
   if Result > 2 then Result := 3;

+ 14 - 14
packages/fcl-db/src/dbase/dbf_wos2.inc

@@ -683,28 +683,28 @@ begin
   Result := DefaultSystemCodePage;
 end;
 
-function OemToChar(lpszSrc: PChar; lpszDst: PChar): BOOL;
+function OemToChar(lpszSrc: PAnsiChar; lpszDst: PAnsiChar): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrCopy(lpszDst, lpszSrc);
   Result := true;
 end;
 
-function CharToOem(lpszSrc: PChar; lpszDst: PChar): BOOL;
+function CharToOem(lpszSrc: PAnsiChar; lpszDst: PAnsiChar): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrCopy(lpszDst, lpszSrc);
   Result := true;
 end;
 
-function OemToCharBuffA(lpszSrc: PChar; lpszDst: PChar; cchDstLength: DWORD): BOOL;
+function OemToCharBuffA(lpszSrc: PAnsiChar; lpszDst: PAnsiChar; cchDstLength: DWORD): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrLCopy(lpszDst, lpszSrc, cchDstLength);
   Result := true;
 end;
 
-function CharToOemBuffA(lpszSrc: PChar; lpszDst: PChar; cchDstLength: DWORD): BOOL;
+function CharToOemBuffA(lpszSrc: PAnsiChar; lpszDst: PAnsiChar; cchDstLength: DWORD): BOOL;
 begin
   if lpszDst <> lpszSrc then
     StrLCopy(lpszDst, lpszSrc, cchDstLength);
@@ -755,7 +755,7 @@ begin
    end;
 end;
 
-function CompareString(Locale: LCID; dwCmpFlags: DWORD; lpString1: PChar; cchCount1: Integer; lpString2: PChar; cchCount2: Integer): Integer;
+function CompareString(Locale: LCID; dwCmpFlags: DWORD; lpString1: PAnsiChar; cchCount1: Integer; lpString2: PAnsiChar; cchCount2: Integer): Integer;
 begin
 {$WARNING To be rewritten using the UnicodeStringManager and LIBUNI.DLL functionality!}
   Result := StrLComp(lpString1, lpString2, cchCount1) + 2;
@@ -766,7 +766,7 @@ end;
 function EnumSystemCodePages(lpCodePageEnumProc: TFNCodepageEnumProc; dwFlags: DWORD): BOOL;
 
 type
-  TCodePagesProc = function (CodePageString: PChar): Cardinal; stdcall;
+  TCodePagesProc = function (CodePageString: PAnsiChar): Cardinal; stdcall;
 
 var
   CP: word;
@@ -793,7 +793,7 @@ begin
   if not (UniAPI) then
    begin
     Str (DefaultSystemCodepage, S);
-    CPProc (PChar (S));
+    CPProc (PAnsiChar (S));
    end
   else
    begin
@@ -801,22 +801,22 @@ begin
 (* Skip higher numbers which are not supported under OS/2 anyway *)
 (* and testing them would take considerable amount of time.      *)
      if TestCPNum then
-      CPProc (PChar (S));
+      CPProc (PAnsiChar (S));
     CP := 4946;
     if TestCPNum then
 (* This one might be recognized... *)
-     CPProc (PChar (S));
+     CPProc (PAnsiChar (S));
     CP := 28709;
     if TestCPNum then
 (* ...and this one as well. *)
-     CPProc (PChar (S));
+     CPProc (PAnsiChar (S));
    end;
   Result := True;
 end;
 
 function EnumSystemLocales(lpLocaleEnumProc: TFNLocaleEnumProc; dwFlags: DWORD): BOOL;
 type
-  TLocaleProc = function (LocaleString: PChar): Integer; stdcall;
+  TLocaleProc = function (LocaleString: PAnsiChar): Integer; stdcall;
 var
   S: AnsiString;
   Loc: PtrInt;
@@ -827,10 +827,10 @@ begin
     for Loc := MinRealLocale to High (LocaleMap) do
      begin
       S := LocaleMap [Loc].LangCode + LocaleMap [Loc].SubLangCode;
-      if Sys_UniCreateLocaleObject (2, PChar (S), LocObj) = 0 then
+      if Sys_UniCreateLocaleObject (2, PAnsiChar (S), LocObj) = 0 then
        begin
         S := HexStr (Pointer (PtrUInt (LocaleMap [Loc].LCID)));
-        TLocaleProc (lpLocaleEnumProc) (PChar (S));
+        TLocaleProc (lpLocaleEnumProc) (PAnsiChar (S));
         Sys_UniFreeLocaleObject (LocObj);
        end;
      end;
@@ -838,7 +838,7 @@ begin
   else
    begin
     Str (GetUserDefaultLCID, S);
-    TLocaleProc (lpLocaleEnumProc) (PChar (S));
+    TLocaleProc (lpLocaleEnumProc) (PAnsiChar (S));
    end;
   Result := True;
 end;

+ 5 - 5
packages/fcl-db/src/dbase/dbf_wtil.pas

@@ -274,13 +274,13 @@ function UnlockFile(hFile: THandle; dwFileOffsetLow, dwFileOffsetHigh: DWORD; nN
 procedure GetLocalTime(var lpSystemTime: TSystemTime);
 function GetOEMCP: Cardinal;
 function GetACP: Cardinal;
-function OemToChar(lpszSrc: PChar; lpszDst: PChar): BOOL;
-function CharToOem(lpszSrc: PChar; lpszDst: PChar): BOOL;
-function OemToCharBuffA(lpszSrc: PChar; lpszDst: PChar; cchDstLength: DWORD): BOOL;
-function CharToOemBuffA(lpszSrc: PChar; lpszDst: PChar; cchDstLength: DWORD): BOOL;
+function OemToChar(lpszSrc: PAnsiChar; lpszDst: PAnsiChar): BOOL;
+function CharToOem(lpszSrc: PAnsiChar; lpszDst: PAnsiChar): BOOL;
+function OemToCharBuffA(lpszSrc: PAnsiChar; lpszDst: PAnsiChar; cchDstLength: DWORD): BOOL;
+function CharToOemBuffA(lpszSrc: PAnsiChar; lpszDst: PAnsiChar; cchDstLength: DWORD): BOOL;
 function MultiByteToWideChar(CodePage: DWORD; dwFlags: DWORD; const lpMultiByteStr: LPCSTR; cchMultiByte: Integer; lpWideCharStr: LPWSTR; cchWideChar: Integer): Integer;
 function WideCharToMultiByte(CodePage: DWORD; dwFlags: DWORD; lpWideCharStr: LPWSTR; cchWideChar: Integer; lpMultiByteStr: LPSTR; cchMultiByte: Integer; lpDefaultChar: LPCSTR; lpUsedDefaultChar: PBOOL): Integer;
-function CompareString(Locale: LCID; dwCmpFlags: DWORD; lpString1: PChar; cchCount1: Integer; lpString2: PChar; cchCount2: Integer): Integer;
+function CompareString(Locale: LCID; dwCmpFlags: DWORD; lpString1: PAnsiChar; cchCount1: Integer; lpString2: PAnsiChar; cchCount2: Integer): Integer;
 function EnumSystemCodePages(lpCodePageEnumProc: TFNCodepageEnumProc; dwFlags: DWORD): BOOL;
 function EnumSystemLocales(lpLocaleEnumProc: TFNLocaleEnumProc; dwFlags: DWORD): BOOL;
 function GetUserDefaultLCID: LCID;

+ 3 - 3
packages/fcl-db/src/export/fpcsvexport.pp

@@ -30,12 +30,12 @@ Type
     FHeaderRow: Boolean;
     FIgnoreOuterWhiteSpace: Boolean;
     FRowDelimiter: String;
-    FQuoteChar: Char;
+    FQuoteChar: AnsiChar;
   Public
     Constructor Create(DoInitSettings : Boolean); override;
     Procedure Assign(Source : TPersistent); override;
     // Kept for compatibility with older versions; please replace with QuoteChar
-    Property StringQuoteChar : Char Read FQuoteChar Write FQuoteChar; deprecated 'Please replace with QuoteChar';
+    Property StringQuoteChar : AnsiChar Read FQuoteChar Write FQuoteChar; deprecated 'Please replace with QuoteChar';
   Published
     // Properties
     // Delimiter between fields/columns. Traditionally , for CSV.
@@ -47,7 +47,7 @@ Type
     // Whether or not the file should have a header row with field names
     Property HeaderRow : Boolean Read FHeaderRow Write FHeaderRow default true;
     // If fields need to be surrounded by quotes, use this character (e.g. ")
-    Property QuoteChar : Char Read FQuoteChar Write FQuoteChar;
+    Property QuoteChar : AnsiChar Read FQuoteChar Write FQuoteChar;
   end;
 
   { TCustomCSVExporter }

+ 3 - 3
packages/fcl-db/src/export/fpdbexport.pp

@@ -24,7 +24,7 @@ uses
 Type
   TCustomDatasetExporter = Class;
 
-  // Quote string fields if value contains a space or delimiter char.
+  // Quote string fields if value contains a space or delimiter AnsiChar.
   TQuoteString = (qsAlways,qsSpace,qsDelimiter);
   TQuoteStrings = Set of TQuoteString;
 
@@ -86,14 +86,14 @@ Type
     FHandleNullField: Boolean;
     FTimeFormat : String;
     FDateTimeFormat : String;
-    FDecimalSeparator: Char;
+    FDecimalSeparator: AnsiChar;
     FUseDisplayText : Boolean;
   Protected
     Procedure InitSettings; virtual;
     Property HandleNullField : Boolean Read FHandleNullField Write FHandleNullField;
     Property UseDisplayText : Boolean Read FUseDisplayText Write FUseDisplayText;
     Property IntegerFormat : String Read FIntegerFormat Write FIntegerFormat;
-    Property DecimalSeparator : Char Read FDecimalSeparator Write FDecimalSeparator;
+    Property DecimalSeparator : AnsiChar Read FDecimalSeparator Write FDecimalSeparator;
     Property CurrencySymbol : String Read FCurrencySymbol Write FCurrencySymbol;
     Property CurrencyDigits : Integer Read FCurrencyDigits Write FCurrencyDigits;
     Property BooleanTrue : String Read FBooleanTrue Write FBooleanTrue;

+ 2 - 2
packages/fcl-db/src/export/fpsimplejsonexport.pp

@@ -149,14 +149,14 @@ function TCustomSimpleJSONExporter.TextString(const S: String): String;
 
 Var
   I,J,L : Integer;
-  P : Pchar;
+  P : PAnsiChar;
 
 begin
   I:=1;
   J:=1;
   Result:='';
   L:=Length(S);
-  P:=PChar(S);
+  P:=PAnsiChar(S);
   While I<=L do
     begin
     if (P^ in ['"','/','\',#8,#9,#10,#12,#13]) then

+ 3 - 3
packages/fcl-db/src/export/fptexexport.pp

@@ -136,14 +136,14 @@ function TCustomTexExporter.EscapeLaTeX(const S: String): String;
 
 Var
   I,J,L : Integer;
-  P : Pchar;
+  P : PAnsiChar;
 
 begin
   I:=1;
   J:=1;
   Result:='';
   L:=Length(S);
-  P:=PChar(S);
+  P:=PAnsiChar(S);
   While I<=L do
     begin
     if (P^ in ['&','{','}','#','_','$','%']) then
@@ -224,7 +224,7 @@ end;
 procedure TCustomTeXExporter.DoDataHeader;
 
 Const
-  AlChars : Array[TAlignment] of char = 'lcr';
+  AlChars : Array[TAlignment] of AnsiChar = 'lcr';
 
 Var
   I,TW : Integer;

+ 9 - 9
packages/fcl-db/src/paradox/paradox.pp

@@ -492,7 +492,7 @@ begin
   If (BFN<>'') then
     begin
     //Writeln('opening blib file',bfn);
-    if PX_set_blob_file(FDoc,PChar(BFN))<>0 then
+    if PX_set_blob_file(FDoc,PAnsiChar(BFN))<>0 then
       RaiseError(SErrInvalidBlobFile,[BFN]);
     FBlobFileName:=BFN;
     end;
@@ -510,7 +510,7 @@ begin
   FN:=FFileName;
   FDoc:=PX_New();
   try
-    If (px_open_file(FDoc,PChar(FN))<>0) then
+    If (px_open_file(FDoc,PAnsiChar(FN))<>0) then
       RaiseError(SErrFailedToOpenFile,[FN]);
     SetOpenParams;
     OpenBlobFile;
@@ -640,11 +640,11 @@ var
   Buf          : TRecordbuffer;
   No,pft,flen : integer;
   pxf          : PPx_field;
-  Value        : Pchar;
+  Value        : PAnsiChar;
   D            : clong;
   longv        : Clong;
   R            : Double;
-  c            : Char;
+  c            : AnsiChar;
 
 begin
   No:=Field.FieldNo-1;
@@ -665,7 +665,7 @@ begin
           begin
           Move(Value^,Buffer^,flen);
           If (Flen<=Field.DataSize) then
-            Pchar(Buffer)[flen]:=#0;
+            PAnsiChar(Buffer)[flen]:=#0;
           FDoc^.free(FDoc,value);
           end;
         end;
@@ -788,7 +788,7 @@ function TParadox.CreateBlobStream(Field: TField; Mode: TBlobStreamMode
 TYpe
   PGraphicHeader = ^TGraphicHeader;
 Var
-  FBuf,Value,V2 : Pchar;
+  FBuf,Value,V2 : PAnsiChar;
   FLen,Res : Integer;
   M,D : Cint;
   H : PGraphicHeader;
@@ -944,12 +944,12 @@ end;
 function TParadox.GetParam(const ParamName: String): String;
 
 Var
-  V : Pchar;
+  V : PAnsiChar;
 
 begin
   If Not Assigned(FDoc) then
     RaiseError(SErrParadoxNotOpen,[]);
-  if (PX_Get_parameter(FDoc,Pchar(ParamName),@V)<>0) then
+  if (PX_Get_parameter(FDoc,PAnsiChar(ParamName),@V)<>0) then
     RaiseError(SErrGetParamFailed,[ParamName]);
   If (V<>Nil) then
     Result:=strpas(V);
@@ -959,7 +959,7 @@ procedure TParadox.SetParam(const ParamName, ParamValue: String);
 begin
   If Not Assigned(FDoc) then
     RaiseError(SErrParadoxNotOpen,[]);
-  if (PX_Set_parameter(FDoc,Pchar(ParamName),PChar(ParamValue))<>0) then
+  if (PX_Set_parameter(FDoc,PAnsiChar(ParamName),PAnsiChar(ParamValue))<>0) then
     RaiseError(SErrSetParamFailed,[ParamName]);
 end;
 

+ 26 - 26
packages/fcl-db/src/sdf/sdfdata.pp

@@ -275,14 +275,14 @@ type
 //-----------------------------------------------------------------------------
   TSdfDataSet = class(TFixedFormatDataSet)
   private
-    FDelimiter : Char;
+    FDelimiter : AnsiChar;
     FFirstLineAsSchema : Boolean;
     FMultiLine         : Boolean;
     FStripTrailingDelimiters : Boolean;
     procedure DoStripTrailingDelimiters(var S: String);
     procedure SetMultiLine(const Value: Boolean);
     procedure SetFirstLineAsSchema(Value : Boolean);
-    procedure SetDelimiter(Value : Char);
+    procedure SetDelimiter(Value : AnsiChar);
   protected
     procedure InternalInitFieldDefs; override;
     function BufToStore(Buffer: TRecordBuffer): String; override;
@@ -293,7 +293,7 @@ type
   published
     // Whether or not to allow fields containing CR and/or LF (on write only)
     property AllowMultiLine: Boolean read FMultiLine write SetMultiLine;
-    property Delimiter: Char read FDelimiter write SetDelimiter;
+    property Delimiter: AnsiChar read FDelimiter write SetDelimiter;
     property FirstLineAsSchema: Boolean read FFirstLineAsSchema write SetFirstLineAsSchema;
     // Set this to True if you want to strip all last delimiters
     Property StripTrailingDelimiters : Boolean Read FStripTrailingDelimiters Write FStripTrailingDelimiters;
@@ -689,7 +689,7 @@ end;
 function TFixedFormatDataSet.GetFieldData(Field: TField; Buffer: Pointer): Boolean;
 var
   RecBuf,
-  BufEnd: PChar;
+  BufEnd: PAnsiChar;
 begin
   Result := GetActiveRecBuf(TRecordBuffer(RecBuf));
   if Result then
@@ -726,7 +726,7 @@ end;
 
 procedure TFixedFormatDataSet.SetFieldData(Field: TField; Buffer: Pointer);
 var
-  RecBuf: PChar;
+  RecBuf: PAnsiChar;
 begin
   if not (State in dsWriteModes) then
     DatabaseErrorFmt(SNotEditing, [Name], Self);
@@ -908,12 +908,12 @@ end;
 
 function TFixedFormatDataSet.StoreToBuf(Source: String): String;
 var i, Len: integer;
-    Src, Dest: PChar;
+    Src, Dest: PAnsiChar;
 begin
   // moves fixed length fields from Source to record buffer and null-terminates each field
   SetLength(Result, FRecordSize);
-  Src  := PChar(Source);
-  Dest := PChar(Result);
+  Src  := PAnsiChar(Source);
+  Dest := PAnsiChar(Result);
   for i := 0 to FieldDefs.Count - 1 do
   begin
     Len := FieldDefDataSize(FieldDefs[i])-1;
@@ -927,7 +927,7 @@ end;
 
 function TFixedFormatDataSet.BufToStore(Buffer: TRecordBuffer): String;
 var i, Len, SrcLen: integer;
-    Src, Dest: PChar;
+    Src, Dest: PAnsiChar;
 begin
   // calculate fixed length record size
   Len := 0;
@@ -935,8 +935,8 @@ begin
     Inc(Len, FieldDefDataSize(FieldDefs[i])-1);
   SetLength(Result, Len);
 
-  Src  := PChar(Buffer);
-  Dest := PChar(Result);
+  Src  := PAnsiChar(Buffer);
+  Dest := PAnsiChar(Result);
   for i := 0 to FieldDefs.Count - 1 do
   begin
     Len := FieldDefDataSize(FieldDefs[i])-1;
@@ -961,9 +961,9 @@ var
 
   function GetNextLine(const Value: string; out S: string; var P: Integer): Boolean;
   const
-    CR: char = #13;
-    LF: char = #10;
-    DQ: char = '"';
+    CR: AnsiChar = #13;
+    LF: AnsiChar = #10;
+    DQ: AnsiChar = '"';
   var
     L, P1: integer;
     InDQ: boolean;
@@ -1018,12 +1018,12 @@ end;
 
 function TSdfDataSet.ExtractDelimited(const S: String; var Pos: integer): string;
 const
-  CR: char = #13;
-  LF: char = #10;
-  DQ: char = '"';
+  CR: AnsiChar = #13;
+  LF: AnsiChar = #10;
+  DQ: AnsiChar = '"';
 var
   Len, P1: integer;
-  pSrc, pDest: PChar;
+  pSrc, pDest: PAnsiChar;
 begin
   Len := Length(S);
   P1 := Pos;
@@ -1136,13 +1136,13 @@ var
   Pos,
   Len     : Integer; // Actual length of field
   S       : String;
-  Dest    : PChar;
+  Dest    : PAnsiChar;
 begin
   SetLength(Result, FRecordSize);
   FillChar(Result[1], FRecordSize, Ord(' '));
 
   Pos := 1;
-  Dest := PChar(Result);
+  Dest := PAnsiChar(Result);
 
   for i := 0 to FieldDefs.Count - 1 do
   begin
@@ -1163,17 +1163,17 @@ end;
 
 function TSdfDataSet.BufToStore(Buffer: TRecordBuffer): String;
 const
-  CR: char = #13;
-  LF: char = #10;
-  DQ: char = '"';
+  CR: AnsiChar = #13;
+  LF: AnsiChar = #10;
+  DQ: AnsiChar = '"';
 var
-  Src: PChar;
+  Src: PAnsiChar;
   S : String;
   i, MaxLen, Len : Integer;
   QuoteMe: boolean;
 begin
   Result := '';
-  Src := PChar(Buffer);
+  Src := PAnsiChar(Buffer);
   for i := 0 to FieldDefs.Count - 1 do
   begin
     MaxLen := FieldDefDataSize(FieldDefs[i])-1;
@@ -1220,7 +1220,7 @@ begin
     S:=Copy(S,1,P);
 end;
 
-procedure TSdfDataSet.SetDelimiter(Value : Char);
+procedure TSdfDataSet.SetDelimiter(Value : AnsiChar);
 begin
   CheckInactive;
   FDelimiter := Value;

+ 1 - 1
packages/fcl-db/src/sqldb/examples/bcreatetable.pp

@@ -29,7 +29,7 @@ begin
   Fconnection.ExecuteDirect('create table FPDEV (       ' +
                             '  id INT NOT NULL,           ' +
                             '  Name VARCHAR(50),          ' +
-                            '  Email CHAR(50),            ' +
+                            '  Email AnsiChar(50),            ' +
                             '  Birthdate Date,            ' +
                             '  PRIMARY KEY (id)           ' +
                             ')                            ');

+ 4 - 4
packages/fcl-db/src/sqldb/interbase/fbadmin.pp

@@ -287,7 +287,7 @@ end;
 
 procedure TFBAdmin.CheckError(const ProcName: string; Status: PISC_STATUS);
 var
-  buf : array [0..1023] of char;
+  buf : array [0..1023] of AnsiChar;
   Msg : string;
   Err : longint;
 
@@ -427,7 +427,7 @@ begin
   spb:=chr(isc_spb_version)+chr(isc_spb_current_version)+
     IBParamSerialize(isc_spb_user_name,FUser)+
     IBParamSerialize(isc_spb_password,FPassword);
-  result:=isc_service_attach(@FStatus[0], 0,PChar(Service), @FSvcHandle,
+  result:=isc_service_attach(@FStatus[0], 0,PAnsiChar(Service), @FSvcHandle,
       length(spb), @spb[1]) = 0;
   if not result then
     CheckError('Connect',FStatus)
@@ -524,7 +524,7 @@ begin
           @spb[1],BUFFERSIZE,@buffer[1])=0;
   if Not Result then
     CheckError('ServiceRunning',FSTatus);
-  if (Buffer[1]=Char(isc_info_svc_running)) then
+  if (Buffer[1]=AnsiChar(isc_info_svc_running)) then
     begin
     res:=isc_vax_integer(@Buffer[2],4);
     Result:=res=1;
@@ -850,7 +850,7 @@ begin
     param := param or isc_spb_sts_record_versions;
   if (IBStatTables in Options) then
     param := param or isc_spb_sts_table;
-  spb  := Char(isc_action_svc_db_stats)+IBSPBParamSerialize(isc_spb_dbname,Database)+
+  spb  := AnsiChar(isc_action_svc_db_stats)+IBSPBParamSerialize(isc_spb_dbname,Database)+
     IBSPBParamSerialize(isc_spb_options, param);
   if (IBStatTables in Options) and (TableNames <> '') then
     spb := spb+IBSPBParamSerialize(isc_spb_command_line, TableNames);

+ 6 - 6
packages/fcl-db/src/sqldb/interbase/fbeventmonitor.pp

@@ -85,8 +85,8 @@ const
   MAXEVENTSPEREPB=15;      //isc_event_block limitated to 15 events.
 type
   TEPBpair=record
-    EventBuf:PChar;        //isc_event_block event block
-    ResultBuf:PChar;       //isc_event_block result block
+    EventBuf:PAnsiChar;        //isc_event_block event block
+    ResultBuf:PAnsiChar;       //isc_event_block result block
     Signal:pointer;        //pointer to TFBEventsThread.FSignal
     Signaled:Boolean;      //this event block is signaled
     Len:ISC_LONG;          //lenght returned by isc_event_block
@@ -128,7 +128,7 @@ type
     property Handle:pointer read GetDBHandle;
   end;
 
-procedure event_function(ptr:pointer;len:ushort;updated: pchar);cdecl;
+procedure event_function(ptr:pointer;len:ushort;updated: PAnsiChar);cdecl;
 begin
   Move(updated^, PEPBpair(ptr)^.ResultBuf^, len);
   PEPBpair(ptr)^.signaled:=true;
@@ -144,7 +144,7 @@ end;
 
 procedure TFBEventsThread.CheckError(Status: PISC_STATUS);
 var
-  buf : array [0..1023] of char;
+  buf : array [0..1023] of AnsiChar;
 
 begin
   if ((Status[0] = 1) and (Status[1] <> 0)) then
@@ -174,11 +174,11 @@ var
   DBHandle : pointer;
   bStartup:boolean;
 
-  function P(num:integer):pchar;
+  function P(num:integer):PAnsiChar;
   begin
     num:=num+i*MAXEVENTSPEREPB;
     if num<FParent.FEvents.Count then
-      result:=pchar(FParent.FEvents[num])
+      result:=PAnsiChar(FParent.FEvents[num])
     else
       result:=nil;
   end;

+ 19 - 20
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

@@ -36,8 +36,8 @@ type
   TDatabaseInfo = record
     Dialect             : integer; //Dialect set in database
     ODSMajorVersion     : integer; //On-Disk Structure version of file
-    ServerVersion       : string;  //Representation of major.minor (.build)
-    ServerVersionString : string;  //Complete version string, including name, platform
+    ServerVersion       : ansistring;  //Representation of major.minor (.build)
+    ServerVersionString : ansistring;  //Complete version string, including name, platform
   end;
 
   TStatusVector = array [0..19] of ISC_STATUS;
@@ -63,7 +63,7 @@ type
     in_SQLDA             : PXSQLDA;
     ParamBinding         : array of integer;
     FieldBinding         : array of integer;
-    CursorName : String;
+    CursorName : AnsiString;
   end;
 
   TIBTrans = Class(TSQLHandle)
@@ -194,7 +194,7 @@ procedure TIBConnection.CheckError(const ProcName : string; Status : PISC_STATUS
 var
   i,ErrorCode : longint;
   Msg, SQLState : string;
-  Buf : array [0..1023] of char;
+  Buf : array [0..1023] of AnsiChar;
   aStatusVector: TStatusVector;
   Exc : EIBDatabaseError;
 
@@ -305,7 +305,7 @@ begin
       Dec(P);
     Result:=P>0;
     if Result then
-      TPB:=Char(P);
+      TPB:=AnsiChar(P);
     end;
 end;
 
@@ -356,14 +356,14 @@ Begin
             Begin
             If prVal='' Then
               DatabaseErrorFmt('Table name must be specified for "%s"',[S],Self);
-            LTPB:=LTPB+Char(Length(prVal))+prVal;
+            LTPB:=LTPB+AnsiChar(Length(prVal))+prVal;
             End;
           isc_tpb_lock_timeout:
             Begin
             //In case of using lock timeout we need add timeout
             If prVal='' Then
               DatabaseErrorFmt('Timeout must be specified for "%s"',[S],Self);
-            LTPB:=LTPB+Char(SizeOf(ISC_LONG));
+            LTPB:=LTPB+AnsiChar(SizeOf(ISC_LONG));
             SetLength(LTPB,Length(LTPB)+SizeOf(ISC_LONG));
             pInt:=@LTPB[Length(LTPB)-SizeOf(ISC_LONG)+1];
             pInt^:=StrToInt(prVal);
@@ -379,7 +379,7 @@ Begin
   // Construct block.
   With IBTrans do
     begin
-    TPB:=Char(Ord(Version)-Ord('0'))+LTPB;
+    TPB:=AnsiChar(Ord(Version)-Ord('0'))+LTPB;
     TransactionHandle:=Nil;
     If isc_start_transaction(@Status[0],@TransactionHandle,1,[@DBHandle,Length(TPB),@TPB[1]])<>0 Then
       CheckError('StartTransaction',Status)
@@ -547,7 +547,7 @@ begin
     ReqBuf[2] := isc_info_db_sql_dialect;
     ReqBuf[3] := isc_info_end;
     if isc_database_info(@FStatus[0], @FDatabaseHandle, Length(ReqBuf),
-      pchar(@ReqBuf[0]), SizeOf(ResBuf), pchar(@ResBuf[0])) <> 0 then
+      PAnsiChar(@ReqBuf[0]), SizeOf(ResBuf), PAnsiChar(@ResBuf[0])) <> 0 then
         CheckError('CacheServerInfo', FStatus);
     x := 0;
     while x < ResBufHigh+1 do
@@ -555,23 +555,23 @@ begin
         isc_info_db_sql_dialect :
           begin
           Inc(x);
-          Len := isc_vax_integer(pchar(@ResBuf[x]), 2);
+          Len := isc_vax_integer(PAnsiChar(@ResBuf[x]), 2);
           Inc(x, 2);
-          FDatabaseInfo.Dialect := isc_vax_integer(pchar(@ResBuf[x]), Len);
+          FDatabaseInfo.Dialect := isc_vax_integer(PAnsiChar(@ResBuf[x]), Len);
           Inc(x, Len);
           end;
         isc_info_ods_version :
           begin
           Inc(x);
-          Len := isc_vax_integer(pchar(@ResBuf[x]), 2);
+          Len := isc_vax_integer(PAnsiChar(@ResBuf[x]), 2);
           Inc(x, 2);
-          FDatabaseInfo.ODSMajorVersion := isc_vax_integer(pchar(@ResBuf[x]), Len);
+          FDatabaseInfo.ODSMajorVersion := isc_vax_integer(PAnsiChar(@ResBuf[x]), Len);
           Inc(x, Len);
           end;
         isc_info_version :
           begin
           Inc(x);
-          Len := isc_vax_integer(pchar(@ResBuf[x]), 2);
+          Len := isc_vax_integer(PAnsiChar(@ResBuf[x]), 2);
           Inc(x, 2);
           SetString(FDatabaseInfo.ServerVersionString, PAnsiChar(@ResBuf[x + 2]), Len-2);
           FDatabaseInfo.ServerVersion := ParseServerVersion(FDatabaseInfo.ServerVersionString);
@@ -1003,7 +1003,6 @@ procedure TIBConnection.Execute(cursor: TSQLCursor;atransaction:tSQLtransaction;
 var
   TransactionHandle : pointer;
   out_SQLDA : PXSQLDA;
-  S: String;
 
 begin
   TransactionHandle := aTransaction.Handle;
@@ -1025,7 +1024,7 @@ begin
         Inc(FCursorCount);
         CursorName:='sqldbcursor'+IntToStr(FCursorCount);
         end;
-      if isc_dsql_set_cursor_name(@Status[0], @StatementHandle, PChar(CursorName) , 0) <> 0 then
+      if isc_dsql_set_cursor_name(@Status[0], @StatementHandle, PAnsiChar(CursorName) , 0) <> 0 then
         CheckError('Open Cursor', Status);
     end
     else
@@ -1068,7 +1067,7 @@ begin
       TranslateFldType(PSQLVar^.SQLType, PSQLVar^.sqlsubtype, PSQLVar^.SQLLen, PSQLVar^.SQLScale,
         TransType, TransLen, TransPrec);
 
-      // [var]char or blob column character set NONE or OCTETS overrides connection charset
+      // [var]AnsiChar or blob column character set NONE or OCTETS overrides connection charset
       if (((TransType in [ftString, ftFixedChar]) and (PSQLVar^.sqlsubtype and $FF in [CS_NONE,CS_BINARY])) and not UseConnectionCharSetIfNone)
          or
          ((TransType = ftMemo) and (PSQLVar^.relname_length>0) and (PSQLVar^.sqlname_length>0) and (GetBlobCharset(@PSQLVar^.relname,@PSQLVar^.sqlname) in [CS_NONE,CS_BINARY])) then
@@ -1183,7 +1182,7 @@ var
   SQLVarNr : integer;
   si       : smallint;
   li       : LargeInt;
-  CurrBuff : pchar;
+  CurrBuff : PAnsiChar;
   w        : word;
 
 begin
@@ -1282,7 +1281,7 @@ function TIBConnection.LoadField(cursor : TSQLCursor; FieldDef : TFieldDef; buff
 var
   VSQLVar    : PXSQLVAR;
   VarcharLen : word;
-  CurrBuff     : pchar;
+  CurrBuff     : PAnsiChar;
   c            : currency;
   AFmtBcd      : tBCD;
 
@@ -1375,7 +1374,7 @@ begin
         ftString, ftFixedChar  :
           begin
             Move(CurrBuff^, Buffer^, VarCharLen);
-            PChar(Buffer + VarCharLen)^ := #0;
+            PAnsiChar(Buffer + VarCharLen)^ := #0;
           end;
         ftFloat   :
           GetFloat(CurrBuff, Buffer, VSQLVar^.SQLLen);

+ 5 - 6
packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

@@ -28,8 +28,8 @@
     TMSSQLConnection properties:
       HostName - can be specified also as 'servername:port' or 'servername\instance'
                  (SQL Server Browser Service must be running on server to connect to specific instance)
-      CharSet - if you use Microsoft DB-Lib and set to 'UTF-8' then char/varchar fields will be UTF8Encoded/Decoded
-                if you use FreeTDS DB-Lib then you must compile with iconv support (requires libiconv2.dll) or cast char/varchar to nchar/nvarchar in SELECTs
+      CharSet - if you use Microsoft DB-Lib and set to 'UTF-8' then AnsiChar/varchar fields will be UTF8Encoded/Decoded
+                if you use FreeTDS DB-Lib then you must compile with iconv support (requires libiconv2.dll) or cast AnsiChar/varchar to nchar/nvarchar in SELECTs
       Params - "AutoCommit=true" - if you don't want explicitly commit/rollback transactions
                "TextSize=16777216" - set maximum size of text/image data returned
                "ApplicationName=YourAppName" - Set the app name for the connection. MSSQL 2000 and higher only
@@ -41,8 +41,7 @@ unit MSSQLConn;
 interface
 
 uses
-  Classes, SysUtils, sqldb, db, BufDataset,
-  dblib;
+  Types, Classes, SysUtils, sqldb, db, BufDataset, dblib;
 
 type
 
@@ -235,7 +234,7 @@ end;
 
 function TDBLibCursor.ReplaceParams(AParams: TParams): string;
 var i: integer;
-    ParamNames, ParamValues: array of string;
+    ParamNames, ParamValues: tansistringdynarray;
 begin
   if Assigned(AParams) and (AParams.Count > 0) then //taken from mysqlconn, pqconnection
   begin
@@ -373,7 +372,7 @@ function TMSSQLConnection.GetAsSQLText(Param: TParam): string;
   function StrToHex(const s: string): string;
   begin
     setlength(Result, 2*length(s));
-    BinToHex(PChar(s), PChar(Result), length(s));
+    BinToHex(PAnsiChar(s), PAnsiChar(Result), length(s));
   end;
 begin
   if not Param.IsNull then

+ 75 - 45
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

@@ -35,7 +35,7 @@
 interface
 
 uses
-  Classes, SysUtils,bufdataset,sqldb,db,ctypes,fmtbcd,
+  Classes,Types, SysUtils,bufdataset,sqldb,db,ctypes,fmtbcd,
 {$IFDEF mysql80}
   mysql80dyn;
 {$ELSE}
@@ -148,25 +148,26 @@ Type
     function GetServerStatus: String;
     procedure ConnectMySQL(var HMySQL: PMySQL);
     procedure ExecuteDirectMySQL(const query : string);
-    function InternalStrToBCD(C: pchar; Len: integer): tBCD;
-    function InternalStrToCurrency(C: pchar; Len: integer): Currency;
-    function InternalStrToDate(C: pchar; Len: integer): TDateTime;
-    function InternalStrToDateTime(C: pchar; Len: integer): TDateTime;
-    function InternalStrToFloat(C: pchar; Len: integer): Extended;
-    function InternalStrToInt(C: pchar; Len: integer): integer;
-    function InternalStrToDWord(C: pchar; Len: integer): DWord;
-    function InternalStrToInt64(C: pchar; Len: integer): Int64;
-    function InternalStrToTime(C: pchar; Len: integer): TDateTime;
-    function StrToMSecs(C: pchar; Len: integer): Word;
+    function InternalStrToBCD(C: PAnsiChar; Len: integer): tBCD;
+    function InternalStrToCurrency(C: PAnsiChar; Len: integer): Currency;
+    function InternalStrToDate(C: PAnsiChar; Len: integer): TDateTime;
+    function InternalStrToDateTime(C: PAnsiChar; Len: integer): TDateTime;
+    function InternalStrToFloat(C: PAnsiChar; Len: integer): Extended;
+    function InternalStrToInt(C: PAnsiChar; Len: integer): integer;
+    function InternalStrToDWord(C: PAnsiChar; Len: integer): DWord;
+    function InternalStrToInt64(C: PAnsiChar; Len: integer): Int64;
+    function InternalStrToTime(C: PAnsiChar; Len: integer): TDateTime;
+    function StrToMSecs(C: PAnsiChar; Len: integer): Word;
 {$IFDEF MYSQL40}
-    function InternalStrToTimeStamp(C: pchar; Len: integer): TDateTime;
+    function InternalStrToTimeStamp(C: PAnsiChar; Len: integer): TDateTime;
 {$ENDIF}
   protected
     Procedure ConnectToServer; virtual;
     Procedure SelectDatabase; virtual;
     function MySQLDataType(AField: PMYSQL_FIELD; var NewType: TFieldType; var NewSize: Integer): Boolean;
-    function MySQLWriteData(AField: PMYSQL_FIELD; FieldDef: TFieldDef; Source, Dest: PChar; Len: integer; out CreateBlob : boolean): Boolean;
-    function EscapeString(const Str : string) : string;
+    function MySQLWriteData(AField: PMYSQL_FIELD; FieldDef: TFieldDef; Source, Dest: PAnsiChar; Len: integer; out CreateBlob : boolean): Boolean;
+    function EscapeString(const Str : UnicodeString) : UnicodeString;
+    function EscapeString(const Str : AnsiString) : AnsiString;
 
     // SQLConnection methods
     procedure DoInternalConnect; override;
@@ -469,9 +470,10 @@ Var
   APort : Cardinal;
   i,e: integer;
   AMysql_Option: mysql_option;
-  OptStr: string;
+  OptStr: ansistring;
   OptInt: cuint;
   Opt: pointer;
+  CS,H,U,P : AnsiString;
 
 begin
   HMySQL := mysql_init(HMySQL);
@@ -486,26 +488,32 @@ begin
       if e=0 then
         Opt := @OptInt
       else
-        Opt := pchar(OptStr);
+        Opt := PAnsiChar(OptStr);
       if mysql_options(HMySQL,AMysql_Option,Opt) <> 0 then
           MySQLError(HMySQL,Format(SErrSettingParameter,[Params.Names[i]]),Self);
       end;
     end;
-
-  if mysql_real_connect(HMySQL,PChar(HostName),PChar(UserName),PChar(Password),Nil,APort,Nil,CLIENT_MULTI_RESULTS) = nil then //CLIENT_MULTI_RESULTS is required by CALL SQL statement(executes stored procedure), that produces result sets
+  H:=HostName;
+  U:=UserName;
+  P:=Password;
+  if mysql_real_connect(HMySQL,PAnsiChar(H),PAnsiChar(U),PAnsiChar(P),Nil,APort,Nil,CLIENT_MULTI_RESULTS) = nil then //CLIENT_MULTI_RESULTS is required by CALL SQL statement(executes stored procedure), that produces result sets
     MySQLError(HMySQL,SErrServerConnectFailed,Self);
 
   if (trim(CharSet) <> '') then
     // major_version*10000 + minor_version *100 + sub_version
     if (50007 <= mysql_get_server_version(HMySQL)) then
       begin
+      CS:=CharSet;
       // Only available for MySQL 5.0.7 and later...
-      if mysql_set_character_set(HMySQL, PChar(CharSet)) <> 0 then
+      if mysql_set_character_set(HMySQL, PAnsiChar(CS)) <> 0 then
         MySQLError(HMySQL,SErrSetCharsetFailed,Self);
       end
     else
-      if mysql_query(HMySQL,PChar('SET NAMES ''' + EscapeString(CharSet) +'''')) <> 0 then
+      begin
+      CS:='SET NAMES ''' + EscapeString(CharSet) +'''';
+      if mysql_query(HMySQL,PAnsiChar(CS)) <> 0 then
         MySQLError(HMySQL,SErrExecuting,Self);
+      end;  
 end;
 
 function TConnectionName.GetAsSQLText(Param: TParam) : string;
@@ -534,8 +542,13 @@ end;
 
 
 Procedure TConnectionName.SelectDatabase;
+
+Var
+  DN : AnsiString;
+
 begin
-  if mysql_select_db(FMySQL,pchar(DatabaseName))<>0 then
+  DN:=DatabaseName;
+  if mysql_select_db(FMySQL,PAnsiChar(DN))<>0 then
     MySQLError(FMySQL,SErrDatabaseSelectFailed,Self);
 end;
 
@@ -554,8 +567,9 @@ end;
 
 procedure TConnectionName.ExecuteDirectMySQL(const query : string);
 
-var AMySQL      : PMySQL;
-
+var 
+  AMySQL      : PMySQL;
+  Qry : AnsiString;
 begin
   CheckDisConnected;
 
@@ -565,7 +579,12 @@ begin
     AMySQL := nil;
     ConnectMySQL(AMySQL);
     try
-      if mysql_query(AMySQL,pchar(query))<>0 then
+      {$if SIZEOF(CHAR)=2}
+      Qry:=UTF8Encode(Query);
+      {$ELSE}
+      Qry:=Query;
+      {$ENDIF}
+      if mysql_query(AMySQL,PAnsiChar(Qry))<>0 then
         MySQLError(AMySQL,SErrExecuting,Self);
     finally
       mysql_close(AMySQL);
@@ -575,16 +594,22 @@ begin
   end;
 end;
 
-function TConnectionName.EscapeString(const Str: string): string;
-
-var Len : integer;
+function TConnectionName.EscapeString(const Str: ansistring): ansistring;
 
+var 
+  Len : integer;
 begin
   SetLength(result,length(str)*2+1);
-  Len := mysql_real_escape_string(FMySQL,pchar(Result),pchar(Str),length(Str));
+  Len := mysql_real_escape_string(FMySQL,PAnsiChar(Result),PAnsiChar(Str),length(Str));
   SetLength(result,Len);
 end;
 
+function TConnectionName.EscapeString(const Str: Unicodestring): Unicodestring;
+
+begin
+  Result:=UTF8Decode(EscapeString(UTF8Encode(Str)));
+end;
+
 procedure TConnectionName.DoInternalConnect;
 var
   FullVersion: string;
@@ -718,9 +743,10 @@ procedure TConnectionName.Execute(cursor: TSQLCursor;
 Var
   C : TCursorName;
   i : integer;
-  ParamNames,ParamValues : array of string;
+  ParamNames,ParamValues : TAnsiStringDynArray;
   Res: PMYSQL_RES;
   Status : Integer;
+  FStat : AnsiString;
 
 begin
   C:=Cursor as TCursorName;
@@ -746,8 +772,12 @@ begin
       Log(detExecute, C.FPreparedStatement);
     if LogEvent(detActualSQL) then
       Log(detActualSQL,C.FActualStatement);
-
-    if mysql_query(FMySQL,Pchar(C.FActualStatement))<>0 then
+    {$IF SIZEOF(CHAR)=2}
+    FStat:=UTF8Encode(C.FActualStatement);  
+    {$ELSE}
+    FStat:=C.FActualStatement;
+    {$ENDIF}
+    if mysql_query(FMySQL,PAnsiChar(FStat))<>0 then
       begin
       if not ForcedClose then
         MySQLError(FMYSQL,SErrExecuting,Self)
@@ -867,7 +897,7 @@ begin
       else
         NewType := ftString;
 {$IFDEF MYSQL50_UP}
-      if AField^.charsetnr = 63 then begin //BINARY vs. CHAR, VARBINARY vs. VARCHAR
+      if AField^.charsetnr = 63 then begin //BINARY vs. AnsiChar, VARBINARY vs. VARCHAR
         if NewType = ftFixedChar then
           NewType := ftBytes
         else
@@ -996,7 +1026,7 @@ begin
   ABlobBuf^.BlobBuffer^.Size := len;
 end;
 
-function TConnectionName.InternalStrToInt(C: pchar; Len: integer): integer;
+function TConnectionName.InternalStrToInt(C: PAnsiChar; Len: integer): integer;
 
 Var
   S : String;
@@ -1009,7 +1039,7 @@ begin
   Result:=StrToInt(S);
 end;
 
-function TConnectionName.InternalStrToDWord(C: pchar; Len: integer): DWord;
+function TConnectionName.InternalStrToDWord(C: PAnsiChar; Len: integer): DWord;
 Var
   S : String;
 begin
@@ -1020,7 +1050,7 @@ begin
   Result:=StrToDWord(S);
 end;
 
-function TConnectionName.InternalStrToInt64(C: pchar; Len: integer): Int64;
+function TConnectionName.InternalStrToInt64(C: PAnsiChar; Len: integer): Int64;
 
 Var
   S : String;
@@ -1033,7 +1063,7 @@ begin
   Result:=StrToInt64(S);
 end;
 
-function TConnectionName.InternalStrToFloat(C: pchar; Len: integer): Extended;
+function TConnectionName.InternalStrToFloat(C: PAnsiChar; Len: integer): Extended;
 
 var
   Tmp: string;
@@ -1045,7 +1075,7 @@ begin
   Result := StrToFloat(Tmp, FSQLFormatSettings);
 end;
 
-function TConnectionName.InternalStrToCurrency(C: pchar; Len: integer): Currency;
+function TConnectionName.InternalStrToCurrency(C: PAnsiChar; Len: integer): Currency;
 
 var
   Tmp: string;
@@ -1057,7 +1087,7 @@ begin
   Result := StrToCurr(Tmp, FSQLFormatSettings);
 end;
 
-function TConnectionName.InternalStrToBCD(C: pchar; Len: integer): tBCD;
+function TConnectionName.InternalStrToBCD(C: PAnsiChar; Len: integer): tBCD;
 
 var
   Tmp: string;
@@ -1069,7 +1099,7 @@ begin
   Result := StrToBCD(Tmp, FSQLFormatSettings);
 end;
 
-function TConnectionName.InternalStrToDate(C: pchar; Len: integer): TDateTime;
+function TConnectionName.InternalStrToDate(C: PAnsiChar; Len: integer): TDateTime;
 
 var
   EY, EM, ED: Word;
@@ -1088,7 +1118,7 @@ begin
     Result:=EncodeDate(EY, EM, ED);
 end;
 
-function TConnectionName.StrToMSecs(C: pchar; Len: integer): Word;
+function TConnectionName.StrToMSecs(C: PAnsiChar; Len: integer): Word;
 {$IFDEF MYSQL56_UP}
 var I: Integer;
     d, MSecs: double;
@@ -1113,7 +1143,7 @@ begin
 {$ENDIF}
 end;
 
-function TConnectionName.InternalStrToDateTime(C: pchar; Len: integer): TDateTime;
+function TConnectionName.InternalStrToDateTime(C: PAnsiChar; Len: integer): TDateTime;
 
 var
   EY, EM, ED: Word;
@@ -1141,11 +1171,11 @@ begin
   Result := ComposeDateTime(Result, EncodeTimeInterval(EH, EN, ES, EMS));
 end;
 
-function TConnectionName.InternalStrToTime(C: pchar; Len: integer): TDateTime;
+function TConnectionName.InternalStrToTime(C: PAnsiChar; Len: integer): TDateTime;
 
 var
   EH, EM, ES, EMS: Word;
-  M: PChar;
+  M: PAnsiChar;
   I: Integer;
 
 begin
@@ -1174,7 +1204,7 @@ begin
 end;
 
 {$IFDEF mysql40}
-function TConnectionName.InternalStrToTimeStamp(C: pchar; Len: integer): TDateTime;
+function TConnectionName.InternalStrToTimeStamp(C: PAnsiChar; Len: integer): TDateTime;
 
 var
   EY, EM, ED: Word;
@@ -1199,7 +1229,7 @@ begin
 end;
 {$ENDIF}
 
-function TConnectionName.MySQLWriteData(AField: PMYSQL_FIELD; FieldDef: TFieldDef; Source, Dest: PChar; Len: integer; out CreateBlob : boolean): Boolean;
+function TConnectionName.MySQLWriteData(AField: PMYSQL_FIELD; FieldDef: TFieldDef; Source, Dest: PAnsiChar; Len: integer; out CreateBlob : boolean): Boolean;
 
 var
   VI: Integer;

+ 12 - 12
packages/fcl-db/src/sqldb/odbc/odbcconn.pas

@@ -703,7 +703,7 @@ begin
     CheckResult(
       SQLDriverConnect(FDBCHandle,               // the ODBC connection handle
                        nil,                      // no parent window (would be required for prompts)
-                       PChar(ConnectionString),  // the connection string
+                       PAnsiChar(ConnectionString),  // the connection string
                        Length(ConnectionString), // connection string length
                        @(OutConnectionString[1]),// buffer for storing the completed connection string
                        BufferLength,             // length of the buffer
@@ -944,7 +944,7 @@ begin
   Result := false;
   if SQLAllocHandle(SQL_HANDLE_STMT, FDBCHandle, STMTHandle) = SQL_SUCCESS then
     begin
-    if SQLExecDirect(STMTHandle, PChar(FDBMSInfo.GetLastInsertIDSQL), Length(FDBMSInfo.GetLastInsertIDSQL)) = SQL_SUCCESS then
+    if SQLExecDirect(STMTHandle, PAnsiChar(FDBMSInfo.GetLastInsertIDSQL), Length(FDBMSInfo.GetLastInsertIDSQL)) = SQL_SUCCESS then
       if SQLFetch(STMTHandle) = SQL_SUCCESS then
         if SQLGetData(STMTHandle, 1, SQL_C_SBIGINT, @LastInsertID, SizeOf(LargeInt), @StrLenOrInd) = SQL_SUCCESS then
           Field.AsLargeInt := LastInsertID;
@@ -1443,7 +1443,7 @@ var
   _Type     :SQLSMALLINT; _TypeIndOrLen     :SQLLEN;
   OrdinalPos:SQLSMALLINT; OrdinalPosIndOrLen:SQLLEN;
   ColName   :string;      ColNameIndOrLen   :SQLLEN;
-  AscOrDesc :char;        AscOrDescIndOrLen :SQLLEN;
+  AscOrDesc :AnsiChar;        AscOrDescIndOrLen :SQLLEN;
   PKName    :string;      PKNameIndOrLen    :SQLLEN;
 const
   DEFAULT_NAME_LEN = 255;
@@ -1482,7 +1482,7 @@ begin
         StmtHandle,
         nil, 0, // any catalog
         nil, 0, // any schema
-        PChar(TableName), Length(TableName)
+        PAnsiChar(TableName), Length(TableName)
       ),
       SQL_HANDLE_STMT, StmtHandle, 'Could not retrieve primary key metadata for table %s using SQLPrimaryKeys.', [TableName]
     );
@@ -1507,13 +1507,13 @@ begin
           if OrdinalPos=1 then begin
             // create new IndexDef if OrdinalPos=1
             IndexDef:=IndexDefs.AddIndexDef;
-            IndexDef.Name:=PChar(@PKName[1]);
-            IndexDef.Fields:=PChar(@ColName[1]);
+            IndexDef.Name:=PAnsiChar(@PKName[1]);
+            IndexDef.Fields:=PAnsiChar(@ColName[1]);
             IndexDef.Options:=IndexDef.Options+[ixUnique]+[ixPrimary]; // Primary key is always unique
             KeyName:=IndexDef.Name;
           end else begin
             assert(Assigned(IndexDef));
-            IndexDef.Fields:=IndexDef.Fields+';'+PChar(@ColName[1]); // NB ; is the separator to be used for IndexDef.Fields
+            IndexDef.Fields:=IndexDef.Fields+';'+PAnsiChar(@ColName[1]); // NB ; is the separator to be used for IndexDef.Fields
           end;
         end else begin
           CheckResult(Res, SQL_HANDLE_STMT, StmtHandle, 'Could not fetch primary key metadata row.');
@@ -1533,7 +1533,7 @@ begin
         StmtHandle,
         nil, 0, // catalog unknown; request for all catalogs
         nil, 0, // schema unknown; request for all schemas
-        PChar(TableName), Length(TableName), // request information for TableName
+        PAnsiChar(TableName), Length(TableName), // request information for TableName
         SQL_INDEX_ALL,
         SQL_QUICK
       ),
@@ -1563,7 +1563,7 @@ begin
         if ODBCSuccess(Res) then begin
           // note: SQLStatistics not only returns index info, but also statistics; we skip the latter
           if _Type<>SQL_TABLE_STAT then begin
-            if PChar(@IndexName[1])=KeyName then begin
+            if PAnsiChar(@IndexName[1])=KeyName then begin
               // The indexdef is already made as the primary key
               // Only if the index is descending is not known yet.
               if (AscOrDescIndOrLen<>SQL_NULL_DATA) and (AscOrDesc='D') then begin
@@ -1573,8 +1573,8 @@ begin
             end else if (OrdinalPos=1) or not Assigned(IndexDef) then begin
               // create new IndexDef if OrdinalPos=1 or not Assigned(IndexDef) (the latter should not occur though)
               IndexDef:=IndexDefs.AddIndexDef;
-              IndexDef.Name:=PChar(@IndexName[1]); // treat ansistring as zero terminated string
-              IndexDef.Fields:=PChar(@ColName[1]);
+              IndexDef.Name:=PAnsiChar(@IndexName[1]); // treat ansistring as zero terminated string
+              IndexDef.Fields:=PAnsiChar(@ColName[1]);
               if NonUnique=SQL_FALSE then
                 IndexDef.Options:=IndexDef.Options+[ixUnique];
               if (AscOrDescIndOrLen<>SQL_NULL_DATA) and (AscOrDesc='D') then
@@ -1582,7 +1582,7 @@ begin
               // TODO: figure out how we can tell whether COLUMN_NAME is an expression or not
               //       if it is an expression, we should include ixExpression in Options and set Expression to ColName
             end else // NB we re-use the last IndexDef
-              IndexDef.Fields:=IndexDef.Fields+';'+PChar(@ColName[1]); // NB ; is the separator to be used for IndexDef.Fields
+              IndexDef.Fields:=IndexDef.Fields+';'+PAnsiChar(@ColName[1]); // NB ; is the separator to be used for IndexDef.Fields
           end;
         end else begin
           CheckResult(Res, SQL_HANDLE_STMT, StmtHandle, 'Could not fetch index metadata row.');

+ 5 - 5
packages/fcl-db/src/sqldb/oracle/oracleconnection.pp

@@ -334,12 +334,12 @@ procedure TOracleConnection.HandleError;
 
 var
     errcode : sb4;
-    buf     : array[0..1023] of char;
+    buf     : array[0..1023] of AnsiChar;
 
 begin
   OCIErrorGet(FOciError,1,nil,errcode,@buf[0],1024,OCI_HTYPE_ERROR);
 
-  raise EOraDatabaseError.CreateFmt(pchar(buf), [], Self, errcode, '')
+  raise EOraDatabaseError.CreateFmt(PAnsiChar(buf), [], Self, errcode, '')
 end;
 
 procedure TOracleConnection.GetParameters(cursor: TSQLCursor; ATransaction : TSQLTransaction; AParams: TParams);
@@ -673,12 +673,12 @@ begin
 
         if AParams[i].ParamType=ptInput then
           begin
-          if OCIBindByName(FOciStmt,FOcibind,FOciError,pchar(AParams[i].Name),length(AParams[i].Name),OBuffer,OFieldSize,OFieldType,@ParamBuffers[i].ind,nil,nil,0,nil,OCI_DEFAULT )= OCI_ERROR then
+          if OCIBindByName(FOciStmt,FOcibind,FOciError,PAnsiChar(AParams[i].Name),length(AParams[i].Name),OBuffer,OFieldSize,OFieldType,@ParamBuffers[i].ind,nil,nil,0,nil,OCI_DEFAULT )= OCI_ERROR then
             HandleError;
           end
         else if AParams[i].ParamType=ptOutput then
           begin
-          if OCIBindByName(FOciStmt,FOcibind,FOciError,pchar(AParams[i].Name),length(AParams[i].Name),nil,OFieldSize,OFieldType,nil,nil,nil,0,nil,OCI_DATA_AT_EXEC )= OCI_ERROR then
+          if OCIBindByName(FOciStmt,FOcibind,FOciError,PAnsiChar(AParams[i].Name),length(AParams[i].Name),nil,OFieldSize,OFieldType,nil,nil,nil,0,nil,OCI_DATA_AT_EXEC )= OCI_ERROR then
             HandleError;
           if OCIBindDynamic(FOcibind, FOciError, nil, @cbf_no_data, @parambuffers[i], @cbf_get_data) <> OCI_SUCCESS then
             HandleError;
@@ -873,7 +873,7 @@ var Param      : POCIParam;
     FieldSize  : cardinal;
 
     OFieldType   : ub2;
-    OFieldName   : Pchar;
+    OFieldName   : PAnsiChar;
     OFieldSize   : ub4;
     OFNameLength : ub4;
     NumCols      : ub4;

+ 34 - 13
packages/fcl-db/src/sqldb/postgres/pqconnection.pp

@@ -23,7 +23,7 @@ unit PQConnection;
 interface
 
 uses
-  Classes, SysUtils, sqldb, db, dbconst,bufdataset,
+  Classes, Types, SysUtils, sqldb, db, dbconst,bufdataset,
 {$IfDef LinkDynamically}
   postgres3dyn;
 {$Else}
@@ -108,8 +108,8 @@ type
   private
     procedure SetHandle(AValue: TPGhandle);
   protected
-    Statement    : string;
-    StmtName     : string;
+    Statement    : RawByteString;
+    StmtName     : RawByteString;
     Fhandle       : TPGHandle;
     res          : PPGresult;
     CurTuple     : integer;
@@ -146,6 +146,7 @@ type
     FCursorCount         : dword;
     FIntegerDateTimes    : boolean;
     FVerboseErrors       : Boolean;
+    function PGexec(aConnection: PPGconn; query: String): PPGresult;
   protected
     // Protected so they can be used by descendents.
    function GetConnectionString(const aDBName : String) : string;
@@ -481,6 +482,20 @@ begin
 {$EndIf}
 end;
 
+function TPQConnection.PGexec(aConnection : PPGconn; query:String):PPGresult;
+
+Var
+  SQL : RawByteString;
+
+begin
+{$IF SIZEOF(CHAR)=2}
+  SQL:=UTF8Encode(Query);
+{$ELSE}
+  SQL:=Query;
+{$ENDIF}
+  Result:=PQexec(aConnection,PAnsiChar(SQL));
+end;
+
 procedure TPQConnection.GetExtendedFieldInfo(cursor: TPQCursor;
   Bindings: TFieldBindings);
 
@@ -491,7 +506,7 @@ Var
   toid : oid;
 
 begin
-s:='';
+  s:='';
   For I:=0 to Length(Bindings)-1 do
     if (Bindings[i].TypeOID>0) then
       begin
@@ -503,6 +518,8 @@ s:='';
     exit;
   S:='select oid,typname,typtype,typcategory from pg_type where oid in ('+S+') order by oid';
   Res:=Cursor.Handle.Exec(S,False,'Error getting typeinfo');
+  if (PQresultStatus(res)<>PGRES_TUPLES_OK) then
+    CheckResultError(Res,Cursor.tr.PGConn,'Error getting type info');
   try
     For I:=0 to PQntuples(Res)-1 do
       begin
@@ -635,7 +652,6 @@ begin
     {$IFDEF PQDEBUG}
     Writeln('>>> ',T.FHandleID,' [',TThread.CurrentThread.ThreadID, '] Reusing connection ');
     {$ENDIF}
-
     end;
 
   if (Not T.Connected) then
@@ -884,7 +900,7 @@ var
   COLUMN_NAME: string;
   DATATYPE_NAME: string;
   CONSTRAINT_NAME: string;
-  P : Pchar;
+  P : PAnsiChar;
   haveError : Boolean;
   lMessage : String;
 
@@ -986,7 +1002,10 @@ begin
   case AOID of
     Oid_varchar,Oid_bpchar,
     Oid_name               : begin
-                             Result := ftString;
+                             if aOID=Oid_bpchar then
+                               Result:=ftFixedChar
+                             else
+                               Result := ftString;
                              size := PQfsize(Res, Tuple);
                              if (size = -1) then
                                begin
@@ -1231,7 +1250,7 @@ var ar  : array of PAnsiChar;
     bd : TBlobData;
     lengths,formats : array of integer;
     ParamNames,
-    ParamValues : array of string;
+    ParamValues : tansistringdynarray;
     cash: int64;
     PQCurs : TPQCursor;
 
@@ -1362,6 +1381,7 @@ var
   Q : TPQCursor;
   FD : TSQLDBFieldDef;
   FB : PFieldBinding;
+  FN: String;
 
 begin
   B:=False;
@@ -1372,8 +1392,9 @@ begin
     setlength(FieldBinding,nFields);
     for i := 0 to nFields-1 do
       begin
+      FN:=PQfname(Res, i);
       fieldtype := TranslateFldType(Res, i, asize, aoid );
-      FD := AddFieldDef(FieldDefs, i+1, PQfname(Res, i), fieldtype, asize, -1, False, False, False) as TSQLDBFieldDef;
+      FD := AddFieldDef(FieldDefs, i+1, FN, fieldtype, asize, -1, False, False, False) as TSQLDBFieldDef;
       With FD do
         begin
         SQLDBData:=@FieldBinding[i];
@@ -1494,7 +1515,7 @@ var
   x,i           : integer;
   s             : string;
   li            : Longint;
-  CurrBuff      : pchar;
+  CurrBuff      : PAnsiChar;
   dbl           : pdouble;
   cur           : currency;
   NumericRecord : ^TNumericRecord;
@@ -1569,7 +1590,7 @@ begin
               Move(CurrBuff^, Buffer^, li);
             end;
           end;
-          pchar(Buffer + li)^ := #0;
+          PAnsiChar(Buffer + li)^ := #0;
           end;
         ftBlob, ftMemo, ftVarBytes :
           CreateBlob := True;
@@ -1637,7 +1658,7 @@ begin
           dbl^ := BEtoN(PInt64(CurrBuff)^) / 100;
           end;
         ftBoolean:
-          pchar(buffer)[0] := CurrBuff[0];
+          PAnsiChar(buffer)[0] := CurrBuff[0];
         ftGuid:
           begin
           Move(CurrBuff^, guid, sizeof(guid));
@@ -1645,7 +1666,7 @@ begin
           guid.D2:=BEtoN(guid.D2);
           guid.D3:=BEtoN(guid.D3);
           s:=GUIDToString(guid);
-          StrPLCopy(PChar(Buffer), s, FieldDef.Size);
+          StrPLCopy(PAnsiChar(Buffer), s, FieldDef.Size);
           end
         else
           result := false;

+ 3 - 3
packages/fcl-db/src/sqldb/postgres/pqeventmonitor.pp

@@ -199,7 +199,7 @@ begin
     if (FConnection.DatabaseName <> '') then sConn := sConn + ' dbname=''' + FConnection.DatabaseName + '''';
     if (FConnection.Params.Text <> '') then sConn := sConn + ' '+FConnection.Params.Text;
 
-    FDBHandle := PQconnectdb(pchar(sConn));
+    FDBHandle := PQconnectdb(PAnsiChar(sConn));
     if (PQstatus(FDBHandle) <> CONNECTION_OK) then
       begin
       msg := PQerrorMessage(FDBHandle);
@@ -208,7 +208,7 @@ begin
       end;
     for i:=0 to Events.Count-1 do
       begin
-      res := PQexec(FDBHandle,pchar('LISTEN '+ Events[i]));
+      res := PQexec(FDBHandle,PAnsiChar('LISTEN '+ Events[i]));
       if (PQresultStatus(res) <> PGRES_COMMAND_OK) then
         begin
         msg := PQerrorMessage(FDBHandle);
@@ -234,7 +234,7 @@ begin
     begin
     for i:=0 to Events.Count-1 do
       begin
-      res := PQexec(FDBHandle,pchar('unlisten '+ Events[i]));
+      res := PQexec(FDBHandle,PAnsiChar('unlisten '+ Events[i]));
       if (PQresultStatus(res) <> PGRES_COMMAND_OK) then
         begin
         msg := PQerrorMessage(FDBHandle);

+ 32 - 21
packages/fcl-db/src/sqldb/sqldb.pp

@@ -365,7 +365,7 @@ type
     FParamCheck: Boolean;
     FParams: TParams;
     FMacroCheck: Boolean;
-    FMacroChar: Char;
+    FMacroChar: AnsiChar;
     FMacros: TParams;
     FSQL: TStrings;
     FOrigSQL : String;
@@ -375,9 +375,10 @@ type
     FDoUnPrepare : Boolean;
     FDataLink : TDataLink;
     FRowsAffected : TRowsCount;
+    FInfoquery : Boolean;
     function ExpandMacros(const OrigSQL: String): String;
     procedure SetDatabase(AValue: TSQLConnection);
-    procedure SetMacroChar(AValue: Char);
+    procedure SetMacroChar(AValue: AnsiChar);
     procedure SetMacroCheck(AValue: Boolean);
     procedure SetParams(AValue: TParams);
     procedure SetMacros(AValue: TParams);
@@ -415,11 +416,12 @@ type
     Property SQL : TStrings Read FSQL Write SetSQL;
     Property Params : TParams Read FParams Write SetParams stored HasParams;
     Property Macros : TParams Read FMacros Write SetMacros stored HasMacros;
-    property MacroChar: Char read FMacroChar write SetMacroChar default DefaultMacroChar;
+    property MacroChar: AnsiChar read FMacroChar write SetMacroChar default DefaultMacroChar;
     Property DataSource : TDataSource Read GetDataSource Write SetDataSource;
     Property ParseSQL : Boolean Read FParseSQL Write FParseSQL;
     Property ParamCheck : Boolean Read FParamCheck Write FParamCheck default true;
     Property MacroCheck : Boolean Read FMacroCheck Write SetMacroCheck default false;
+    Property InfoQuery : Boolean Read FInfoQuery Write FInfoQuery;
   Public
     constructor Create(AOwner : TComponent); override;
     destructor Destroy; override;
@@ -504,10 +506,10 @@ type
     FUpdateQry,
     FDeleteQry           : TCustomSQLQuery;
     FSequence            : TSQLSequence;
-    procedure CheckPrepare;
+    procedure CheckPrepare(InfoQuery : Boolean);
     procedure CheckUnPrepare;
     procedure FreeFldBuffers;
-    function GetMacroChar: Char;
+    function GetMacroChar: AnsiChar;
     function GetParamCheck: Boolean;
     function GetParams: TParams;
     function GetMacroCheck: Boolean;
@@ -521,7 +523,7 @@ type
     function HasMacros: Boolean;
     Function HasParams : Boolean;
     Function NeedLastInsertID: TField;
-    procedure SetMacroChar(AValue: Char);
+    procedure SetMacroChar(AValue: AnsiChar);
     procedure SetOptions(AValue: TSQLQueryOptions);
     procedure SetParamCheck(AValue: Boolean);
     procedure SetMacroCheck(AValue: Boolean);
@@ -645,7 +647,7 @@ type
     Property ParamCheck : Boolean Read GetParamCheck Write SetParamCheck default true;
     property Macros : TParams read GetMacros Write SetMacros stored HasMacros;
     Property MacroCheck : Boolean Read GetMacroCheck Write SetMacroCheck default false;
-    Property MacroChar : Char Read GetMacroChar Write SetMacroChar default DefaultMacroChar;
+    Property MacroChar : AnsiChar Read GetMacroChar Write SetMacroChar default DefaultMacroChar;
     property ParseSQL : Boolean read GetParseSQL write SetParseSQL default true;
     property UpdateMode : TUpdateMode read FUpdateMode write SetUpdateMode default upWhereKeyOnly;
     property UsePrimaryKeyAsKey : boolean read FUsePrimaryKeyAsKey write SetUsePrimaryKeyAsKey default true;
@@ -967,7 +969,7 @@ begin
     end;
 end;
 
-procedure TCustomSQLStatement.SetMacroChar(AValue: Char);
+procedure TCustomSQLStatement.SetMacroChar(AValue: AnsiChar);
 begin
   if FMacroChar=AValue then Exit;
   FMacroChar:=AValue;
@@ -1228,8 +1230,8 @@ Const
 
 var
   I: Integer;
-  Ch : Char;
-  TermArr : Set of Char;
+  Ch : AnsiChar;
+  TermArr : Set of AnsiChar;
   TempStr, TempMacroName : String;
   MacroFlag : Boolean;
 
@@ -1293,13 +1295,17 @@ begin
   FServerSQL:=ExpandMacros( FOrigSQL );
   GetStatementInfo(FServerSQL,StmInfo);
   AllocateCursor;
+  if FInfoquery then
+    // We signal that we want to have field definitions.
+    // This is needed for e.g. postgres, where the result of the prepare statement is not enough to get field defs.
+    FCursor.FInitFieldDef:=True;
   FCursor.FSelectable:=True; // let PrepareStatement and/or Execute alter it
   FCursor.FStatementType:=StmInfo.StatementType;
   FCursor.FSchemaType:=GetSchemaType;
   If LogEvent(detPrepare) then
     Log(detPrepare,FServerSQL);
   Database.PrepareStatement(FCursor,Transaction,FServerSQL,FParams);
-  // Update
+  // Update FInitFieldDef with whatever we got from the server.
   FCursor.FInitFieldDef:=FCursor.FSelectable;
 end;
 
@@ -1738,7 +1744,7 @@ const
 
 var
   PSQL, CurrentP, SavedP,
-  PhraseP, PStatementPart : pchar;
+  PhraseP, PStatementPart : PChar;
   S                       : string;
   ParsePart               : TParsePart;
   BracketCount            : Integer;
@@ -2840,7 +2846,7 @@ end;
 procedure TCustomSQLQuery.OpenCursor(InfoQuery: Boolean);
 begin
   if InfoQuery then
-    CheckPrepare;
+    CheckPrepare(InfoQuery);
   try
     inherited OpenCursor(InfoQuery);
   finally
@@ -2993,7 +2999,7 @@ begin
      SQLConnection.FreeFldBuffers(Cursor);
 end;
 
-function TCustomSQLQuery.GetMacroChar: Char;
+function TCustomSQLQuery.GetMacroChar: AnsiChar;
 begin
   Result := FStatement.MacroChar;
 end;
@@ -3147,7 +3153,7 @@ begin
     end
   else
     begin
-    CheckPrepare;
+    CheckPrepare(False);
     if not Cursor.FSelectable then
       DatabaseError(SErrNoSelectStatement,Self);
 
@@ -3174,7 +3180,7 @@ begin
           if ixPrimary in ServerIndexDefs[counter].Options then
             begin
             IndexFields := TStringList.Create;
-            ExtractStrings([';'],[' '],pchar(ServerIndexDefs[counter].Fields),IndexFields);
+            ExtractStrings([';'],[' '],PAnsiChar(ServerIndexDefs[counter].Fields),IndexFields);
             for fieldc := 0 to IndexFields.Count-1 do
               begin
               F := FindField(IndexFields[fieldc]);
@@ -3205,13 +3211,18 @@ end;
 
 // public part
 
-procedure TCustomSQLQuery.CheckPrepare;
+procedure TCustomSQLQuery.CheckPrepare(InfoQuery : Boolean);
 
 begin
   if Not IsPrepared then
     begin
-    Prepare;
-    FDoUnPrepare:=True;
+    FStatement.FInfoquery:=InfoQuery;
+    try
+      Prepare;
+      FDoUnPrepare:=True;
+    finally
+      FStatement.FInfoquery:=False;
+    end;
     end;
 end;
 
@@ -3229,7 +3240,7 @@ end;
 procedure TCustomSQLQuery.ExecSQL;
 
 begin
-  CheckPrepare;
+  CheckPrepare(False);
   try
     Execute;
     // Always retrieve rows affected
@@ -3327,7 +3338,7 @@ begin
     end
 end;
 
-procedure TCustomSQLQuery.SetMacroChar(AValue: Char);
+procedure TCustomSQLQuery.SetMacroChar(AValue: AnsiChar);
 begin
   FStatement.MacroChar:=AValue;
 end;

+ 2 - 2
packages/fcl-db/src/sqldb/sqlite/sqlite3backup.pas

@@ -101,8 +101,8 @@ begin
    FErrorMessage:='';
    Source.Connected:=true;
    Destination.Connected:=true;
-   pBackup := sqlite3_backup_init(Destination.Handle, pchar(DestinationDBName),
-      Source.Handle, pchar(SourceDBName));
+   pBackup := sqlite3_backup_init(Destination.Handle, PAnsiChar(DestinationDBName),
+      Source.Handle, PAnsiChar(SourceDBName));
    if LockUntilFinished then
      nPage:=-1
    else

+ 13 - 13
packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp

@@ -165,7 +165,7 @@ type
    fhandle : psqlite3;
    fconnection: TSQLite3Connection;
    fstatement: psqlite3_stmt;
-   ftail: pchar;
+   ftail: PAnsiChar;
    fstate: integer;
    fparambinding: array of Integer;
    procedure checkerror(const aerror: integer);
@@ -268,7 +268,7 @@ begin
     S := AParams.ParseSQL(S,false,false,false,psInterbase,fparambinding);
   if (detActualSQL in fconnection.LogEvents) then
     fconnection.Log(detActualSQL,S);
-  checkerror(sqlite3_prepare(fhandle,pchar(S),length(S),@fstatement,@ftail));
+  checkerror(sqlite3_prepare(fhandle,PAnsiChar(S),length(S),@fstatement,@ftail));
   FPrepared:=True;
 end;
 
@@ -446,7 +446,7 @@ Const
    (n:'CURRENCY'; t: ftCurrency),
    (n:'MONEY'; t: ftCurrency),
    (n:'VARCHAR'; t: ftString),
-   (n:'CHAR'; t: ftFixedChar),
+   (n:'AnsiChar'; t: ftFixedChar),
    (n:'NUMERIC'; t: ftBCD),
    (n:'DECIMAL'; t: ftBCD),
    (n:'TEXT'; t: ftMemo),
@@ -599,7 +599,7 @@ begin
   SC.Execute;
 end;
 
-Function NextWord(Var S : ShortString; Sep : Char) : String;
+Function NextWord(Var S : ShortString; Sep : AnsiChar) : String;
 
 Var
   P : Integer;
@@ -880,7 +880,7 @@ const
   PRAGMAS:array[0..1] of string=('foreign_keys','journal_mode');
 var
   filename: ansistring;
-  pvfs: PChar;
+  pvfs: PAnsiChar;
   i,j: integer;
 begin
   Inherited;
@@ -894,7 +894,7 @@ begin
     pvfs := Nil;
   checkerror(sqlite3_open_v2(PAnsiChar(filename),@fhandle,GetSQLiteOpenFlags,pvfs));
   if (Length(Password)>0) and assigned(sqlite3_key) then
-    checkerror(sqlite3_key(fhandle,PChar(Password),StrLen(PChar(Password))));
+    checkerror(sqlite3_key(fhandle,PAnsiChar(Password),StrLen(PAnsiChar(Password))));
   for i:=Low(PRAGMAS) to High(PRAGMAS) do begin
     j:=Params.IndexOfName(PRAGMAS[i]);
     if j <> -1 then
@@ -941,12 +941,12 @@ end;
 
 procedure TSQLite3Connection.execsql(const asql: string);
 var
- err  : pchar;
+ err  : PAnsiChar;
  str1 : string;
  res  : integer;
 begin
  err:= nil;
- Res := sqlite3_exec(fhandle,pchar(asql),nil,nil,@err);
+ Res := sqlite3_exec(fhandle,PAnsiChar(asql),nil,nil,@err);
  if err <> nil then 
    begin
    str1:= strpas(err);
@@ -962,7 +962,7 @@ begin
 end;
 
 function execcallback(adata: pointer; ncols: longint; //adata = PStringArray
-                avalues: PPchar; anames: PPchar):longint; cdecl;
+                avalues: PPAnsiChar; anames: PPAnsiChar):longint; cdecl;
 var
   P : PStringArray;
   i : integer;
@@ -976,7 +976,7 @@ begin
 end;
 
 function execscallback(adata: pointer; ncols: longint; //adata = PArrayStringArray
-                avalues: PPchar; anames: PPchar):longint; cdecl;
+                avalues: PPAnsiChar; anames: PPAnsiChar):longint; cdecl;
 var
  I,N : integer;
  PP : PArrayStringArray;
@@ -996,7 +996,7 @@ end;
 function TSQLite3Connection.stringsquery(const asql: string): TArrayStringArray;
 begin
   SetLength(result,0);
-  checkerror(sqlite3_exec(fhandle,pchar(asql),@execscallback,@result,nil));
+  checkerror(sqlite3_exec(fhandle,PAnsiChar(asql),@execscallback,@result,nil));
 end;
 
 function TSQLite3Connection.GetSchemaInfoSQL(SchemaType: TSchemaType;
@@ -1180,7 +1180,7 @@ begin
     Compare := @UTF8CompareCallback;
   end;
   CheckConnected;
-  CheckError(sqlite3_create_collation(fhandle, PChar(CollationName), eTextRep, Arg, Compare));
+  CheckError(sqlite3_create_collation(fhandle, PAnsiChar(CollationName), eTextRep, Arg, Compare));
 end;
 
 procedure TSQLite3Connection.LoadExtension(const LibraryFile: string);
@@ -1193,7 +1193,7 @@ begin
     LoadResult:=sqlite3_enable_load_extension(fhandle, 1); //Make sure we are allowed to load
     if LoadResult=SQLITE_OK then
       begin
-      LoadResult:=sqlite3_load_extension(fhandle, PChar(LibraryFile), nil, nil); //Actually load extension
+      LoadResult:=sqlite3_load_extension(fhandle, PAnsiChar(LibraryFile), nil, nil); //Actually load extension
       if LoadResult=SQLITE_ERROR then
         begin
         DatabaseError('LoadExtension: failed to load SQLite extension (SQLite returned an error while loading).',Self);

+ 13 - 8
packages/fcl-db/tests/bufdatasettoolsunit.pas

@@ -35,13 +35,6 @@ type
     function GetTestUniDirectional: boolean; override;
   end;
 
-implementation
-
-uses
-  StrUtils, FmtBCD;
-
-type
-
   { TPersistentBufDataSet }
 
   TPersistentBufDataSet=class(TBufDataset)
@@ -53,6 +46,13 @@ type
       destructor Destroy; override;
   end;
 
+
+implementation
+
+uses
+  StrUtils, FmtBCD;
+
+
 { TPersistentBufDataSet }
 
 procedure TPersistentBufDataSet.LoadBlobIntoBuffer(FieldDef: TFieldDef; ABlobBuf: PBufBlobField);
@@ -112,7 +112,9 @@ begin
     MergeChangeLog;
     TempFileName:=GetTempFileName;
     FileName:=TempFileName;
+    // Writeln(FileName);
     Close; // Save data into file
+    Fields.Clear;
     end;
   Result := BufDataset;
 end;
@@ -144,7 +146,7 @@ begin
     FieldDefs.Add('FDATE',ftDate);
     FieldDefs.Add('FTIME',ftTime);
     FieldDefs.Add('FDATETIME',ftDateTime);
-    FieldDefs.Add('FVARBYTES',ftVarBytes,10);
+    FieldDefs.Add('FVARBYTES',ftVarBytes,20);
     FieldDefs.Add('FBLOB',ftBlob);
     FieldDefs.Add('FMEMO',ftMemo);
     FieldDefs.Add('FFIXEDCHAR',ftFixedChar,10);
@@ -178,6 +180,9 @@ begin
       FieldByName('FTIME').AsDateTime := StrToTime(testTimeValues[i], Self.FormatSettings);
       FieldByName('FDATETIME').AsDateTime := StrToDateTime(testValues[ftDateTime,i], Self.FormatSettings);
       FieldByName('FVARBYTES').AsString := testStringValues[i];
+{      if not (FieldByName('FVARBYTES').AsString = testStringValues[i]) then
+        Writeln('Error');
+        }
       FieldByName('FBLOB').AsString := testStringValues[i];
       FieldByName('FMEMO').AsString := testStringValues[i];
       FieldByName('FFIXEDCHAR').AsString := PadRight(testStringValues[i], 10);

+ 6 - 6
packages/fcl-db/tests/dbftoolsunit.pas

@@ -57,10 +57,10 @@ type
   TDbfTraceDataset = class(TdbfAutoClean)
   protected
     procedure SetCurrentRecord(Index: longint); override;
-    procedure RefreshInternalCalcFields(Buffer: PChar); override;
+    procedure RefreshInternalCalcFields(Buffer: PAnsiChar); override;
     procedure InternalInitFieldDefs; override;
-    procedure CalculateFields(Buffer: PChar); override;
-    procedure ClearCalcFields(Buffer: PChar); override;
+    procedure CalculateFields(Buffer: PAnsiChar); override;
+    procedure ClearCalcFields(Buffer: PAnsiChar); override;
   end;
 
 
@@ -293,7 +293,7 @@ begin
   inherited SetCurrentRecord(Index);
 end;
 
-procedure TDbfTraceDataset.RefreshInternalCalcFields(Buffer: PChar);
+procedure TDbfTraceDataset.RefreshInternalCalcFields(Buffer: PAnsiChar);
 begin
   DataEvents := DataEvents + 'RefreshInternalCalcFields' + ';';
   inherited RefreshInternalCalcFields(Buffer);
@@ -320,13 +320,13 @@ begin
     end;
 end;
 
-procedure TDbfTraceDataset.CalculateFields(Buffer: PChar);
+procedure TDbfTraceDataset.CalculateFields(Buffer: PAnsiChar);
 begin
   DataEvents := DataEvents + 'CalculateFields' + ';';
   inherited CalculateFields(Buffer);
 end;
 
-procedure TDbfTraceDataset.ClearCalcFields(Buffer: PChar);
+procedure TDbfTraceDataset.ClearCalcFields(Buffer: PAnsiChar);
 begin
   DataEvents := DataEvents + 'ClearCalcFields' + ';';
   inherited ClearCalcFields(Buffer);

+ 6 - 2
packages/fcl-db/tests/dbtestframework.lpi

@@ -7,6 +7,7 @@
         <SaveOnlyProjectUnits Value="True"/>
         <MainUnitHasCreateFormStatements Value="False"/>
         <MainUnitHasTitleStatement Value="False"/>
+        <MainUnitHasScaledStatement Value="False"/>
         <CompatibilityMode Value="True"/>
       </Flags>
       <SessionStorage Value="InProjectDir"/>
@@ -25,13 +26,13 @@
     </PublishOptions>
     <RunParams>
       <local>
-        <CommandLineParams Value="--suite=TTestFieldTypes.TestRefresh"/>
+        <CommandLineParams Value="--suite=TTestFieldTypes.TestBlobParamQuery"/>
       </local>
       <FormatVersion Value="2"/>
       <Modes Count="1">
         <Mode0 Name="default">
           <local>
-            <CommandLineParams Value="--suite=TTestFieldTypes.TestRefresh"/>
+            <CommandLineParams Value="--suite=TTestFieldTypes.TestBlobParamQuery"/>
           </local>
         </Mode0>
       </Modes>
@@ -128,6 +129,9 @@
         <UseAnsiStrings Value="False"/>
       </SyntaxOptions>
     </Parsing>
+    <Other>
+      <CustomOptions Value="-tunicodertl"/>
+    </Other>
   </CompilerOptions>
   <Debugging>
     <Exceptions Count="3">

+ 11 - 7
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -42,6 +42,7 @@ type
     procedure CreateFConnection;
     Function CreateQuery : TSQLQuery;
   protected
+    procedure ClearDatasets; override;
     procedure SetTestUniDirectional(const AValue: boolean); override;
     function GetTestUniDirectional: boolean; override;
     procedure CreateNDatasets; override;
@@ -408,7 +409,7 @@ begin
     for i := 0 to testValuesCount-1 do
       testValues[ftCurrency,i] := QuotedStr(CurrToStr(testCurrencyValues[i]));
 
-  // SQLite does not support fixed length CHAR datatype
+  // SQLite does not support fixed length Char datatype
   if SQLServerType in [ssSQLite] then
     for i := 0 to testValuesCount-1 do
       testValues[ftFixedChar,i] := PadRight(testValues[ftFixedChar,i], 10);
@@ -724,11 +725,7 @@ end;
 
 procedure TSQLDBConnector.TryCreateSequence(ASequenceName: String);
 
-var
-  NoSeq : Boolean;
-
 begin
-  NoSeq:=False;
   case SQLServerType of
     ssInterbase,
     ssFirebird: FConnection.ExecuteDirect('CREATE GENERATOR '+ASequenceName);
@@ -761,9 +758,10 @@ begin
   FreeAndNil(FTransaction);
 end;
 
-destructor TSQLDBConnector.Destroy;
+Procedure TSQLDBConnector.ClearDatasets;
+
 begin
-  FreeAndNil(FQuery);
+  Inherited;
   if assigned(FTransaction) then
     begin
     try
@@ -781,6 +779,12 @@ begin
         Ftransaction.Rollback;
     end; // try
     end;
+end;
+
+destructor TSQLDBConnector.Destroy;
+begin
+  ClearDatasets;
+  FreeAndNil(FQuery);
   FreeTransaction;
   FreeAndNil(FConnection);
   inherited Destroy;

+ 2 - 2
packages/fcl-db/tests/testdatasources.pas

@@ -571,7 +571,7 @@ procedure TTestDatasources.TestCalculateFields;
 var ds, lkpDs   : TDataset;
     AFld1, AFld2, AFld3 : Tfield;
     StoreValue : Variant;
-    Buffer: pchar;
+    Buffer: PAnsiChar;
 begin
   ds := DBConnector.GetTraceDataset(True);
   lkpDs := DBConnector.GetNDataset(5);
@@ -633,7 +633,7 @@ end;
 procedure TTestDatasources.TestCalcLookupValue;
 var ds, lkpDs   : TDataset;
     AFld1, AFld2, AFld3 : Tfield;
-    Buffer: pchar;
+    Buffer: PAnsiChar;
 begin
   ds := DBConnector.GetNDataset(True,15);
   lkpDs := DBConnector.GetNDataset(5);

+ 13 - 11
packages/fcl-db/tests/testdbbasics.pas

@@ -1185,18 +1185,18 @@ begin
     begin
     open;
     AVar:=FieldValues['id'];
-    CheckEquals(AVar,1);
+    CheckEquals(1,AVar);
 
     AVar:=FieldValues['name'];
-    CheckEquals(AVar,'TestName1');
+    CheckEquals('TestName1',AVar);
 
     AVar:=FieldValues['id;name'];
-    CheckEquals(AVar[0],1);
-    CheckEquals(AVar[1],'TestName1');
+    CheckEquals(1,AVar[0]);
+    CheckEquals('TestName1',AVar[1]);
 
     AVar:=FieldValues['name;id;'];
-    CheckEquals(AVar[1],1);
-    CheckEquals(AVar[0],'TestName1');
+    CheckEquals(1,AVar[1]);
+    CheckEquals('TestName1',AVar[0]);
     
     PassException:=false;
     try
@@ -1205,7 +1205,6 @@ begin
       on E: EDatabaseError do PassException := True;
     end;
     CheckTrue(PassException);
-
     end;
 end;
 
@@ -2603,7 +2602,7 @@ begin
 
   for i := 0 to testValuesCount-1 do
     begin
-    CheckEquals(testValues[AFieldType,i], AField.AsString);
+    CheckEquals(testValues[AFieldType,i], AField.AsAnsiString);
     ADataSet.Next;
     end;
   ADataSet.Close;
@@ -3067,6 +3066,7 @@ begin
 end;
 
 procedure TTestDBBasics.TestCanModifySpecialFields;
+
 var ds    : TDataset;
     lds   : TDataset;
     fld   : TField;
@@ -3078,6 +3078,9 @@ begin
     Fld := TIntegerField.Create(ds);
     Fld.FieldName:='ID';
     Fld.DataSet:=ds;
+    Fld := TStringField.Create(ds);
+    Fld.FieldName:='Name';
+    Fld.DataSet:=ds;
 
     Fld := TStringField.Create(ds);
     Fld.FieldName:='LookupFld';
@@ -3087,8 +3090,8 @@ begin
     Fld.LookupResultField:='NAME';
     Fld.LookupKeyFields:='ID';
     Fld.KeyFields:='ID';
-
     lds.Open;
+
     Open;
     if IsUniDirectional then
       // The CanModify property is always False for UniDirectional datasets
@@ -3098,7 +3101,6 @@ begin
     CheckFalse(FieldByName('LookupFld').CanModify);
     CheckFalse(FieldByName('ID').ReadOnly);
     CheckFalse(FieldByName('LookupFld').ReadOnly);
-
     CheckEquals(1,FieldByName('ID').AsInteger);
     if IsUniDirectional then
       // Lookup fields are not supported by UniDirectional datasets
@@ -3297,7 +3299,7 @@ initialization
   RegisterTestDecorator(TDBBasicsTestSetup, TTestCursorDBBasics);
 
   // The SQL connectors are descendents of bufdataset and therefore benefit from testing:
-  if (uppercase(dbconnectorname)='SQL') or (uppercase(dbconnectorname)='BUFDATASET') then
+  if (uppercase(dbconnectorname)='SQL') {or (uppercase(dbconnectorname)='BUFDATASET') } then
     begin
     RegisterTestDecorator(TDBBasicsTestSetup, TTestBufDatasetDBBasics);
     RegisterTestDecorator(TDBBasicsUniDirectionalTestSetup, TTestUniDirectionalDBBasics);

+ 12 - 10
packages/fcl-db/tests/testdbexport.pas

@@ -7,6 +7,7 @@ unit TestDBExport;
 {$IFDEF FPC}
   {$mode Delphi}{$H+}
 {$ENDIF}
+{$codepage utf8}
 
 interface
 
@@ -30,7 +31,7 @@ type
     efJSON, efRTF, efSQL, efTeX, efXML, efXMLXSDAccess, efXMLXSDADONet, efXMLXSDClientDataset,
     efXMLXSDExcel, efVisualFoxpro);
 const
-  TDetailedExportExtensions: array [TDetailedExportFormats] of string[5] =
+  TDetailedExportExtensions: array [TDetailedExportFormats] of string =
     ('.dbf','.dbf','.dbf','.csv','.txt','.dbf','.json','.rtf','.sql','.tex',
     '.xml','.xml','.xml','.xml','.xml','.dbf'); //File extension for the corresponding TDetailedExportFormats
 type
@@ -83,7 +84,7 @@ type
 
 implementation
 
-uses xmlread,dom;
+uses bufdatasettoolsunit, xmlread,dom;
 
 
 function TTestDBExport.FieldSupported(const FieldType: TFieldType;
@@ -393,7 +394,7 @@ begin
     ExportSettings.ExportFormat:=AccessCompatible;
     ExportFormat:=efXMLXSDAccess;
     ExportSettings.CreateXSD:=true;
-    ExportSettings.DecimalSeparator:=char(#0); //don't override
+    ExportSettings.DecimalSeparator:=AnsiChar(#0); //don't override
     Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
       lowercase(rightstr(TestName,5)) +
       TDetailedExportExtensions[ExportFormat];
@@ -632,7 +633,7 @@ Var
   DS : TBufDataset;
 
 begin
-  DS:=TBufDataset.Create(Nil);
+  DS:=TPersistentBufDataset.Create(Nil);
   try
     DS.FieldDefs.Add('F',ftWideString,10);
     DS.CreateDataset;
@@ -742,7 +743,7 @@ Var
   DS : TBufDataset;
 
 begin
-  DS:=TBufDataset.Create(Nil);
+  DS:=TPersistentBufDataSet.Create(Nil);
   try
     DS.FieldDefs.Add('F',ftBoolean,0);
     DS.CreateDataset;
@@ -766,7 +767,7 @@ Var
   DS : TBufDataset;
 
 begin
-  DS:=TBufDataset.Create(Nil);
+  DS:=TPersistentBufDataset.Create(Nil);
   try
     DS.FieldDefs.Add('A',ftString,2);
     DS.FieldDefs.Add('B',ftString,2);
@@ -850,8 +851,9 @@ begin
     Exporter.FormatSettings.HeaderRow:=True;
     Exporter.Dataset:=DS;
     Exporter.FileName := FExportTempDir + lowercase(TestName) + '.txt';
+
     Exporter.BuildDefaultFieldMap(Exporter.ExportFields);
-    AssertEquals('Correct width',5, TFixedLengthExportFieldItem(Exporter.ExportFields[0]).Width);
+    AssertEquals('Correct width',2, TFixedLengthExportFieldItem(Exporter.ExportFields[0]).Width);
     AssertEquals('Output count',2,Exporter.Execute);
     AssertTrue('Output file must be created', FileExists(Exporter.FileName));
     AssertFalse('Output file must not be empty', (GetFileSize(Exporter.FileName) = 0));
@@ -859,11 +861,11 @@ begin
     Reset(F);
     haveFile:=True;
     Readln(F,S);
-    AssertEquals('Correct header line','F    ',S); // 1 extra
+    AssertEquals('Correct header line','A B C ',S); // 1 extra
     Readln(F,S);
-    AssertEquals('Correct first line','True ',S); // 1 extra
+    AssertEquals('Correct first line','xxy zz',S); // 1 extra
     Readln(F,S);
-    AssertEquals('Correct second line','false',S);
+    AssertEquals('Correct second line','x yyz ',S);
   finally
     if HaveFile then
       closeFile(F);

+ 27 - 29
packages/fcl-db/tests/testfieldtypes.pas

@@ -491,14 +491,13 @@ begin
     L := '';
     for I := 1 to 200 do
       L := L + S;
-    Write('Length(L) = ', Length(L));
 
     // insert the long text into DB
     Q.SQL.Text := 'INSERT INTO [dbo].[NVARCHARMAX] ([Longtext], [Shorttext]) VALUES (:longtext, :shorttext)';
     Q.Params[0].AsString := L;
     Q.Params[1].AsString := S;
     Q.ExecSQL;
-    WriteLn('. OK');
+
 
     // check L in WHERE
     Q.SQL.Text := 'SELECT [Shorttext] FROM [dbo].[NVARCHARMAX] WHERE [Shorttext]=:shorttext';
@@ -514,11 +513,9 @@ begin
     // build a long text with exactly 2001 characters (1 character above the maximum for SQL_WVARCHAR)
     Q.SQL.Text := 'INSERT INTO [dbo].[NVARCHARMAX] ([Longtext], [Shorttext]) VALUES (:longtext, :shorttext)';
     L := L + '1';
-    Write('Length(L) = ', Length(L));
     Q.Params[0].AsString := L;
     Q.Params[1].AsString := S;
     Q.ExecSQL;
-    WriteLn('. OK');
 
     // check L in WHERE
     Q.SQL.Text := 'SELECT [Longtext] FROM [dbo].[NVARCHARMAX] WHERE [Longtext]=convert(nvarchar(max), :longtext)';
@@ -692,13 +689,13 @@ begin
   with TSQLDBConnector(DBConnector).Query do
     begin
     Open;
-    AssertEquals('Test this blob',fields[0].AsString);
+    AssertEquals('Test this blob',fields[0].AsAnsiString);
     close;
     end;
 end;
 
 procedure TTestFieldTypes.TestChangeBlob;
-var s : string;
+var s : ansistring;
 begin
   TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (ID int,FT '+FieldtypeDefinitions[ftblob]+')');
   TSQLDBConnector(DBConnector).CommitDDL;
@@ -710,20 +707,20 @@ begin
     sql.clear;
     sql.add('select * from FPDEV2');
     Open;
-    AssertEquals('Test this blob', Fields[1].AsString);
+    AssertEquals('Test this blob', Fields[1].AsAnsiString);
     Fields[1].ProviderFlags := [pfInUpdate]; // Blob is not in the where
     UpdateMode := upWhereAll;
 
     Edit;
     s := 'This blob has changed!';
-    Fields[1].AsString := s;
-    AssertEquals(s, Fields[1].AsString); // test before Post
+    Fields[1].AsAnsiString := s;
+    AssertEquals(s, Fields[1].AsAnsiString); // test before Post
     Cancel;
-    AssertEquals('After Cancel', 'Test this blob', Fields[1].AsString); // original value
+    AssertEquals('After Cancel', 'Test this blob', Fields[1].AsAnsiString); // original value
 
     Append; // Blob is null
-    Fields[1].AsString := s; // Null flag must be unset
-    AssertEquals(s, Fields[1].AsString);
+    Fields[1].AsAnsiString := s; // Null flag must be unset
+    AssertEquals(s, Fields[1].AsAnsiString);
     Fields[1].Clear;
     AssertTrue('Clear', Fields[1].IsNull);
     Cancel;
@@ -736,14 +733,14 @@ begin
       Post;
       Free;
       end;
-    AssertEquals('After Post', s, Fields[1].AsString);
+    AssertEquals('After Post', s, Fields[1].AsAnsiString);
 
     ApplyUpdates(0);
     TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
     Close;
 
     Open;
-    AssertEquals(s, Fields[1].AsString);
+    AssertEquals('Reading again',s, Fields[1].AsAnsiString);
     Close;
     end;
 end;
@@ -761,11 +758,11 @@ begin
     Open;
     AssertFalse(fields[0].IsNull);
     AssertEquals('(BLOB)',fields[0].DisplayText);
-    AssertEquals('Test this blob',fields[0].AsString);
+    AssertEquals('Test this blob',fields[0].AsAnsiString);
     Next;
     AssertTrue(fields[0].IsNull);
     AssertEquals('(blob)',fields[0].Text);
-    AssertEquals('',fields[0].AsString);
+    AssertEquals('',fields[0].AsAnsiString);
     close;
     end;
 end;
@@ -1674,7 +1671,7 @@ end;
 
 procedure TTestFieldTypes.TestFixedStringParamQuery;
 begin
-  TestXXParamQuery(ftFixedChar,'CHAR(10)',testValuesCount);
+  TestXXParamQuery(ftFixedChar,'AnsiChar(10)',testValuesCount);
 end;
 
 procedure TTestFieldTypes.TestXXParamQuery(ADataType : TFieldType; ASQLTypeDecl : string;
@@ -1708,6 +1705,7 @@ begin
 
     for i := 0 to ParamValuesCount-1 do
       begin
+      // Writeln('i : ',I,' (',Length(TEncoding.Default.GetAnsiBytes(testBlobValues[i])),')');
       Params.ParamByName('id').AsInteger := i;
       case ADataType of
         ftSmallInt: Params.ParamByName('field1').AsSmallInt := testSmallIntValues[i];
@@ -1726,7 +1724,7 @@ begin
                       Params.ParamByName('field1').AsDate := StrToDate(testDateValues[i],'yyyy/mm/dd','-');
         ftDateTime: Params.ParamByName('field1').AsDateTime := StrToDateTime(testValues[ADataType,i], DBConnector.FormatSettings);
         ftFMTBcd  : Params.ParamByName('field1').AsFMTBCD := StrToBCD(ParamValues[i], DBConnector.FormatSettings);
-        ftBlob    : Params.ParamByName('field1').AsBlob := BytesOf(testBlobValues[i]);
+        ftBlob    : Params.ParamByName('field1').AsBlob := TEncoding.Default.GetAnsiBytes(testBlobValues[i]);
         ftLongWord: Params.ParamByName('field1').AsLongWord := testLongWordValues[i];
         ftBytes   : if cross then
                       Params.ParamByName('field1').Value := StringToByteArray(testBytesValues[i])
@@ -1769,14 +1767,14 @@ begin
         ftDate     : AssertEquals(testDateValues[i],DateTimeToStr(FieldByName('FIELD1').AsDateTime, DBConnector.FormatSettings));
         ftDateTime : AssertEquals(testValues[ADataType,i], DateTimeToStr(FieldByName('FIELD1').AsDateTime, DBConnector.FormatSettings));
         ftFMTBcd   : AssertEquals(ParamValues[i], BCDToStr(FieldByName('FIELD1').AsBCD, DBConnector.FormatSettings));
-        ftBlob     : AssertEquals(testBlobValues[i], FieldByName('FIELD1').AsString);
+        ftBlob     : AssertEquals(testBlobValues[i], FieldByName('FIELD1').AsAnsiString);
         ftLongWord : AssertEquals(testLongWordValues[i], FieldByName('FIELD1').AsLongWord);
         ftVarBytes,
         ftBytes    : AssertEquals(testBytesValues[i], shortstring(FieldByName('FIELD1').AsString));
       else
         AssertTrue('no test for paramtype available',False);
       end;
-      AssertEquals('IsNull', False, FieldByName('FIELD1').IsNull);
+      AssertEquals(IntToStr(i)+' May not be Null', False, FieldByName('FIELD1').IsNull);
       Next;
       end;
     AssertTrue('Expected IsNull', FieldByName('FIELD1').IsNull);
@@ -1799,7 +1797,7 @@ begin
       begin
       case asWhat of
         0: Params.ParamByName('blobParam').AsMemo   := TestBlobValues[i];
-        1: Params.ParamByName('blobParam').AsBlob   := BytesOf(TestBlobValues[i]);
+        1: Params.ParamByName('blobParam').AsBlob   := TEncoding.Default.GetAnsiBytes(TestBlobValues[i]);
         2: Params.ParamByName('blobParam').AsString := TestBlobValues[i];
       end;
       ExecSQL;
@@ -1811,7 +1809,7 @@ begin
     Open;
     for i:=0 to testBlobValuesCount - 1 do
       begin
-      AssertEquals(TestBlobValues[i], Fields[0].AsString);
+      AssertEquals(Format('What: %d - Val: %d',[asWhat,I]), TestBlobValues[i], Fields[0].AsAnsiString);
       Next;
       end;
     AssertTrue(Fields[0].IsNull);
@@ -2493,15 +2491,15 @@ begin
   AssertEquals('dit is een string was een string',StringsReplace('dit was een string was een string',['was'],['is'],[]));
   AssertEquals('dit is een string is een string',StringsReplace('dit was een string was een string',['was'],['is'],[rfReplaceAll]));
 
-  AssertEquals('dit is een char is een char',StringsReplace('dit was een string was een string',['was','string'],['is','char'],[rfReplaceAll]));
-  AssertEquals('dit is een string was een string',StringsReplace('dit was een string was een string',['string','was'],['char','is'],[]));
+  AssertEquals('dit is een AnsiChar is een AnsiChar',StringsReplace('dit was een string was een string',['was','string'],['is','AnsiChar'],[rfReplaceAll]));
+  AssertEquals('dit is een string was een string',StringsReplace('dit was een string was een string',['string','was'],['AnsiChar','is'],[]));
 
-  AssertEquals('dit is een char is een strin',StringsReplace('dit was een string was een strin',['string','was'],['char','is'],[rfReplaceAll]));
+  AssertEquals('dit is een AnsiChar is een strin',StringsReplace('dit was een string was een strin',['string','was'],['AnsiChar','is'],[rfReplaceAll]));
 
-  AssertEquals('dit Was een char is een char',StringsReplace('dit Was een string was een string',['was','string'],['is','char'],[rfReplaceAll]));
-  AssertEquals('dit wAs een char is een char',StringsReplace('dit wAs een string was een string',['was','string'],['is','char'],[rfReplaceAll]));
-  AssertEquals('dit is een char is een char',StringsReplace('dit Was een sTring was een string',['was','string'],['is','char'],[rfReplaceAll,rfIgnoreCase]));
-  AssertEquals('dit is een char is een char',StringsReplace('dit wAs een STRING was een string',['was','string'],['is','char'],[rfReplaceAll,rfIgnoreCase]));
+  AssertEquals('dit Was een AnsiChar is een AnsiChar',StringsReplace('dit Was een string was een string',['was','string'],['is','AnsiChar'],[rfReplaceAll]));
+  AssertEquals('dit wAs een AnsiChar is een AnsiChar',StringsReplace('dit wAs een string was een string',['was','string'],['is','AnsiChar'],[rfReplaceAll]));
+  AssertEquals('dit is een AnsiChar is een AnsiChar',StringsReplace('dit Was een sTring was een string',['was','string'],['is','AnsiChar'],[rfReplaceAll,rfIgnoreCase]));
+  AssertEquals('dit is een AnsiChar is een AnsiChar',StringsReplace('dit wAs een STRING was een string',['was','string'],['is','AnsiChar'],[rfReplaceAll,rfIgnoreCase]));
 
   AssertEquals('dit was een si was een sa',StringsReplace('dit was een string was een straat',['straat','string'],['sa','si'],[rfReplaceAll]));
   AssertEquals('dit was een si was een sa',StringsReplace('dit was een string was een straat',['string','straat'],['si','sa'],[rfReplaceAll]));

+ 2 - 2
packages/fcl-db/tests/testsqlscript.pas

@@ -816,9 +816,9 @@ var s : string;
 begin
   StopExecution := StopToSend;
   if Argument = '' then
-    s := Directive
+    s := UTF8Decode(Directive)
   else
-    s := format ('%s(%s)', [Directive, Argument]);
+    s := UTF8Decode(format ('%s(%s)', [UTF8Decode(Directive), UTF8Decode(Argument)]));
   if received <> '' then
     received := received + ';' + s
   else

+ 10 - 2
packages/fcl-db/tests/toolsunit.pas

@@ -30,6 +30,7 @@ type
      protected
        FChangedDatasets : array[0..MaxDataSet] of boolean;
        FUsedDatasets : TFPList;
+       procedure ClearDatasets; virtual;
        procedure SetTestUniDirectional(const AValue: boolean); virtual;
        function GetTestUniDirectional: boolean; virtual;
        // These methods should be implemented by all descendents
@@ -280,11 +281,18 @@ begin
   CreateNDatasets;
 end;
 
-destructor TDBConnector.Destroy;
+Procedure TDBConnector.ClearDatasets;
+
 begin
-  if assigned(FUsedDatasets) then FUsedDatasets.Destroy;
   DropNDatasets;
   DropFieldDataset;
+end;
+
+destructor TDBConnector.Destroy;
+begin
+  if assigned(FUsedDatasets) then
+    FUsedDatasets.Destroy;
+  ClearDatasets;
   Inherited;
 end;