forked from exilon/QuickLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
6,329 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
program ArrayHelpers; | ||
|
||
{$APPTYPE CONSOLE} | ||
|
||
{$R *.res} | ||
|
||
uses | ||
System.SysUtils, | ||
Quick.Commons, | ||
Quick.Console, | ||
Quick.Arrays.Helper; | ||
|
||
var | ||
|
||
myarray : TArray<string>; | ||
|
||
begin | ||
try | ||
ReportMemoryLeaksOnShutdown := True; | ||
|
||
myarray.Add('one'); | ||
myarray.Add('two'); | ||
myarray.Add('three'); | ||
coutFmt('count: %d',[myarray.Count],etInfo); | ||
if myarray.Contains('two') then cout('found "two" in array',etInfo) | ||
else cout('not found',etInfo); | ||
|
||
coutFmt('"three" in position %d',[myarray.IndexOf('three')],etInfo); | ||
|
||
TArrayHelper<string>.Add(myarray,'Four'); | ||
|
||
cout('Press <Enter> to Exit',ccYellow); | ||
ConsoleWaitForEnterKey; | ||
except | ||
on E: Exception do | ||
Writeln(E.ClassName, ': ', E.Message); | ||
end; | ||
end. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
program ManageFlexArray; | ||
|
||
{$APPTYPE CONSOLE} | ||
|
||
{$R *.res} | ||
|
||
uses | ||
System.SysUtils, | ||
Quick.Commons, | ||
Quick.Console, | ||
Quick.Arrays; | ||
|
||
type | ||
TUser = class | ||
private | ||
fName : string; | ||
public | ||
property Name : string read fName write fName; | ||
end; | ||
|
||
var | ||
xarThings : TFlexArray; | ||
user : TUser; | ||
|
||
begin | ||
try | ||
xarThings.Add(10); | ||
xarThings.Add('Hello'); | ||
user := TUser.Create; | ||
try | ||
user.Name := 'Joe'; | ||
xarThings.Add(user); | ||
|
||
cout('Integer Item = %d',[xarThings[0].AsInteger],etInfo); | ||
cout('String Item = %s',[xarThings[1].AsString],etInfo); | ||
cout('Record Item = %s',[TUser(xarThings[2]).Name],etInfo); | ||
finally | ||
user.Free; | ||
end; | ||
cout('Press <Enter> to Exit',ccYellow); | ||
ConsoleWaitForEnterKey; | ||
except | ||
on E: Exception do | ||
Writeln(E.ClassName, ': ', E.Message); | ||
end; | ||
end. |
678 changes: 678 additions & 0 deletions
678
samples/delphi/QuickArrays/FlexArrays/ManageFlexArray.dproj
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
samples/delphi/QuickArrays/FlexPairArrays/ManageFlexPairArray.dpr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
program ManageFlexPairArray; | ||
|
||
{$APPTYPE CONSOLE} | ||
|
||
{$R *.res} | ||
|
||
uses | ||
System.SysUtils, | ||
Quick.Commons, | ||
Quick.Console, | ||
Quick.Arrays; | ||
|
||
type | ||
TUser = class | ||
private | ||
fName : string; | ||
public | ||
property Name : string read fName write fName; | ||
end; | ||
|
||
var | ||
flexarray : TFlexPairArray; | ||
user : TUser; | ||
|
||
begin | ||
try | ||
flexarray.Add('onenumber',10); | ||
flexarray.Add('other','Hello boy!'); | ||
user := TUser.Create; | ||
try | ||
user.Name := 'Joe'; | ||
flexarray.Add('myuser',user); | ||
|
||
cout('Integer Item = %d',[flexarray.GetValue('onenumber').AsInteger],etInfo); | ||
cout('String Item = %s',[flexarray.GetValue('other').AsString],etInfo); | ||
cout('Record Item = %s',[TUser(flexarray.GetValue('myuser')).Name],etInfo); | ||
finally | ||
user.Free; | ||
end; | ||
|
||
cout('Press <Enter> to Exit',ccYellow); | ||
ConsoleWaitForEnterKey; | ||
except | ||
on E: Exception do | ||
Writeln(E.ClassName, ': ', E.Message); | ||
end; | ||
end. |
680 changes: 680 additions & 0 deletions
680
samples/delphi/QuickArrays/FlexPairArrays/ManageFlexPairArray.dproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
program ManageArrays; | ||
|
||
{$APPTYPE CONSOLE} | ||
|
||
{$R *.res} | ||
|
||
uses | ||
System.SysUtils, | ||
Quick.Commons, | ||
Quick.Console, | ||
Quick.Arrays; | ||
|
||
type | ||
|
||
TUser = record | ||
Name : string; | ||
Age : Integer; | ||
end; | ||
|
||
var | ||
userarray : TXArray<TUser>; | ||
user : TUser; | ||
normalarray : TArray<TUser>; | ||
|
||
begin | ||
try | ||
ReportMemoryLeaksOnShutdown := True; | ||
|
||
user.Name := 'Joe'; | ||
user.Age := 30; | ||
userarray.Add(user); | ||
user.Name := 'Peter'; | ||
user.Age := 32; | ||
userarray.Add(user); | ||
user.Name := 'James'; | ||
user.Age := 40; | ||
userarray.Add(user); | ||
|
||
if userarray.Contains(user) then cout('found user in array',etInfo); | ||
|
||
for user in userarray do | ||
begin | ||
coutFmt('User: %s',[user.Name],etInfo); | ||
end; | ||
|
||
normalarray := userarray; | ||
|
||
coutFmt('Copied array value 1: %s',[normalarray[1].Name],etInfo); | ||
|
||
cout('Press <Enter> to Exit',ccYellow); | ||
ConsoleWaitForEnterKey; | ||
except | ||
on E: Exception do | ||
Writeln(E.ClassName, ': ', E.Message); | ||
end; | ||
end. |
678 changes: 678 additions & 0 deletions
678
samples/delphi/QuickArrays/ManageArrays/ManageArrays.dproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
samples/delphi/QuickJsonSerializer/JsonSerializerTest/JsonSerializerTest.dpr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
program JsonSerializerTest; | ||
|
||
{$APPTYPE CONSOLE} | ||
|
||
{$R *.res} | ||
|
||
uses | ||
System.SysUtils, | ||
System.Generics.Collections, | ||
Quick.Commons, | ||
Quick.Console, | ||
Quick.Json.Serializer; | ||
|
||
type | ||
THost = class | ||
private | ||
fName : string; | ||
fIP : string; | ||
fPort : Integer; | ||
published | ||
property Name : string read fName write fName; | ||
property IP : string read fIP write fIP; | ||
property Port : Integer read fPort write fPort; | ||
end; | ||
|
||
THostList = TObjectList<THost>; | ||
|
||
TConfig = class | ||
private | ||
fHosts : THostList; | ||
fDebugMode : Boolean; | ||
fLevel : Integer; | ||
published | ||
constructor Create; | ||
destructor Destroy; override; | ||
property Hosts : THostList read fHosts write fHosts; | ||
property DebugMode : Boolean read fDebugMode write fDebugMode; | ||
property Level : Integer read fLevel write fLevel; | ||
end; | ||
|
||
const | ||
jsonstring = '{"Hosts":[{"Name":"Host 1 año perfeción","IP":"127.0.0.1","Port":80},{"Name":"Host 2","IP":"192.168.1.1","Port":443}],"DebugMode":true,"Level":1}'; | ||
jsonstring2 = '{"Hosts":{"List":[{"Name":"Host 1","IP":"127.0.0.2","Port":80},{"Name":"Host 2","IP":"192.168.1.2","Port":443}]},"DebugMode":true,"Level":2}'; | ||
|
||
var | ||
config : TConfig; | ||
host : THost; | ||
serializer : TJsonSerializer; | ||
json : string; | ||
|
||
{ TConfig } | ||
|
||
constructor TConfig.Create; | ||
begin | ||
fHosts := THostList.Create(True); | ||
end; | ||
|
||
destructor TConfig.Destroy; | ||
begin | ||
fHosts.Free; | ||
inherited; | ||
end; | ||
|
||
begin | ||
try | ||
serializer := TJsonSerializer.Create(slPublishedProperty); | ||
try | ||
|
||
//created from object | ||
cout('Create from object',ccYellow); | ||
config := TConfig.Create; | ||
try | ||
host := THost.Create; | ||
host.Name := 'Host 1'; | ||
host.IP := '127.0.0.1'; | ||
host.Port := 80; | ||
config.DebugMode := True; | ||
config.Level := 1; | ||
config.Hosts.Add(host); | ||
|
||
host := THost.Create; | ||
host.Name := 'Host 2'; | ||
host.IP := '192.168.1.1'; | ||
host.Port := 443; | ||
config.Hosts.Add(host); | ||
|
||
json := serializer.ObjectToJson(config,True); | ||
cout(json,ccWhite); | ||
coutFmt('Capacity: %d / Count: %d',[config.Hosts.Capacity,config.Hosts.Count],etInfo); | ||
finally | ||
config.Free; | ||
end; | ||
|
||
//from json string without list property | ||
cout('Create from jsonstring without "List" property',ccYellow); | ||
config := TConfig.Create; | ||
try | ||
serializer.JsonToObject(config,jsonstring); | ||
json := serializer.ObjectToJson(config,True); | ||
cout(json,ccWhite); | ||
coutFmt('Capacity: %d / Count: %d',[config.Hosts.Capacity,config.Hosts.Count],etInfo); | ||
finally | ||
config.Free; | ||
end; | ||
|
||
//from json string with list property | ||
cout('Create from jsonstring with "List" property',ccYellow); | ||
config := TConfig.Create; | ||
try | ||
serializer.JsonToObject(config,jsonstring2); | ||
json := serializer.ObjectToJson(config,True); | ||
cout(json,ccWhite); | ||
coutFmt('Capacity: %d / Count: %d',[config.Hosts.Capacity,config.Hosts.Count],etInfo); | ||
finally | ||
config.Free; | ||
end; | ||
finally | ||
serializer.Free; | ||
end; | ||
ConsoleWaitForEnterKey; | ||
except | ||
on E: Exception do | ||
Writeln(E.ClassName, ': ', E.Message); | ||
end; | ||
end. |
Oops, something went wrong.