Jump to content

mvanrijnen

Members
  • Content Count

    455
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by mvanrijnen

  1. mvanrijnen

    Logging from RAD Server

    Somehow inserting code goes wrong sometime, my text of my post disappeared. You just need the EMS.ResourceAPI in your uses and then you can use the TEMSEndPointEnvironment.Instance.LogMessage('your log text'); In debugmode (running your RADServer package from the IDE), the logging goes into the radserver console window, where the radserver itself also logs. We are not in production yet, so i do not know at the moment where the logging goes in a production environment 🙂 I use this in a logging framework, which also can log to file, database etc etc. Did not see the TEMSLoggingService before, have to inspect that, maybe it's the better way to work. [edit, added first code for the emsloggingservice) so, first tryout for the loggingservice: unit .......; interface uses ..... EMS.Services; type THSLoggerRADServerDebugTargetQueue = class(THSLoggerBaseTargetQueue) private femslogsvc : IEMSLoggingService; protected function HandleTargetItem(const AItem: THSLLoggerItem): Boolean; override; public procedure DoBeforeStart; override; procedure DoAfterStop; override; {TODO -oOwner -cGeneral : CheckCanStart wordt helemaal niet aangeroepen ???? } procedure CheckCanStart(var ACanStart: Boolean; var AMessage: string); override; end; implementation uses ....., EMS.ResourceAPI; { THSLoggerRADServerDebugTargetQueue } procedure THSLoggerRADServerDebugTargetQueue.CheckCanStart(var ACanStart: Boolean; var AMessage: string); begin inherited; ACanStart := True; end; procedure THSLoggerRADServerDebugTargetQueue.DoAfterStop; begin femslogsvc := nil; inherited; end; procedure THSLoggerRADServerDebugTargetQueue.DoBeforeStart; begin femslogsvc := nil; inherited; if TEMSServices.TryGetService<IEMSLoggingService>(femslogsvc) then begin if not femslogsvc.LoggingEnabled then begin femslogsvc := nil; end; end; end; function THSLoggerRADServerDebugTargetQueue.HandleTargetItem(const AItem: THSLLoggerItem): Boolean; var obj : TJSONObject; begin inherited; Result := False; try if Assigned(femslogsvc) then begin obj := TJSONObject.Create(); obj.AddPair('user', AItem.UserName); obj.AddPair('computer', AItem.ComputerName); obj.AddPair('datetime', DateToISO8601(AItem.DateTime)); obj.AddPair('message', AItem.LogMessage); obj.AddPair('position', AItem.Position); femslogsvc.Log(AItem.LogType.AsString, obj); end; Result := True; except on e: exception do begin // DebugLog('xx', 'xxxx'); end; end; end; end.
  2. mvanrijnen

    Logging from RAD Server

    unit MyUnit; interface {$IFDEF RADSERVER_PACKAGE} uses ..... EMS.ResourceAPI; type THSLoggerRADServerDebugTargetQueue = class(THSLoggerBaseTargetQueue) protected function HandleTargetItem(const AItem: THSLLoggerItem): Boolean; override; public end; {$ENDIF} implementation {$IFDEF RADSERVER_PACKAGE} { THSLoggerRADServerDebugTargetQueue } function THSLoggerRADServerDebugTargetQueue.HandleTargetItem(const AItem: THSLLoggerItem): Boolean; var line: string; begin inherited; ..... TEMSEndpointEnvironment.Instance.LogMessage(line); .... end; {$ENDIF} end.
  3. mvanrijnen

    Prevent OnClick to be handled twice

    If you want to prevent doubleclicking by users who still don't know the difference between single and double click (yes, they are still around, we have some overhere 🙂 ), we use a simple trick. (Yelling to the users don't work 🙂 ) You set a timer on enabled in the onclick, something like (at start of program you set the interval to like 250 orso,). not a beauty, but it works here. (not exact code we use, but similar just out of the head): const CNST_PREVEN_DOUBLECLICK_INTERVAL_MSECS = 250; procedure TForm1.Button1Click(Sender : TObject); begin if not Button1Timer.Enabled then begin Button1Timer.Interval := CNST_PREVEN_DOUBLECLICK_INTERVAL_MSECS; Button1Timer.Enabled := True; DoButton1Code(); end; end; procedure TForm1.Button1TimerTimer(Sender : TObject); begin Botton1Timer.Enabled := False; end; [/code] maybe just use a "global" var, to remember lasttime clicked, and compare msecs to that could also be possible.
  4. mvanrijnen

    TPopupMenu with group headers

    Isn't that why we have submenus ? (although they are an extra click away).
  5. mvanrijnen

    upcoming language enhancements?

    The classic code is unusable in big projects with many lines of sourcecode, and causes the IDE completely unusable. We have to choose between to bad options. Third option is disable all function in the IDE. Thats not why we pay a lot of money each year. Big problem is they bring updates which do not fix the bugs they say they do. So apparently they have to little people working on the product, or just shit on their customers.
  6. mvanrijnen

    upcoming language enhancements?

    Only the updates did not fix the problems they supposed to do. LSP/Codecompletion malfunctioning. If i look the the bugs which are still open and/or being reported it does not sound like a reasonable finished product. Like delivering a car from which the weels unexpected fall of. If you'r lucky you don't have a problem, i you'r unlucky you end the day after a few hours withouth wheels. Refactoring which stops working, suddenly freezes of the IDE, suddenly exiting of the IDE, making a mess of project files etc etc. Inserting events wrong in the sourcecoude (doubleclicking an event in the property inspector), i can go on and on. Very slow "getit" a failed ripoff from the packagemanagement from other IDE's, not working GetIt sometimes.
  7. Leaving Delphi 7, and keep hoping on a reasonable release of D10 was the biggest mistake for most Delphi programmers i think. 🙂
  8. mvanrijnen

    upcoming language enhancements?

    I think all communication budget from EMB is spend by the marketeers who are putting out the worthless blogs. @Marco Cantu We did not get an invite for the Beta, nice window to subscribe by the way, 3 days???, called , we would get an invite a week ago, still no email from EMB. I really don't think they are gonna make it for long with this kind of attitude towards their customers. Why not publish some details about the coming Delphi 11 ? When we get a decent version of 10.4 ?
  9. mvanrijnen

    Parsing Text search expression

    Would be nice to have a common parser what you posted in your startpost, something with a base class which does the basic parsing of the query, and which can be extended in execution functionality .
  10. 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.
  11. 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 🙂
  12. 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 ?
  13. 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; 🙂
  14. 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.
  15. ah ok, totally missed on that 🙂 sorry for the confusion
  16. 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.
  17. 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)
  18. I don't know directly from the others, but with Sempare you can make your own functions etc, very handy.
  19. I use sempare, work great for me, the creator is also here on the forum i believe.
  20. 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;
  21. 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.
  22. 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
  23. there is a strange comment post at your blog
  24. 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
×