Jump to content

david_navigator

Members
  • Content Count

    153
  • Joined

  • Last visited

Everything posted by david_navigator

  1. david_navigator

    Escaping UK pound sign in JSON

    Many thanks. Don't I feel stupid !! Now to do some experimenting to see if all the characters in the above routine get escaped correctly automatically .
  2. Me too and there's definitely a learning curve in working out what ChatGPT is good at and what it's not. Tonight I got it to do, like you, the boring part of writing some class code (I was going to say creating, but I think I'm creating, it's just writing), but I also asked it to write a simple function to remove tags from some HTML to just leave plain text. Even after 8 iterations the code wouldn't still wouldn't compile and even after I'd fixed those issues, the code didn't do what was requested. I'm guessing too many StackOverflow wrong answers have been analysed as code sampled !
  3. Something I found it really useful is explaining code that I don't understand. For example last week someone sent me a function in Python (a new language for me) which even with the comments I couldn't work out what it was doing. I asked ChatGPT to explain the code, and it did, in a way that then meant I could code something in delphi very quickly. For example, with your code.
  4. One of my customer's has started to get this error connecting my app to outlook.office365.com via IMAP. He's connecting to port 993 using Implicit TLS. He says that my app has been working for ages and has just started throwing this error, so I'm assuming that something has changed in the world of Microsoft - yet none of my other customers are reporting the error nor can I find anything online that suggest a change that Microsoft may have rolled out in the past week. I get the same error if I try on my PC with his Microsoft credential. I don't really understand what the error means though to then try and diagnose further what might be going on or settings he needs to look for in his account. Any help much appreciated. David
  5. david_navigator

    Converting Python code to Delphi

    I need to convert some python code to delphi, though my knowledge of python is somewhat thin. I've done most of what's needed but there's a part that I don't really understand. starting with _extract, it seems to call marsaglia_xorshift_128 but why does that have a while True & yield - is that so everything is treated as a persistent variable ? Does marsaglia_xorshift_128 effectively get called again for each byte in contents[12:16], from the deobfuscate_string so that w is the value from the "next" iteration ? How would I do something similar in delphi ? def marsaglia_xorshift_128(x = 123456789, y = 362436069, z = 521288629, w = 88675123): while True: t = (x ^ (x << 11)) & 0xffffffff x, y, z = y, z, w w = (w ^ (w >> 19) ^ (t ^ (t >> 8))) yield w # The lower 8-bits from the Xorshift PNR are subtracted from byte # values during extraction, and added to byte values on insertion. # When calling deobfuscate_string() the whole string is processed. def deobfuscate_string(pnr, obfuscated, operation=int.__sub__): return ''.join([chr((operation(ord(c), pnr.next())) & 0xff) for c in obfuscated]) def _extract(container_filename): ... ... ... contents = container.read(compressed_length) header_length, mangling_method, truncated_timestamp, original_length = struct.unpack('>HHLL', contents[:12]) assert header_length == 12 and mangling_method == 1 # The file contents are obfuscated with a Marsaglia xorshift PNR pnr = marsaglia_xorshift_128(x = truncated_timestamp, y = original_length) qcompress_prefix = deobfuscate_string(pnr, contents[12:16])
  6. david_navigator

    Converting Python code to Delphi

    why didn't I think of asking #AI ?? can you explain what this python code does ? def marsaglia_xorshift_128(x = 123456789, y = 362436069, z = 521288629, w = 88675123): while True: t = (x ^ (x << 11)) & 0xffffffff x, y, z = y, z, w w = (w ^ (w >> 19) ^ (t ^ (t >> 8))) yield w This is a Python function that implements the Marsaglia Xorshift 128 random number generator algorithm. The function takes four parameters x, y, z, and w which serve as the seed values for the generator. The function contains an infinite loop that generates random numbers using the Xorshift 128 algorithm. The loop uses bitwise operations to perform the necessary calculations to generate a new random number on each iteration. The t variable is calculated by performing a bitwise XOR operation on x shifted left by 11 bits and x, and then taking the result and performing a bitwise AND with the hexadecimal value 0xffffffff. The purpose of this calculation is to produce a new value for t that is used in the calculation of the next random number. Next, x, y, and z are updated by taking the previous values of y, z, and w. w is then calculated by performing a series of bitwise XOR and right-shift operations. The yield statement returns the new value of w on each iteration of the loop. This allows the function to be used as a generator that can be used to produce an infinite sequence of random numbers. Each time the function is called with the same seed values, it will produce the same sequence of random numbers. To get a different sequence, the seed values must be changed.
  7. Thought I'd just start a little discussion about using ChatAI for code samples as it's proved useful on a couple of occasions recently.
  8. david_navigator

    Does ChatAI make StackOverflow obsolete ?

    That's the experience I've had. Each sample of code has not compiled out of the box, but fixing it has given me an understanding of the code or pointed me in the direction of something I didn't know about.
  9. david_navigator

    Does ChatAI make StackOverflow obsolete ?

    Thanks. I did a search but nothing came up - maybe the search needs more AI 🙂
  10. david_navigator

    Does ChatAI make StackOverflow obsolete ?

    Interestingly none of the code samples it's given me so far have worked "out of the box" & many have contained deprecated or obsolete units. From what I can see, looking at the ExpertsExchange data it seems to have used, it weighs older information higher than recent information, which is of course not what's wanted with delphi.
  11. In my app, when I do anything that interacts with a specific control, the IDE grabs the focus and repeatedly displays KERNELBASE.RaiseException + 0x62 in the Local Variables Process selector. Not seen this before. Should I be concerned ? Doesn't seem to have any affect when running the exe outside of Delphi. This video demonstrates what I mean https://navigator.tinytake.com/msc/NzQ5MDQxM18yMDQxNTMxMQ
  12. david_navigator

    Should I be concerned about KERNELBASE.RaiseException + 0x62

    exactly the same, but without the exception name being displayed. i.e delphi still grabs the focus for a few seconds before returning it to my app.
  13. david_navigator

    Should I be concerned about KERNELBASE.RaiseException + 0x62

    No one any suggestions - delphi has become impossible to debug with this unit as every click in my app now is followed by 20 seconds of flashing debugger.
  14. david_navigator

    Enttec DMX USB Pro and Delphi

    you seem to be setting buf_size to 0. What happens if you use buf_size[0] := $FF; buf_size[1] := $FF; buf_size[2] := $FF; buf_size[3] := $FF;
  15. david_navigator

    TaskMessageDlg('.... behind form?

    I had a similar problem recently and it turned out to be due to a third party control on another form within my project. The 3rd party control did something in it's constructor that resulted in not only message dialogs opening behind, but popups, such as calendars doing similar - it of course didn't happen in normal use, but just when I happened to have two unrelated 3rd party controls in my app. (Thinfinity & TMS Planner)
  16. david_navigator

    Help debugging TNotificationCenter

    I am getting an Access Violation in the VCL TNotificationCenter, however how it occurs is strange and I can't seem to debug far enough in to the delphi source to work out why. I have a delphi form with an editbox. The edit box has an OnKeyDown event. Within that OnKeyDown event we call a routine to check if the key was VK_RETURN and if it was, we then process the content of the edit box (Method ProcessBarcodeScan) and in certain circumstances we create a Windows 10 (Toast) notification. (The notification makes no reference to the edit box or any of it's properties.) Now, the odd bit, if I type in to the edit box, then everything works as it should and there are no errors and the "toast" pops up. If I populate the Edit box via a SendMessage thus SendMessage(BarcodeEdit.Handle, WM_CHAR, lKeyCode, 0); and then call the ProcessBarcodeScan method via a PostMessage, thus PostMessage(handle, pm_ProcessBarcodeScan, WPARAM(lKeyCode), LPARAM(Ord(TRUE))) again all works correctly. However, if I populate the edit box via the SendMessage as above and then call ProcessBarcodeScan via a SendMessage thus SendMessage(handle, pm_ProcessBarcodeScan, WPARAM(lKeyCode), LPARAM(Ord(TRUE))); application.ProcessMessages; I get an Access violation, which stepping through the code gets me to class function TToastTemplateGenerator.GetXMLDoc(const ANotification: TNotification): Xml_Dom_IXmlDocument; ... ... Result := TToastNotificationManager.Statics.GetTemplateContent(LTemplateType); but the only place I can find GetTemplateContent is in Winapi.UI.Notifications class function TToastNotificationManager which won't accept a break point This is my Notification code procedure TDMNexusConnect.SendWin10Notification(aTitle, aAlertBody: string); var lNotification: TNotification; begin lNotification := NotificationCenter.CreateNotification; try lNotification.Name := format('Windows10Notification%d', [GetTickcount]); lNotification.Title := aTitle; lNotification.AlertBody := aAlertBody; NotificationCenter.PresentNotification(lNotification); finally lNotification.Free; end; end; and this is the Access Violation. exception class : EAccessViolation exception message : Access violation at address 03C4EBE9 in module 'HireTrackNX.exe'. Read of address 00000000. thread $2c24: 03c4ebe9 +015 HireTrackNX.exe System.Win.Notification TNotificationWinRT.Destroy 77e64ee1 +021 ntdll.dll KiUserExceptionDispatcher 00407984 +004 HireTrackNX.exe System 34 +0 @FreeMem 0040cc24 +01c HireTrackNX.exe System 34 +0 @UStrClr 03c4eaa6 +046 HireTrackNX.exe System.Win.Notification TNotificationWinRT.Create 03c4deb3 +02f HireTrackNX.exe System.Win.Notification TNotificationCenterWinRT.DoPresentNotification 03c59b40 +018 HireTrackNX.exe System.Notification TCustomNotificationCenter.DoPresentNotification 03c59c52 +002 HireTrackNX.exe System.Notification TCustomNotificationCenter.PresentNotification 03de9d23 +0a7 HireTrackNX.exe DMNexus 2440 +7 TDMNexusConnect.SendWin10Notification
  17. david_navigator

    Help debugging TNotificationCenter

    Problem solved. If the SendMessage originates from a different thread to that Presenting the Notification, then Windows raises the error "An outgoing call cannot be made since the application is dispatching an input synchronous call." As this is raised in the constructor of TNotificationWinRT, the destructor is called. The destructure doesn't check if FToast is assigned (which it's not 'cos the constructor fails) and thus raises an Access violation. I'll report this via QC. Meanwhile the fix to the original problem seems to be as simple as introducing a timer (which I'm guessing moves the processing to the main thread - is there a better way to do this ?). So the code becomes something like this (from my test app) procedure TForm62.comportclient1Receive(Sender: TObject; InQue: Integer); begin SendMessage(handle, pm_ProcessBarcodeScan, WPARAM(0), LPARAM(0)); application.processmessages; end; procedure TForm62.ProcessBarcodeScan(var Message: TMessage); begin inherited; SendWin10Notification('Hello World', 'Sent by Message'); end; procedure TForm62.SendWin10Notification(aTitle, aAlertBody: string); begin FNotification.Name := format('Windows10Notification%d', [GetTickcount]); FNotification.Title := aTitle; FNotification.AlertBody := aAlertBody; if not insendmessage then NotificationCenter1.PresentNotification(FNotification) else Timer1.enabled := true; end; procedure TForm62.Timer1Timer(Sender: TObject); begin if not insendmessage then begin NotificationCenter1.PresentNotification(FNotification); timer1.enabled := false; end; end;
  18. david_navigator

    Help debugging TNotificationCenter

    I think it must be something like that. Interestingly if I change the code so that rather than a local variable (which might go out of scope ?) the Notification is a class field, I get an additional error "An outgoing call cannot be made since the application is dispatching an input-synchronous call", then I get an AV !!
  19. david_navigator

    Help debugging TNotificationCenter

    Yes, Debug DCU's is checked. I can step through a lot of the source, until I get to Result := TToastNotificationManager.Statics.GetTemplateContent(LTemplateType); where the debugged just goes in to some interface assembler and no further. In this case, it's part of the design so that serial port data gets dealt with in the background whilst a dialog is visible if ScansDismissPromptsCheckbox.Checked then PostMessage(handle, pm_ProcessBarcodeScan, WPARAM(lKeyCode), LPARAM(Ord(TRUE))) // see bug tracker 3503 , need to be a PostMessage else begin SendMessage(handle, pm_ProcessBarcodeScan, WPARAM(lKeyCode), LPARAM(Ord(TRUE))); // see bug tracker 3009 , need to be a SendMessage application.ProcessMessages; end;
  20. I have a two sets of datetimes which I need to frequently check to see if the two lists are identical. There isn't the time to iterate through the lists whenever I need this info, so I'm thinking I need to store a value that represents the data. I think it's a hash, but this isn't something I've done before and everything I've attempted hasn't worked i.e I've changed some of the datetimes and ended up with the same result. If it's relevant there are usually about 60 in each set, but it could be between two and a thousand (always an even number) and each is only stored to the minute i.e seconds & mS are always zero. Can anyone point me in the correct direction please ? Many thanks David
  21. david_navigator

    Routine to check if set of dates match

    1. My UI, so I "know" when a user changes a date. 2. I need to know if any lists are the same as my list. 3. answered by 2 - I don't want to know anything if they're different. 4. No. Imagine each list represents a hotel room and each element of the list is the check in and check out time for each visitor over the next 6 months - I need to know if any two rooms have exactly the same booking schedules. The dates change frequently, the comparison gets run infrequently, but the compare has to be very fast and the date changes can be slow.
  22. david_navigator

    Routine to check if set of dates match

    The date lists are sorted. There can be N date lists, I need to know which date lists match the current one.
  23. david_navigator

    Routine to check if set of dates match

    Thanks, for the idea, though I don't it won't work in this particular case as there are actually many lists and I need to know if any list matches my "current" list.
×