2022-02-14 22:57:27 +02:00
|
|
|
unit uCEFArgCopy;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2022-02-19 19:56:41 +02:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
2022-02-14 22:57:27 +02:00
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2022-03-26 21:05:29 +02:00
|
|
|
System.Classes, System.SysUtils, System.AnsiStrings;
|
2022-02-14 22:57:27 +02:00
|
|
|
{$ELSE}
|
|
|
|
Classes, SysUtils;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
type
|
|
|
|
TCEFArgCopy = class
|
|
|
|
protected
|
|
|
|
FArgCCopy : longint;
|
2022-03-26 21:05:29 +02:00
|
|
|
FArgVCopy : PPAnsiChar;
|
2022-02-14 22:57:27 +02:00
|
|
|
|
|
|
|
procedure InitializeFields;
|
|
|
|
procedure DestroyFields;
|
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
2022-03-26 21:05:29 +02:00
|
|
|
procedure CopyFromArgs(aArgc : longint; aArgv : PPAnsiChar);
|
2022-02-14 22:57:27 +02:00
|
|
|
|
2022-03-26 21:05:29 +02:00
|
|
|
property argc : longint read FArgCCopy;
|
|
|
|
property argv : PPAnsiChar read FArgVCopy;
|
2022-02-14 22:57:27 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$POINTERMATH ON}
|
|
|
|
|
|
|
|
constructor TCEFArgCopy.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
InitializeFields;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TCEFArgCopy.Destroy;
|
|
|
|
begin
|
|
|
|
DestroyFields;
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFArgCopy.InitializeFields;
|
|
|
|
begin
|
|
|
|
FArgCCopy := 0;
|
|
|
|
FArgVCopy := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFArgCopy.DestroyFields;
|
|
|
|
var
|
|
|
|
i : integer;
|
|
|
|
begin
|
|
|
|
if (FArgVCopy <> nil) then
|
|
|
|
begin
|
|
|
|
i := pred(FArgCCopy);
|
|
|
|
|
|
|
|
while (i >= 0) do
|
|
|
|
begin
|
|
|
|
if (FArgVCopy[i] <> nil) then
|
2022-04-26 12:14:05 +02:00
|
|
|
{$IFDEF DELPHI18_UP}System.AnsiStrings.{$ENDIF}StrDispose(FArgVCopy[i]);
|
2022-02-14 22:57:27 +02:00
|
|
|
|
|
|
|
dec(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
FreeMem(FArgVCopy);
|
|
|
|
end;
|
|
|
|
|
|
|
|
InitializeFields;
|
|
|
|
end;
|
|
|
|
|
2022-03-26 21:05:29 +02:00
|
|
|
procedure TCEFArgCopy.CopyFromArgs(aArgc : longint; aArgv : PPAnsiChar);
|
2022-02-14 22:57:27 +02:00
|
|
|
var
|
|
|
|
i : integer;
|
|
|
|
begin
|
|
|
|
DestroyFields;
|
|
|
|
|
|
|
|
if (aArgc > 0) and (aArgv <> nil) then
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
FArgCCopy := aArgc;
|
|
|
|
|
|
|
|
GetMem(FArgVCopy, (FArgCCopy + 1) * SizeOf(Pointer));
|
|
|
|
|
|
|
|
while (i < aArgc) do
|
|
|
|
begin
|
2022-03-26 21:05:29 +02:00
|
|
|
{$IFDEF FPC}
|
2022-04-26 12:14:05 +02:00
|
|
|
FArgVCopy[i] := StrAlloc(length(aArgv[i]) + 1);
|
|
|
|
StrCopy(FArgVCopy[i], aArgv[i]);
|
2022-03-26 21:05:29 +02:00
|
|
|
{$ELSE}
|
2022-04-26 12:14:05 +02:00
|
|
|
{$IFDEF DELPHI18_UP}
|
|
|
|
FArgVCopy[i] := System.AnsiStrings.AnsiStrAlloc(length(aArgv[i]) + 1);
|
|
|
|
System.AnsiStrings.StrCopy(FArgVCopy[i], aArgv[i]);
|
|
|
|
{$ELSE}
|
2022-07-19 22:37:46 +02:00
|
|
|
FArgVCopy[i] := {$IFDEF DELPHI16_UP}System.{$ENDIF}SysUtils.AnsiStrAlloc(length(aArgv[i]) + 1);
|
|
|
|
{$IFDEF DELPHI16_UP}System.{$ENDIF}SysUtils.StrCopy(FArgVCopy[i], aArgv[i]);
|
2022-04-26 12:14:05 +02:00
|
|
|
{$ENDIF}
|
2022-03-26 21:05:29 +02:00
|
|
|
{$ENDIF}
|
2022-02-14 22:57:27 +02:00
|
|
|
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
FArgVCopy[i] := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|