Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FPC compatibility #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Quick.Files.pas
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ TDirItem = record
function FindDelimiter(const Delimiters, S: string; StartIdx: Integer = 1): Integer;
{$ENDIF}
function ConvertDateTimeToFileTime(const DateTime: TDateTime; const UseLocalTimeZone: Boolean): TFileTime;
{$ifdef mswindows}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to {IF DEFINED(DELPHIXE_UP) OR (DEFINED(FPC) AND DEFINED(MSWINDOWS))} because it's delphi crossplatform compatible

function ConvertFileTimeToDateTime(const FileTime : TFileTime; const UseLocalTimeZone : Boolean) : TDateTime;
{$endif mswindows}
procedure SetDateTimeInfo(const Path: string; const CreationTime, LastAccessTime, LastWriteTime: PDateTime; const UseLocalTimeZone: Boolean);
function GetFiles(const Path : string; Recursive : Boolean) : TArray<TDirItem>; overload;
procedure GetFiles(const Path : string; aAddToList : TDirItemAddProc; Recursive : Boolean); overload;
Expand Down Expand Up @@ -1309,8 +1311,10 @@ function GetFiles(const Path : string; Recursive : Boolean) : TArray<TDirItem>;
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

Result := Result + [diritem];
end
else
Expand All @@ -1336,8 +1340,10 @@ procedure GetFiles(const Path : string; aAddToList : TDirItemAddProc; Recursive
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

aAddToList(diritem);
end
else
Expand All @@ -1363,8 +1369,10 @@ function GetDirectories(const Path : string; Recursive : Boolean) : TArray<TDirI
diritem.Name := rec.Name;
diritem.IsDirectory := True;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

Result := Result + [diritem];
if Recursive then Result := Result + GetFiles(IncludeTrailingPathDelimiter(Path) + diritem.Name,Recursive);
end;
Expand Down Expand Up @@ -1402,17 +1410,23 @@ function GetFilesAndDirectories(const Path : string; Recursive : Boolean) : TArr
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}

Result := Result + [diritem];
end
else if (rec.Name <> '.') and (rec.Name <> '..') then
begin
diritem.Name := rec.Name;
diritem.IsDirectory := True;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}

Result := Result + [diritem];
if Recursive then Result := Result + GetFilesAndDirectories(dirpath + diritem.Name,Recursive);
end;
Expand Down Expand Up @@ -1452,17 +1466,23 @@ procedure GetFilesAndDirectories(const Path : string; aAddToList : TDirItemAddPr
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}

aAddToList(diritem);
end
else if (rec.Name <> '.') and (rec.Name <> '..') then
begin
diritem.Name := rec.Name;
diritem.IsDirectory := True;
diritem.Size := rec.Size;
{$ifdef SEARCHREC_USEFINDDATA}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FPC to conditional because this is a FPC only conditional

diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$endif SEARCHREC_USEFINDDATA}

aAddToList(diritem);
if Recursive then GetFilesAndDirectories(dirpath + diritem.Name,aAddToList,Recursive);
end;
Expand Down
10 changes: 6 additions & 4 deletions Quick.Json.Serializer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ TRTTIJson = class
//serialize methods
function SerializeValue(const aValue : TValue) : TJSONValue;
function SerializeObject(aObject : TObject) : TJSONObject; overload;
function SerializeStream(aObject : TObject) : TJSONValue;
{$IFNDEF FPC}
function SerializeStream(aObject : TObject) : TJSONValue;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've moved outside conditional because is fpc compatible

function SerializeDynArray(const aValue: TValue; aMaxElements : Integer = -1) : TJsonArray;
function SerializeRecord(const aValue : TValue) : TJSONValue;
{$ELSE}
Expand Down Expand Up @@ -213,7 +213,9 @@ TJsonSerializer = class(TInterfacedObject,IJsonSerializer)
property UseNullStringsAsEmpty : Boolean read fUseNullStringsAsEmpty write fUseNullStringsAsEmpty;
function JsonToObject(aType : TClass; const aJson: string) : TObject; overload;
function JsonToObject(aObject : TObject; const aJson: string) : TObject; overload;
{$IFNDEF FPC}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've moved outside conditional because is fpc compatible

function JsonStreamToObject(aObject : TObject; aJsonStream : TStream) : TObject;
{$ENDIF}
function ObjectToJson(aObject : TObject; aIndent : Boolean = False): string;
function ObjectToJsonString(aObject : TObject; aIndent : Boolean = False): string;
procedure ObjectToJsonStream(aObject : TObject; aStream : TStream);
Expand Down Expand Up @@ -450,21 +452,21 @@ function TRTTIJson.DeserializeRecord(const aRecord : TValue; aObject : TObject;
end;
Result := aRecord;
end;
{$ENDIF}

function TRTTIJson.DeserializeStream(aObject: TObject; const aJson: TJSONValue): TObject;
var
stream : TStringStream;
begin
if fUseBase64Stream then stream := TStringStream.Create(Base64Decode(aJson.Value),TEncoding.Ansi)
else stream := TStringStream.Create(aJson.Value,TEncoding.Ansi);
else stream := TStringStream.Create(String(aJson.Value),TEncoding.Ansi);
try
TStream(aObject).CopyFrom(stream,stream.Size);
finally
stream.Free;
end;
end;

{$ENDIF}

constructor TRTTIJson.Create(aSerializeLevel : TSerializeLevel; aUseEnumNames : Boolean = True);
begin
fSerializeLevel := aSerializeLevel;
Expand Down