mvanrijnen
Members-
Content Count
471 -
Joined
-
Last visited
-
Days Won
1
Everything posted by mvanrijnen
-
Parsing Text search expression
mvanrijnen replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
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. -
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 🙂
-
Const Records and Class/Property Attributes (decoration)
mvanrijnen posted a topic in Algorithms, Data Structures and Class Design
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 ? -
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; 🙂
-
var numbers : TArray<string>; begin numbers := '10 * 20 * 30'.Replace(' ', '', [rfReplaceAll]).Split(['*'], TStringSplitOptions.ExcludeEmpty]); Trim removes only the starting or ending whitespace.
-
Const Records and Class/Property Attributes (decoration)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
ah ok, totally missed on that 🙂 sorry for the confusion -
Const Records and Class/Property Attributes (decoration)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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. -
Const Records and Class/Property Attributes (decoration)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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) -
The BEST template engine for generating webpages on the server side?
mvanrijnen replied to Edwin Yip's topic in Tips / Blogs / Tutorials / Videos
I don't know directly from the others, but with Sempare you can make your own functions etc, very handy. -
The BEST template engine for generating webpages on the server side?
mvanrijnen replied to Edwin Yip's topic in Tips / Blogs / Tutorials / Videos
I use sempare, work great for me, the creator is also here on the forum i believe. -
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;
-
Code causes Bitdefender Advanced Threat Control see the app as malicious (SingleInstanceAppl)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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. -
- 15 replies
-
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
- 15 replies
-
Spring4D 2.0 sneak peek - the evolution of performance
mvanrijnen replied to Stefan Glienke's topic in Tips / Blogs / Tutorials / Videos
there is a strange comment post at your blog -
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
- 15 replies
-
maybe an EOL too many/too short ? (at the end of the file)
- 15 replies
-
-nevermind, reado ver the base64 thing-
- 15 replies
-
base64 encode/decode  TStringDynArray
mvanrijnen replied to borni69's topic in Network, Cloud and Web
Don't know your "memcache" class, but why not use a simple dictionairy ? -
[RadServer] User can not logon to multiple sessions simultaneously?
mvanrijnen posted a topic in Network, Cloud and Web
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? -
[RadServer] User can not logon to multiple sessions simultaneously?
mvanrijnen replied to mvanrijnen's topic in Network, Cloud and Web
Okay, we have two enterprise subscription, that would be good for 6 issues then? -
Code causes Bitdefender Advanced Threat Control see the app as malicious (SingleInstanceAppl)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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 -
Code causes Bitdefender Advanced Threat Control see the app as malicious (SingleInstanceAppl)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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. -
Code causes Bitdefender Advanced Threat Control see the app as malicious (SingleInstanceAppl)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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 -
Code causes Bitdefender Advanced Threat Control see the app as malicious (SingleInstanceAppl)
mvanrijnen replied to mvanrijnen's topic in Algorithms, Data Structures and Class Design
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)