Jump to content

mvanrijnen

Members
  • Content Count

    150
  • Joined

  • Last visited

Community Reputation

33 Excellent

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. mvanrijnen

    Trim, SplitString

    declaration: type TStringArray = TArray<string>; TIntegerArray = TArray<integer>; TStringArrayHelper = record helper for TStringArray function ToIntArray() : TIntegerArray; end; TIntegerArrayHelper = record helper for TIntegerArray class function FromString(const AValue : string; const ASeparator : Char = ';') : TIntegerArray; end; implementation: { TStringArrayHelper } function TStringArrayHelper.ToIntArray: TIntegerArray; var idx : integer; begin SetLength(Result, Length(Self)); for idx := Low(Self) to High(Self) do Result[idx] := Self[idx].ToInteger; end; { TIntegerArrayHelper } class function TIntegerArrayHelper.FromString(const AValue: string; const ASeparator: Char): TIntegerArray; begin Result := AValue.Replace(' ', '', [rfReplaceAll]).Split([ASeparator], TStringSplitOptions.ExcludeEmpty).ToIntArray; end; usecase: procedure TForm1.Button4Click(Sender: TObject); const CNST_TEST_Value = '10 * 20 * 30'; var lValues : TIntegerArray; begin lvalues := TIntegerArray.FromString(CNST_TEST_Value, '*'); end; 🙂
  2. mvanrijnen

    Trim, SplitString

    var numbers : TArray<string>; begin numbers := '10 * 20 * 30'.Replace(' ', '', [rfReplaceAll]).Split(['*'], TStringSplitOptions.ExcludeEmpty]); Trim removes only the starting or ending whitespace.
  3. ah ok, totally missed on that 🙂 sorry for the confusion
  4. Yes i'm mistaking it with something else, there is (or was) such a thing in Delphi, Have to check some very old code if i can find it.
  5. So we need true constants for records 🙂 Always found it strange the variable constant construction in Delphi. Try to explain it to someone: * var x : integer; Variables: something from which the value can change throughout the execution of the application. * const x = 5; Constant: something from which the value can not change throughout the execution of the application. * const X : integer = 5; A constant from which the value can change throughout the execution of the application, so whats constant on this? If i want to explain this to my mother, she be asking if everything is alright with me 🙂 (and she uses an iphone, ipad and a notebook)
  6. I don't know directly from the others, but with Sempare you can make your own functions etc, very handy.
  7. Hey guys, i'm trying to implement something with attributes, which for the most works, but stumble on some problems with something. I have a setting class, which i use with class decoration, following works just fine: type TMyClass = class private fmyint : integer; public [Setting(666), SettingGroup('MySettingGroup1')] property MyInt : integer read FMyInt write FMyInt; end; So the property MyInt has a default value of 666, and through a SettingWorker class i can store and retrieve settings from json, ini's, database or whatever, that works just fine. (the SettingWorker class has methods like ApplyDefaults, LoadIni, SaveIni, etc etc) so now the challenge, i want to use this for some more complex properties (records like TPoint etc, this works: type TMyClass = class private fmyPoint : TPoint; public [Setting(), SettingGroup('MySettingGroup1')] property MyPoint : TPoint read FMyPoint write FMyPoint; end; so, i can store and retrieve the MyPoint value no problem, no i want to introduce the default value for this: This does not work: const CNST_MYPOINT : TPoint = (X: 35; Y: 55); type TMyClass = class private fmyPoint : TPoint; public [Setting(CNST_MYPOINT), SettingGroup('MySettingGroup1')] property MyPoint : TPoint read FMyPoint write FMyPoint; end; (i get: E2026 Constant expression expected) This also does not work: type TMyClass = class private fmyPoint : TPoint; public [Setting(TPoint = (X: 35; Y: 55)), SettingGroup('MySettingGroup1')] property MyPoint : TPoint read FMyPoint write FMyPoint; end; (i get: E2029 '(' expected but '=' found) Any thoughts, remark, ideas ?
  8. I use sempare, work great for me, the creator is also here on the forum i believe.
  9. Yes i know, it's what i had first, probably gonna mix them up. add the mutex way to the code. Needed the code i posted because i need to a way to get the handle of the already started instance.
  10. mvanrijnen

    Convert C# function to delphi

  11. mvanrijnen

    Convert C# function to delphi

    When i put the content (the given json in a file), and read it with ReadAllText, i get d6 ef 0e 0a f6 5e af fd 1c 87 4a b9 09 2a 0c 6b 2e cf df 08 6c 5a 79 a7 ad 3a bd 1b c2 73 c2 c9 SHA-256=1u8OCvZer/0ch0q5CSoMay7P3whsWnmnrTq9G8Jzwsk= i believe thats what lebeau also got (one of his results) quickie c# and the testfile attached also: using System; using System.Security.Cryptography; using System.Text; namespace DigestTEst2 { class Program { static void Main(string[] args) { string bytesRes = ""; string digestRes = ""; string inputtext2 = ""; static string ByteArrayToString(byte[] ba) { StringBuilder hex = new StringBuilder(ba.Length * 2); foreach (byte b in ba) hex.AppendFormat("{0:x2} ", b); return hex.ToString(); } static string GenerateDigest(string bodyText, out string bytetext) { var digest = ""; bytetext = ""; //var bodyText = "{ your JSON payload }"; using (var sha256hash = SHA256.Create()) { byte[] payloadBytes = sha256hash .ComputeHash(Encoding.UTF8.GetBytes(bodyText)); bytetext = ByteArrayToString(payloadBytes); digest = Convert.ToBase64String(payloadBytes); digest = "SHA-256=" + digest; } return digest; } inputtext2 = System.IO.File.ReadAllText(@"C:\Users\myname\Desktop\testfile.txt"); digestRes = GenerateDigest(inputtext2, out bytesRes); // Console.WriteLine(GenerateDigest(inputtext)); Console.WriteLine(bytesRes); Console.WriteLine(digestRes); } } } testfile.txt
  12. there is a strange comment post at your blog
  13. mvanrijnen

    Convert C# function to delphi

    strange i try tomorrow at work, with c#, see what comes out of that. maybe ts can get a dump of the sha256 digest as well. so we can figure out if it's the hash or the base64 function which differs
  14. mvanrijnen

    Convert C# function to delphi

    maybe an EOL too many/too short ? (at the end of the file)
  15. mvanrijnen

    Convert C# function to delphi

    -nevermind, reado ver the base64 thing-
×