

david_navigator
Members-
Content Count
153 -
Joined
-
Last visited
Everything posted by david_navigator
-
Detect stack full for recursive routine
david_navigator replied to david_navigator's topic in RTL and Delphi Object Pascal
Thanks. This is the first time it's fallen over in 20 years so not too concerned. I just wondered if there was a call like "is there enough stack space left for me to call this routine again" kind of thing. -
Error - 12030 The connection with the server was terminated abnormally
david_navigator posted a topic in Network, Cloud and Web
Using Delphi to upload or download from a cloud S3 server, my customers are getting this intermittent error. exception class : ENetHTTPClientException exception message : Error sending data: (12030) The connection with the server was terminated abnormally. thread $2f68: 01d4096a +126 HireTrackNX.exe System.Net.HttpClient.Win TWinHTTPClient.HandleExecuteError 01d40c76 +2d2 HireTrackNX.exe System.Net.HttpClient.Win TWinHTTPClient.DoExecuteRequest 01d4bda2 +1ea HireTrackNX.exe System.Net.HttpClient THTTPClient.ExecuteHTTPInternal 01d4c080 +008 HireTrackNX.exe System.Net.HttpClient THTTPClient.ExecuteHTTP 01d4b0f2 +0ee HireTrackNX.exe System.Net.HttpClient THTTPClient.Execute 01d4bb05 +04d HireTrackNX.exe System.Net.HttpClient THTTPClient.DoExecute 01d4fe18 +050 HireTrackNX.exe System.Net.HttpClient THTTPClient.Put 022b7f32 +03a HireTrackNX.exe Data.Cloud.CloudAPI TCloudHTTP.Put 022b77e7 +077 HireTrackNX.exe Data.Cloud.CloudAPI TCloudService.IssuePutRequest Google seems to suggest it could be a Winsock timeout or a TLS mismatch between the target machine and console machine., but I have no understanding of what that actually means in practical terms - it certainly doesn't seem to be related to the size of the file being transferred. Would that be something as simple as a network connection issue between the client & server ? The server's hosting company tell me there's no issue at their end and the user is connecting to the client over RDP, so there can't be an internet issue at their end either. I'm really looking for any ideas or suggestions on how to either deal with the error better from a user's POV or how to diagnose what the actual cause is and address that. Usually if the user retries the upload or download process a couple of times, it does eventually work. Many thanks David -
Escaping UK pound sign in JSON
david_navigator posted a topic in Algorithms, Data Structures and Class Design
I have some code that I inherited from someone else which is used to convert a dataset to JSON. Mostly it works OK, but rather than a £ being converted to \u00A3 it gets converted to \\u00A3 i.e the slash gets escaped again. So from "Additional Fuel Used 170 Litres @ £2.00 per Litre" rather than "Additional Fuel Used 170 Litres @ \u00A32.00 per Litre" I get "Additional Fuel Used 170 Litres @ \\u00A32.00 per Litre" I've found very similar code in StackOverflow, but that has the same issue. This is the SO code as it's potentially easier to read. Can anyone point out where I/they are going wrong please ? As far as I can tell the EscapeValue code is correctly converting the £ to \u00A3, but then the TJSONPair.create seems to be then re-escaping the one '\' in to '\\' unit Unit71; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, dbxjson, json; type TForm71 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type TSvJsonString = class(TJSONString) private function EscapeValue(const AValue: string): string; public constructor Create(const AValue: string); overload; end; var Form71: TForm71; implementation {$R *.dfm} constructor TSvJsonString.Create(const AValue: string); begin inherited Create(EscapeValue(AValue)); end; function TSvJsonString.EscapeValue(const AValue: string): string; procedure AddChars(const AChars: string; var Dest: string; var AIndex: Integer); inline; begin System.Insert(AChars, Dest, AIndex); System.Delete(Dest, AIndex + 2, 1); Inc(AIndex, 2); end; procedure AddUnicodeChars(const AChars: string; var Dest: string; var AIndex: Integer); inline; begin System.Insert(AChars, Dest, AIndex); System.Delete(Dest, AIndex + 6, 1); Inc(AIndex, 6); end; var i, ix: Integer; AChar: Char; begin Result := AValue; ix := 1; for i := 1 to System.Length(AValue) do begin AChar := AValue[i]; case AChar of '/', '\', '"': begin System.Insert('\', Result, ix); Inc(ix, 2); end; #8: //backspace \b begin AddChars('\b', Result, ix); end; #9: begin AddChars('\t', Result, ix); end; #10: begin AddChars('\n', Result, ix); end; #12: begin AddChars('\f', Result, ix); end; #13: begin AddChars('\r', Result, ix); end; #0 .. #7, #11, #14 .. #31: begin AddUnicodeChars('\u' + IntToHex(Word(AChar), 4), Result, ix); end else begin if Word(AChar) > 127 then begin AddUnicodeChars('\u' + IntToHex(Word(AChar), 4), Result, ix); end else begin Inc(ix); end; end; end; end; end; procedure TForm71.Button1Click(Sender: TObject); var LText, LEscapedText: string; LJsonString: TSvJsonString; LJsonPair: TJsonPair; LJsonObject: TJsonObject; begin LText := 'The price is £20.00'; LJsonString := TSvJsonString.Create(LText); LJsonPair := TJsonPair.Create('MyString', LJsonString); LJsonObject := TJsonObject.Create(LJsonPair); try LEscapedText := LJsonObject.ToString; showmessage(LEscapedText); LEscapedText := LJsonObject.ToJSON; showmessage(LEscapedText); finally LJsonObject.Free; end; end; end. -
Escaping UK pound sign in JSON
david_navigator replied to david_navigator's topic in Algorithms, Data Structures and Class Design
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 . -
New blog post: Leveraging ChatGPT to generate a Delphi class along with CRUD code from a table schema
david_navigator replied to Darian Miller's topic in Tips / Blogs / Tutorials / Videos
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 ! -
New blog post: Leveraging ChatGPT to generate a Delphi class along with CRUD code from a table schema
david_navigator replied to Darian Miller's topic in Tips / Blogs / Tutorials / Videos
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. -
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])
-
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.
-
Does ChatAI make StackOverflow obsolete ?
david_navigator posted a topic in Tips / Blogs / Tutorials / Videos
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. -
Does ChatAI make StackOverflow obsolete ?
david_navigator replied to david_navigator's topic in Tips / Blogs / Tutorials / Videos
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. -
Does ChatAI make StackOverflow obsolete ?
david_navigator replied to david_navigator's topic in Tips / Blogs / Tutorials / Videos
Thanks. I did a search but nothing came up - maybe the search needs more AI 🙂 -
Does ChatAI make StackOverflow obsolete ?
david_navigator replied to david_navigator's topic in Tips / Blogs / Tutorials / Videos
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. -
Does ChatAI make StackOverflow obsolete ?
david_navigator replied to david_navigator's topic in Tips / Blogs / Tutorials / Videos
-
Should I be concerned about KERNELBASE.RaiseException + 0x62
david_navigator posted a topic in General Help
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 -
Should I be concerned about KERNELBASE.RaiseException + 0x62
david_navigator replied to david_navigator's topic in General Help
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. -
Should I be concerned about KERNELBASE.RaiseException + 0x62
david_navigator replied to david_navigator's topic in General Help
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. -
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;
-
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)
-
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;
-
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 !!
-
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;
-
Routine to check if set of dates match
david_navigator posted a topic in Algorithms, Data Structures and Class Design
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 -
Routine to check if set of dates match
david_navigator replied to david_navigator's topic in Algorithms, Data Structures and Class Design
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. -
Routine to check if set of dates match
david_navigator replied to david_navigator's topic in Algorithms, Data Structures and Class Design
The date lists are sorted. There can be N date lists, I need to know which date lists match the current one. -
Routine to check if set of dates match
david_navigator replied to david_navigator's topic in Algorithms, Data Structures and Class Design
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.