Browse Source

* PChar -> PAnsiChar

Michaël Van Canneyt 2 years ago
parent
commit
391bec7249

+ 1 - 1
packages/fcl-report/demos/udapp.pp

@@ -463,7 +463,7 @@ begin
     begin
     J:=GetOptionValue('j','json');
     if J='' then
-      J:=ChangeFileExt(Paramstr(0),'.json');
+      J:=ChangeFileExt(Paramstr(0),rtlstring('.json'));
     end;
   F:=GetOptionValue('f','format');
   Fmt:=High(TRenderFormat);

+ 38 - 38
packages/fcl-report/src/fprepexprpars.pp

@@ -55,11 +55,11 @@ Type
     FSource : String;
     LSource,
     FPos : Integer;
-    FChar : PChar;
+    FChar : PAnsiChar;
     FToken : String;
     FTokenType : TTokenType;
   private
-    function GetCurrentChar: Char;
+    function GetCurrentChar: AnsiChar;
     procedure ScanError(Msg: String);
   protected
     procedure SetSource(const AValue: String); virtual;
@@ -67,12 +67,12 @@ Type
     function DoNumber(AKind: TNumberKind): TTokenType;
     function DoDelimiter: TTokenType;
     function DoString: TTokenType;
-    Function NextPos : Char; // inline;
+    Function NextPos : AnsiChar; // inline;
     procedure SkipWhiteSpace; // inline;
-    function IsWordDelim(C : Char) : Boolean; // inline;
-    function IsDelim(C : Char) : Boolean; // inline;
-    function IsDigit(C : Char; AKind: TNumberKind) : Boolean; // inline;
-    function IsAlpha(C : Char) : Boolean; // inline;
+    function IsWordDelim(C : AnsiChar) : Boolean; // inline;
+    function IsDelim(C : AnsiChar) : Boolean; // inline;
+    function IsDigit(C : AnsiChar; AKind: TNumberKind) : Boolean; // inline;
+    function IsAlpha(C : AnsiChar) : Boolean; // inline;
   public
     Constructor Create;
     Function GetToken : TTokenType;
@@ -80,7 +80,7 @@ Type
     Property TokenType : TTokenType Read FTokenType;
     Property Source : String Read FSource Write SetSource;
     Property Pos : Integer Read FPos;
-    Property CurrentChar : Char Read GetCurrentChar;
+    Property CurrentChar : AnsiChar Read GetCurrentChar;
   end;
 
   EExprScanner = Class(Exception);
@@ -584,9 +584,9 @@ Type
     Function AddCurrencyVariable(Const AName : ShortString; AValue : Currency) : TFPExprIdentifierDef;
     Function AddStringVariable(Const AName : ShortString; AValue : String) : TFPExprIdentifierDef;
     Function AddDateTimeVariable(Const AName : ShortString; AValue : TDateTime) : TFPExprIdentifierDef;
-    Function AddFunction(Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ACallBack : TFPExprFunctionCallBack) : TFPExprIdentifierDef;
-    Function AddFunction(Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ACallBack : TFPExprFunctionEvent) : TFPExprIdentifierDef;
-    Function AddFunction(Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ANodeClass : TFPExprFunctionClass) : TFPExprIdentifierDef;
+    Function AddFunction(Const AName : ShortString; Const AResultType : AnsiChar; Const AParamTypes : String; ACallBack : TFPExprFunctionCallBack) : TFPExprIdentifierDef;
+    Function AddFunction(Const AName : ShortString; Const AResultType : AnsiChar; Const AParamTypes : String; ACallBack : TFPExprFunctionEvent) : TFPExprIdentifierDef;
+    Function AddFunction(Const AName : ShortString; Const AResultType : AnsiChar; Const AParamTypes : String; ANodeClass : TFPExprFunctionClass) : TFPExprIdentifierDef;
     property Identifiers[AIndex : Integer] : TFPExprIdentifierDef Read GetI Write SetI; Default;
   end;
 
@@ -803,9 +803,9 @@ Type
     Function AddCurrencyVariable(Const ACategory : TBuiltInCategory; Const AName : ShortString; AValue : Currency) : TFPBuiltInExprIdentifierDef;
     Function AddStringVariable(Const ACategory : TBuiltInCategory; Const AName : ShortString; AValue : String) : TFPBuiltInExprIdentifierDef;
     Function AddDateTimeVariable(Const ACategory : TBuiltInCategory; Const AName : ShortString; AValue : TDateTime) : TFPBuiltInExprIdentifierDef;
-    Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ACallBack : TFPExprFunctionCallBack) : TFPBuiltInExprIdentifierDef;
-    Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ACallBack : TFPExprFunctionEvent) : TFPBuiltInExprIdentifierDef;
-    Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : Char; Const AParamTypes : String; ANodeClass : TFPExprFunctionClass) : TFPBuiltInExprIdentifierDef;
+    Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : AnsiChar; Const AParamTypes : String; ACallBack : TFPExprFunctionCallBack) : TFPBuiltInExprIdentifierDef;
+    Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : AnsiChar; Const AParamTypes : String; ACallBack : TFPExprFunctionEvent) : TFPBuiltInExprIdentifierDef;
+    Function AddFunction(Const ACategory : TBuiltInCategory; Const AName : ShortString; Const AResultType : AnsiChar; Const AParamTypes : String; ANodeClass : TFPExprFunctionClass) : TFPBuiltInExprIdentifierDef;
     Property IdentifierCount : Integer Read GetCount;
     Property Identifiers[AIndex : Integer] :TFPBuiltInExprIdentifierDef Read GetI;
   end;
@@ -817,7 +817,7 @@ Const
 
 Function TokenName (AToken : TTokenType) : String;
 Function ResultTypeName (AResult : TResultType) : String;
-Function CharToResultType(C : Char) : TResultType;
+Function CharToResultType(C : AnsiChar) : TResultType;
 Function BuiltinIdentifiers : TExprBuiltInManager;
 Procedure RegisterStdBuiltins(AManager : TExprBuiltInManager; Categories : TBuiltInCategories = AllBuiltIns);
 function ArgToFloat(Arg: TFPExpressionResult): TExprFloat;
@@ -918,7 +918,7 @@ begin
   Result:=GetEnumName(TypeInfo(TResultType),Ord(AResult));
 end;
 
-function CharToResultType(C: Char): TResultType;
+function CharToResultType(C: AnsiChar): TResultType;
 begin
   Case Upcase(C) of
     'S' : Result:=rtString;
@@ -1203,7 +1203,7 @@ end;
   TFPExpressionScanner
   ---------------------------------------------------------------------}
 
-function TFPExpressionScanner.IsAlpha(C: Char): Boolean;
+function TFPExpressionScanner.IsAlpha(C: AnsiChar): Boolean;
 begin
   Result := C in ['A'..'Z', 'a'..'z'];
 end;
@@ -1223,11 +1223,11 @@ begin
     FPos:=0
   else
     FPos:=1;
-  FChar:=Pchar(FSource);
+  FChar:=PAnsiChar(FSource);
   FToken:='';
 end;
 
-function TFPExpressionScanner.NextPos: Char;
+function TFPExpressionScanner.NextPos: AnsiChar;
 begin
   Inc(FPos);
   Inc(FChar);
@@ -1235,17 +1235,17 @@ begin
 end;
 
 
-function TFPExpressionScanner.IsWordDelim(C: Char): Boolean;
+function TFPExpressionScanner.IsWordDelim(C: AnsiChar): Boolean;
 begin
   Result:=C in WordDelimiters;
 end;
 
-function TFPExpressionScanner.IsDelim(C: Char): Boolean;
+function TFPExpressionScanner.IsDelim(C: AnsiChar): Boolean;
 begin
   Result:=C in Delimiters;
 end;
 
-function TFPExpressionScanner.IsDigit(C: Char; AKind: TNumberKind): Boolean;
+function TFPExpressionScanner.IsDigit(C: AnsiChar; AKind: TNumberKind): Boolean;
 begin
   case AKind of
     nkDecimal: Result := C in Digits;
@@ -1266,7 +1266,7 @@ Function TFPExpressionScanner.DoDelimiter : TTokenType;
 
 Var
   B : Boolean;
-  C,D : Char;
+  C,D : AnsiChar;
 
 begin
   C:=FChar^;
@@ -1313,7 +1313,7 @@ end;
 
 Function TFPExpressionScanner.DoString : TTokenType;
 
-  Function TerminatingChar(C : Char) : boolean;
+  Function TerminatingChar(C : AnsiChar) : boolean;
 
   begin
     Result:=(C=cNull) or
@@ -1323,7 +1323,7 @@ Function TFPExpressionScanner.DoString : TTokenType;
 
 
 Var
-  C : Char;
+  C : AnsiChar;
 
 begin
   FToken := '';
@@ -1342,7 +1342,7 @@ begin
   NextPos;
 end;
 
-function TFPExpressionScanner.GetCurrentChar: Char;
+function TFPExpressionScanner.GetCurrentChar: AnsiChar;
 begin
   If FChar<>Nil then
     Result:=FChar^
@@ -1367,12 +1367,12 @@ end;
 Function TFPExpressionScanner.DoNumber(AKind: TNumberKind) : TTokenType;
 
 Var
-  C : Char;
+  C : AnsiChar;
   X : TExprFloat;
   I : Integer;
-  prevC: Char;
+  prevC: AnsiChar;
 
-  function ValidDigit(C: Char; AKind: TNumberKind): Boolean;
+  function ValidDigit(C: AnsiChar; AKind: TNumberKind): Boolean;
   begin
     Result := IsDigit(C, AKind);
     if (not Result) then
@@ -1401,7 +1401,7 @@ begin
         nkHex, nkOctal:
           break;
         nkBinary:
-          if (prevC <> #0) then break;   // allow '%' as first char
+          if (prevC <> #0) then break;   // allow '%' as first AnsiChar
       end;
     if not ValidDigit(C, AKind) then
       ScanError(Format(SErrInvalidNumberChar,[C]));
@@ -1418,7 +1418,7 @@ end;
 Function TFPExpressionScanner.DoIdentifier : TTokenType;
 
 Var
-  C : Char;
+  C : AnsiChar;
   S : String;
 begin
   C:=CurrentChar;
@@ -1465,7 +1465,7 @@ end;
 Function TFPExpressionScanner.GetToken : TTokenType;
 
 Var
-  C : Char;
+  C : AnsiChar;
 
 begin
   FToken := '';
@@ -2263,7 +2263,7 @@ begin
 end;
 
 function TFPExprIdentifierDefs.AddFunction(const AName: ShortString;
-  const AResultType: Char; const AParamTypes: String;
+  const AResultType: AnsiChar; const AParamTypes: String;
   ACallBack: TFPExprFunctionCallBack): TFPExprIdentifierDef;
 begin
   Result:=Add as TFPExprIdentifierDef;
@@ -2275,7 +2275,7 @@ begin
 end;
 
 function TFPExprIdentifierDefs.AddFunction(const AName: ShortString;
-  const AResultType: Char; const AParamTypes: String;
+  const AResultType: AnsiChar; const AParamTypes: String;
   ACallBack: TFPExprFunctionEvent): TFPExprIdentifierDef;
 begin
   Result:=Add as TFPExprIdentifierDef;
@@ -2287,7 +2287,7 @@ begin
 end;
 
 function TFPExprIdentifierDefs.AddFunction(const AName: ShortString;
-  const AResultType: Char; const AParamTypes: String;
+  const AResultType: AnsiChar; const AParamTypes: String;
   ANodeClass: TFPExprFunctionClass): TFPExprIdentifierDef;
 begin
   Result:=Add as TFPExprIdentifierDef;
@@ -2643,7 +2643,7 @@ begin
 end;
 
 function TExprBuiltInManager.AddFunction(const ACategory: TBuiltInCategory;
-  const AName: ShortString; const AResultType: Char; const AParamTypes: String;
+  const AName: ShortString; const AResultType: AnsiChar; const AParamTypes: String;
   ACallBack: TFPExprFunctionCallBack): TFPBuiltInExprIdentifierDef;
 begin
   Result:=TFPBuiltInExprIdentifierDef(FDefs.AddFunction(AName,AResultType,AParamTypes,ACallBack));
@@ -2651,7 +2651,7 @@ begin
 end;
 
 function TExprBuiltInManager.AddFunction(const ACategory: TBuiltInCategory;
-  const AName: ShortString; const AResultType: Char; const AParamTypes: String;
+  const AName: ShortString; const AResultType: AnsiChar; const AParamTypes: String;
   ACallBack: TFPExprFunctionEvent): TFPBuiltInExprIdentifierDef;
 begin
   Result:=TFPBuiltInExprIdentifierDef(FDefs.AddFunction(AName,AResultType,AParamTypes,ACallBack));
@@ -2659,7 +2659,7 @@ begin
 end;
 
 function TExprBuiltInManager.AddFunction(const ACategory: TBuiltInCategory;
-  const AName: ShortString; const AResultType: Char; const AParamTypes: String;
+  const AName: ShortString; const AResultType: AnsiChar; const AParamTypes: String;
   ANodeClass: TFPExprFunctionClass): TFPBuiltInExprIdentifierDef;
 begin
   Result:=TFPBuiltInExprIdentifierDef(FDefs.AddFunction(AName,AResultType,AParamTypes,ANodeClass));

+ 1 - 1
packages/fcl-report/src/fpreport.pp

@@ -4038,7 +4038,7 @@ var
   maxw: single; // value in pixels
   n: integer;
   s: UTF8String;
-  c: char;
+  c: AnsiChar;
   lWidth: single;
 
   lDescenderHeight: single;

+ 9 - 8
packages/fcl-report/src/fpreportdom.pp

@@ -118,7 +118,8 @@ function TFPReportDOM.StreamToHex(S: TStream): String;
 
 Var
   T : TMemoryStream;
-  P,PD : PChar;
+  P : PByte;
+  PD : PCHar;
   I,L : Integer;
   h : String[2];
 
@@ -134,10 +135,10 @@ begin
     L:=T.Size;
     SetLength(Result,L*2);
     PD:=PChar(Result);
-    P:=PChar(T.Memory);
+    P:=PByte(T.Memory);
     For I:=1 to L do
       begin
-      H:=HexStr(Ord(P^),2);
+      H:=HexStr(P^,2);
       PD^:=H[1];
       Inc(PD);
       PD^:=H[2];
@@ -509,10 +510,10 @@ end;
 function TFPReportDOM.HexToStringStream(S : String) : TStringStream;
 
 Var
-  T : String;
+  T : RawByteString;
   I,J : Integer;
   B : Byte;
-  P : Pchar;
+  P : PByte;
   H : String[3];
 
 begin
@@ -522,7 +523,7 @@ begin
   if (S<>'') then
     begin
     SetLength(T,Length(S) div 2);
-    P:=PChar(T);
+    P:=PAnsiChar(T);
     I:=1;
     While I<Length(S) do
       begin
@@ -532,9 +533,9 @@ begin
       Inc(I);
       Val(H,B,J);
       If (J=0) then
-        P^:=Char(B)
+        P^:=B
       else
-        P^:=#0;
+        P^:=0;
       Inc(P);
       end;
     Result:=TStringStream.Create(T);

+ 9 - 8
packages/fcl-report/src/fpreportstreamer.pp

@@ -611,7 +611,8 @@ end;
 function TFPReportJSONStreamer.StreamToHex(S: TStream): String;
 var
   T: TMemoryStream;
-  P, PD: PChar;
+  P : PByte;
+  PD: PChar;
   I, L: integer;
   h: string[2];
 begin
@@ -626,10 +627,10 @@ begin
     L := T.Size;
     SetLength(Result, L * 2);
     PD := PChar(Result);
-    P := PChar(T.Memory);
+    P := PByte(T.Memory);
     for I := 1 to L do
     begin
-      H := HexStr(Ord(P^), 2);
+      H := HexStr(P^, 2);
       PD^ := H[1];
       Inc(PD);
       PD^ := H[2];
@@ -668,10 +669,10 @@ end;
 
 function TFPReportJSONStreamer.HexToStringStream(S: String): TStringStream;
 var
-  T: string;
+  T: Ansistring;
   I, J: integer;
   B: byte;
-  P: PChar;
+  P: PByte;
   H: string[3];
 begin
   Result := nil;
@@ -680,7 +681,7 @@ begin
   if (S <> '') then
   begin
     SetLength(T, Length(S) div 2);
-    P := PChar(T);
+    P := PByte(T);
     I := 1;
     while I < Length(S) do
     begin
@@ -690,9 +691,9 @@ begin
       Inc(I);
       Val(H, B, J);
       if (J = 0) then
-        P^ := char(B)
+        P^ := B
       else
-        P^ := #0;
+        P^ := 0;
       Inc(P);
     end;
     Result := TStringStream.Create(T);