Jump to content

david_navigator

Members
  • Content Count

    151
  • Joined

  • Last visited

Posts posted by david_navigator


  1. 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.
    
    
    
    

     

    • Like 1

  2. 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])

     


  3. 2 hours ago, Stano said:

    I know/I read of two cases where programmers used it. AI reduced their time to create the right code from a week to a day. No, they didn't get the right result. But AI led them to it.

    He who knows what he wants and what he is doing will help himself.

    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.

    • Like 1

  4. 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


  5. 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)


  6. 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;

     

     

     


  7. Quote

    Check TNotificationWinRT.Create.

    I assume your lNotification is freed before it used here.

    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 !!


  8. 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.

     

    Quote

    Anyway, the use of Application.ProcessMessages looks like a code flaw and is the wrong approach in most cases.

         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;

     


  9. 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

     

    Quote

     

    Quote

     


  10. 50 minutes ago, bobD said:

    four questions:

    1. Where do the datetimes come from and how/when do they change? For example, if you're comparing file datetimes, then maintaining a status when the data changes might be better than checking when you need to know. They might change a lot less often than you check for a difference.

    2. What is it you really need to know: whether any particular pair is different? or whether any difference exists anywhere in the list?

    3. Is that always simply a 'difference exists' boolean? Or would knowing [greater than | equal to | less than] also needed?

    4. Is there a guarantee that for every element[x] in list one, the same element exists at position[x] in list two? How is that guarantee enforced or checked?

     

    All of these affect your potential solution options. For the first example, if the list changes much less often than the need to check, then you might create a tracking object with two boolean values: FUpdated and FDifferent. Set FUpdated to true when any list element changes. When checking, if FUpdated is false, then simply return the FDifferent boolean, or if true recheck the list, store and return the comparison operation result, and reset FUpdated to false. This can save you thousands of list comparisons if the lists are much less volatile than the need to know whether they're the same. Answers to the other questions could modify the structure of this tracking object.

    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.


  11. 38 minutes ago, joaodanet2018 said:

    I think that using the follow, will be more flexible;

    -- aux: array, dictionary, list, record, class, etc...

    <dateOne, dateTwo, boolean> = 25/02/2022, 24/02/2022, false  == a "class" can allow more controll about setters and getters.

    if dont need the date-values, then, store one "a boolean"

    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.


  12. 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


  13. 23 minutes ago, KenR said:

    I don't think you'll find anything better than the DevEx one but you will have to buy all of their VCL components,

    Luckily I already have the DexEx & TMS controls mentioned in this thread and I have the budget for others if something suitable raised its head 🙂


  14. 2 hours ago, Bill Meyer said:

    Since I do not know the answer myself, does Excel support the attached object? Or is that simply something you need in your UI?

    If the latter, then you may find looking at TMS FlexCel useful. It is a very capable Excel interface I have used for several years. I think you will find you need a hybrid solution to meet your requirements.

    Just my UI. The customer currently uses Google sheets as the UI and then copies data in to various other apps etc. They're after a similar UI, but with everything else automated. I've looked at various UI ideas and I too have come to the conclusion that for this particular task the excel feel is the best for the job. The solution doesn't need to be able to export in to excel or google sheets format and must be completely self contained i.e not just an automation of excel or sheets.


  15. 3 minutes ago, ConstantGardener said:

    ...the TAdvStringGrid from TMS should do the trick.

    I did look at it, but it seemed very basic in comparison to the devEx one. Does it have in built support for all the usual excel functions such as inserting/deleting cells/rows/columns and all the other cells moving appropriately ? 


  16. Hi

    Has anyone come across a grid/spreadsheet component that will allow the developer to "attach" an Object to a cell (or even something as mundane as a tag), but has all the inbuilt functionality of basic excel such as inserting/deleting cells/rows/columns and allowing a range of cells to be selected and cut/copy and pasted elsewhere, grouping rows and allowing them to be expanded/collaspsed etc ?

    The Devex Spreadsheet does everything except for allowing any data to be attached to a cell 😞

×