Jump to content

mvanrijnen

Members
  • Content Count

    471
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by mvanrijnen

  1. mvanrijnen

    Parsing Text search expression

    Maybe create a wrapper around: Welcome to the Lucene.NET website! | Apache Lucene.NET 4.8.0 ? Will be a lot of work i think.
  2. mvanrijnen

    memory usage of TJPGImage

    The TJPGImage has a TBitmap in it which will take the memory i think. This is a simple calculation, width,height,bits/pixel or am i mistaken? mistaken 🙂
  3. 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 ?
  4. 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; 🙂
  5. 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.
  6. ah ok, totally missed on that 🙂 sorry for the confusion
  7. 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.
  8. 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)
  9. I don't know directly from the others, but with Sempare you can make your own functions etc, very handy.
  10. I use sempare, work great for me, the creator is also here on the forum i believe.
  11. Hey, following code causes AV (Bitdefender Advanced Threat Control ) to see software as malicious, somebody here who known what part could cause this? The code is meant to prevent multiple instances of an application, found the original on the internet and adapted it to our needs) (first is the main unit, at the end the adapations tto the prject &mainform) unit MyCompany.SingleAppInstance; { origineel: https://delphidabbler.com/articles/article-13 } { Hoe te gebruiken: ProjectFile: use MyCompany.SingleAppInstance SingleAppInstance.InstanceMainWindowClassName := 'SingleInstTest'; <-- Random class name unique over projects SingleAppInstance.InstanceWaterMark := $8cae8bdc; <-- random dword unique over projects if SingleAppInstance.CanStartApp then begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); Application.Run; end; MainForm: use MyCompany.SingleAppInstance TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private protected procedure WndProc(var Msg : TMessage); override; procedure CreateParams(var Params : TCreateParams); override; procedure HandleParameters(const Param : string); public end; procedure TForm1.CreateParams(var Params: TCreateParams); begin inherited; SingleAppInstance.CreateParams(Params); end; procedure TForm1.FormCreate(Sender: TObject); begin SingleAppInstance.OnProcessParam := HandleParameters; SingleAppInstance.HandleFirstCallParameters; end; procedure TForm1.HandleParameters(const Param: string); begin Memo1.Lines.Add(Param); end; procedure TForm1.WndProc(var Msg: TMessage); begin if not SingleAppInstance.HandleMessages(Self.Handle, Msg) then inherited; end; } interface uses Windows, Controls, Messages, Classes; const CNST_COMPANYPREFIX = 'MyCompany'; CNST_MAXWINCLASSNAME_LENGTH = 255; CNST_WINDOWSMESSAGE = CNST_COMPANYPREFIX+'SINGLEINSTANCE_ENSURERESTORE'; CNST_DEFAULT_MAINWINDOWCLASSNAME = CNST_COMPANYPREFIX+'SINGLEINSTANCE.MainWindow'; CNST_DEFAULT_WATERMARK = 0; type THSSingleAppInstanceParameterEvent = procedure(const AParameters : string) of object; THSSingleAppInstance = class(TObject) private FOnProcessParam: THSSingleAppInstanceParameterEvent; FApplicationInstanceRestoreMsg : UINT; FOnBeforeApplicationRestore: TNotifyEvent; class var FInstanceMainWindowClassName: string; class var FInstanceWaterMark: DWORD; class procedure SetInstanceMainWindowClassName(const Value: string); static; procedure DoBeforeApplicationRestore; procedure HandleFirstCallParameters; protected function FindDuplicateMainWindowHandle : HWND; virtual; function SendParamsToPrevInst(const AWindowHandle : HWND) : Boolean; virtual; function SwitchToPrevInst(const AWindowHandle : HWND) : Boolean; procedure DoApplicationInstanceRestore(const AWindowHandle : HWND; var AMessage : TMessage); dynamic; procedure WMCopyData(var AMessage : TMessage); dynamic; public class constructor Create; constructor Create; procedure CreateParams(var AParameters : TCreateParams); function HandleMessages(const AWindowHandle : HWND; var AMessage : TMessage) : Boolean; function CanStartApp : Boolean; property OnProcessParam : THSSingleAppInstanceParameterEvent read FOnProcessParam write FOnProcessParam; property OnBeforeRestore : TNotifyEvent read FOnBeforeApplicationRestore write FOnBeforeApplicationRestore; class property InstanceWaterMark : DWORD read FInstanceWaterMark write FInstanceWaterMark; class property InstanceMainWindowClassName : string read FInstanceMainWindowClassName write SetInstanceMainWindowClassName; end; function SingleAppInstance : THSSingleAppInstance; implementation uses SysUtils, Forms; var _singleinst : THSSingleAppInstance = nil; function SingleAppInstance : THSSingleAppInstance; begin if not Assigned(_singleinst) then _singleinst := THSSingleAppInstance.Create; Result := _singleinst; end; { THSSingleAppInstance } function THSSingleAppInstance.CanStartApp: Boolean; var wdwd : HWND; begin wdwd := FindDuplicateMainWindowHandle; if wdwd=0 then Result := True else Result := not SwitchToPrevInst(wdwd); end; constructor THSSingleAppInstance.Create; begin inherited; FApplicationInstanceRestoreMsg := RegisterWindowMessage(CNST_WINDOWSMESSAGE) end; class constructor THSSingleAppInstance.Create; begin InstanceWaterMark := CNST_DEFAULT_WATERMARK; InstanceMainWindowClassName := CNST_DEFAULT_MAINWINDOWCLASSNAME end; procedure THSSingleAppInstance.CreateParams(var AParameters: TCreateParams); begin inherited; Fillchar(AParameters.WinClassName, CNST_MAXWINCLASSNAME_LENGTH, #0); Move(InstanceMainWindowClassName[1], AParameters.WinClassName[0], InstanceMainWindowClassName.Length*sizeof(char)); end; procedure THSSingleAppInstance.DoBeforeApplicationRestore; begin if assigned(OnBeforeRestore) then OnBeforeRestore(Self); end; procedure THSSingleAppInstance.DoApplicationInstanceRestore(const AWindowHandle: HWND; var AMessage: TMessage); begin if Assigned(Application.MainForm) and ((IsIconic(Application.MainForm.Handle)) or (Application.MainForm.WindowState = TWindowState.wsMinimized)) then begin DoBeforeApplicationRestore; Application.Restore; end; if Assigned(Application.MainForm) and not Application.MainForm.Visible then Application.MainForm.Visible := True; Application.BringToFront; SetForegroundWindow(AWindowHandle); end; function THSSingleAppInstance.FindDuplicateMainWindowHandle: HWND; begin Result := FindWindow(PWideChar(InstanceMainWindowClassName), nil); end; procedure THSSingleAppInstance.HandleFirstCallParameters; var params : string; i : integer; begin params := string.Empty; for i := 1 to ParamCount do params := params + ParamStr(i) + ' '; params.Trim; if assigned(FOnProcessParam) then FOnProcessParam(params); end; function THSSingleAppInstance.HandleMessages(const AWindowHandle: HWND; var AMessage: TMessage): Boolean; begin if AMessage.Msg=WM_COPYDATA then begin WMCopyData(AMessage); Result := True; end else if AMessage.Msg=FApplicationInstanceRestoreMsg then begin DoApplicationInstanceRestore(AWindowHandle, AMessage); Result := True; end else Result := False; end; function THSSingleAppInstance.SendParamsToPrevInst(const AWindowHandle: HWND): Boolean; var copydata : TCopyDataStruct; params : string; i : integer; begin params := string.Empty; for i := 1 to ParamCount do params := params + ParamStr(i) + ' '; params.Trim; copydata.lpData := PChar(params); copydata.cbData := params.Length*sizeof(char); copydata.dwData := InstanceWaterMark; Result := SendMessage(AWindowHandle, WM_COPYDATA, 0, lparam(@copydata))=1; end; class procedure THSSingleAppInstance.SetInstanceMainWindowClassName(const Value: string); begin FInstanceMainWindowClassName := Value.Substring(0, CNST_MAXWINCLASSNAME_LENGTH); end; function THSSingleAppInstance.SwitchToPrevInst(const AWindowHandle: HWND): Boolean; begin Assert(AWindowHandle<>0); if ParamCount>0 then Result := SendParamsToPrevInst(AWindowHandle) else Result := True; if Result then SendMessage(AWindowHandle, FApplicationInstanceRestoreMsg, 0, 0); end; procedure THSSingleAppInstance.WMCopyData(var AMessage: TMessage); var copydata : TCopyDataStruct; pdata : PChar; params, param : string; charsize : integer; begin charsize := SizeOf(char); copydata := TWMCopyData(AMessage).CopyDataStruct^; if copydata.dwData=InstanceWaterMark then begin params := PChar(copydata.lpData); if assigned(FOnProcessParam) then FOnProcessParam(params); AMessage.Result := 1; end else AMessage.Result := 0; end; end. project file: begin SingleAppInstance.InstanceMainWindowClassName := 'FolderSearch.VCLClient'; SingleAppInstance.InstanceWaterMark := $72f508c5; if SingleAppInstance.CanStartApp then begin Application.Initialize; Application.MainFormOnTaskbar := False; GlobalLogger(); if not TMyCompanySelfUpdater.ExecuteEx('FolderSearch') then begin Application.CreateForm(TfrmMain, frmFolderSearch); Application.Run; end; end; end. type TfrmMain = class(TForm) private procedure DoSingleInstanceRestore(Sender : TObject); protected procedure WMEndSession(var Msg: TWMEndSession); message WM_ENDSESSION; procedure WndProc(var Msg : TMessage); override; procedure CreateParams(var Params : TCreateParams); override; public { Public declarations } end; procedure TfrmMain.CreateParams(var Params: TCreateParams); begin inherited; SingleAppInstance.CreateParams(Params); end; procedure TfrmMain.FormCreate(Sender: TObject); begin SingleAppInstance.OnBeforeRestore := DoSingleInstanceRestore; end; procedure TfrmMain.WndProc(var Msg: TMessage); begin if not SingleAppInstance.HandleMessages(Self.Handle, Msg) then inherited; end;
  12. 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.
  13. 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
  14. there is a strange comment post at your blog
  15. 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
  16. mvanrijnen

    Convert C# function to delphi

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

    Convert C# function to delphi

    -nevermind, reado ver the base64 thing-
  18. Don't know your "memcache" class, but why not use a simple dictionairy ?
  19. When i logon from a second instance of a client, on the radserver the previous session of that user becomes invalid. We do the logon with a username/password, and then use the token (session authorization). Somebody, who als ran into this problem ? Also posted here, but slow reactions from EMB: https://quality.embarcadero.com/browse/RSP-34146?
  20. Okay, we have two enterprise subscription, that would be good for 6 issues then?
  21. Yes, i think it's the combination of code for the "SingleInstanceApp" and the code we use for the selfupdating capability of that application, that includes a createprocess after updating the executable. This also explains why a test application with only the SingleInstanceApp keeps working and is ok for the AV. gonna creeate a testapp with both the SingeInstanceApp and the selfupdating code. (it;s just 2 units with a few calls to them). thnx for the info on the codesigning thing
  22. It's really weird. The stripped down example file, which only contains the SingeInstanceUnit, a form with a memo, is not pointed out as malicious. The original program, is not withouth the SingleInstanceUnitCode, but is with, but only after a specific use. (for so as as i can see now). I can start the program and use it, when the SingInstance behaviour is executed a few times, then after a certain amount of time, is is pointed as malicious, the process is killed and the .exe is removed. (it's Bitdefender advanced thread control). already uploaded samples to them, waiting for the response. Then code signing we will do, gonna propose it to the boss. it's not expensive so thats no problem.
  23. yes, i'll change that 🙂 So you suggest, to make a small exe with only this code, and send it to them? Submitted example to: https://www.bitdefender.com/submit
  24. Yes its for applicaton we use internally only. On filescan there all undetected (virustotal), so it seems the behaviour is the cause. (we have bitdefender endpoint security tools since a few weeks now)
×