From 2065b2bd28cd01c182a984ea9cdf06426ebd73b0 Mon Sep 17 00:00:00 2001 From: Execute Date: Thu, 13 Sep 2018 09:02:09 +0200 Subject: [PATCH] Tuple moved to DelphiTips --- README.md | 4 +- Tuple/Execute.Tuple.pas | 160 ---------------------------------------- Tuple/readme.md | 4 - 3 files changed, 2 insertions(+), 166 deletions(-) delete mode 100644 Tuple/Execute.Tuple.pas delete mode 100644 Tuple/readme.md diff --git a/README.md b/README.md index 55d3904..01696e9 100644 --- a/README.md +++ b/README.md @@ -41,5 +41,5 @@ http://www.execute.fr - TinyPNG > a tiny Unit to load PNG files -- Tuple -> use Tuples under Delphi :) +- Tuple [moved](https://github.com/tothpaul/DelphiTips/tree/master/Tuple) +> ~~use Tuples under Delphi :)~~ diff --git a/Tuple/Execute.Tuple.pas b/Tuple/Execute.Tuple.pas deleted file mode 100644 index 4cda36e..0000000 --- a/Tuple/Execute.Tuple.pas +++ /dev/null @@ -1,160 +0,0 @@ -unit Execute.Tuple; - -{ Variant Tuple for Delphi Tokyo (c)2018 Execute SARL } - -{ -procedure AfficheMonTuple(const ATuple: Variant); -begin - ShowMessage(string(ATuple.Prenom) + ' ' + string(ATuple.Nom) + ' ' + string(ATuple.Age) + ' ' + string(ATuple.Taille)); -end; - -var - v: Variant; -begin - TTuple.Init(v); - v.Nom := 'Durand'; - v.Prenom := 'Pierre'; - v.Age := 45; - v.Taille := 1.80; - AfficheMonTuple(v); -end; - -} - -interface - -uses - System.SysUtils, - System.Variants; - -type - TTuple = class(TInvokeableVariantType) - private const - VTYPE = $0112; - public - // basic functions - procedure Clear(var V: TVarData); override; - procedure Copy(var Dest: TVarData; const Source: TVarData; - const Indirect: Boolean); override; - // properties - function SetProperty(const V: TVarData; const Name: string; - const Value: TVarData): Boolean; override; - function GetProperty(var Dest: TVarData; const V: TVarData; - const Name: string): Boolean; override; - // initialization - class procedure Init(var V: Variant); - end; - -implementation - -var - Instance: TTuple; - -type - TProperty = record - Name : string; - Value: Variant; - end; - TProperties = TArray; - -function GetPropIndex(var Props: TProperties; const Name: string): Integer; -begin - Result := Length(Props) - 1; - while Result >= 0 do - begin - if Props[Result].Name = Name then - Exit; - Dec(Result); - end; -end; - -procedure SetTupleProperty(var Props: TProperties; const Name: string; const Value: TVarData); -var - Index: Integer; -begin - Index := GetPropIndex(Props, Name); - if Index < 0 then - begin - Index := Length(Props); - SetLength(Props, Index + 1); - Props[Index].Name := Name; - end; - Props[Index].Value := Variant(Value); -end; - -function GetTupleProperty(var Props: TProperties; const Name: string; var Dest: TVarData): Boolean; -var - Index: Integer; -begin - Index := GetPropIndex(Props, Name); - if Index < 0 then - Result := False - else begin - Result := True; - Variant(Dest) := Props[Index].Value; - end; -end; - -class procedure TTuple.Init(var V: Variant); -begin - if Instance = nil then - Instance := TTuple.Create(VTYPE); - VarClear(V); - TVarData(V).VType := VTYPE; -end; - -procedure TTuple.Clear(var V: TVarData); -begin - if V.VType = VType then - TProperties(V.VPointer) := nil; -end; - -procedure TTuple.Copy(var Dest: TVarData; const Source: TVarData; - const Indirect: Boolean); -begin - init(Variant(Dest)); - if Source.VType = VTYPE then - begin - if Source.VPointer <> nil then - begin - if Indirect then - begin - Dest.VPointer := Source.VPointer; - end else begin - TProperties(Dest.VPointer) := System.Copy(TProperties(Source.VPointer)); - end; - end; - end; -end; - -function TTuple.SetProperty(const V: TVarData; const Name: string; - const Value: TVarData): Boolean; -var - P: PPointer; -begin - if V.VType = VTYPE then - begin - P := @V.VPointer; - SetTupleProperty(TProperties(P^), Name, Value); - Result := True; - end else begin - Result := False; - end; -end; - -function TTuple.GetProperty(var Dest: TVarData; const V: TVarData; - const Name: string): Boolean; -var - P: PPointer; -begin - if V.VType = VTYPE then - begin - P := @V.VPointer; - Result := GetTupleProperty(TProperties(P^), Name, Dest) - end else begin - Result := False; - end; -end; - - -end. diff --git a/Tuple/readme.md b/Tuple/readme.md deleted file mode 100644 index 56aa284..0000000 --- a/Tuple/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -Quick unit to use Tuple under Delphi Tokyo - -based on an article by Vicente Romero Zaldivar -https://community.embarcadero.com/article/technical-articles/162-programming/6064-programming-in-delphi-7-in-a-script-like-way \ No newline at end of file