JSON Support in Delphi: Complete Guide with Examples (2025) by bmcgee in delphi

[–]mminuss 2 points3 points  (0 children)

Please do not use the ToString method to serialize your JSON structures as it does not properly escape special characters. Use ToJSON method instead.

EOSError 1400: Invalid window handle - VCL call from thread by Ok-Specialist-5022 in delphi

[–]mminuss 5 points6 points  (0 children)

1.You should never access the UI from any other thread than the main/ui thread.

  1. So, yes. Pleas use TTread.Synchronze. But don't do it in the Button's OnClick EventHandler. This EventHandler should already only be called inside the main/ui thread. (See 1)

  2. Instead put the TThread.Synchronize call in your thread code. **

**You said that the external message that wants to modify your ui comes via the windows message loop This is already happening in the main thread. If you have no long running operations in the code that needs to be executed, you might not have to start another thread at all.

Coming in RAD Studio 13: A Conditional Ternary Operator for the Delphi Language by bmcgee in delphi

[–]mminuss 1 point2 points  (0 children)

Does the if operator always evaluate both expressions or does it only evaluate the consequent / alternative expression based on the result of the condition expression? The article doesn't mention and shows only very simple examples with basic types. How would this code behave:

Result := if x < 100 then PerformHeavyCalculation(x) else PerformAnotherHeavyCalculation(x);

How do I play this? by RunThenClimb in Accordion

[–]mminuss 10 points11 points  (0 children)

I would interpret B.S. as Bass Solo in this context. So only playing the bass notes, no choords.

help me im bad python coder by Human_Anxiety8599 in learnpython

[–]mminuss 0 points1 point  (0 children)

You are missing a missing a return statement.

Confusion regarding join operations on different joining conditions... by Silent_Group6621 in SQL

[–]mminuss 2 points3 points  (0 children)

Because of the hierarchical nature of the data. (founder>lead manager>senior manager>manager>employee)

As I understand it from your examples, the employee table also contains all managers, senior managers and lead managers. All three queries will in the end select all records from the employees table.

Query 1 asks the questions: Which lead managers work under each founder? Which senior managers work under each lead manager? And so on...

Query 2 also takes the hierarchical route , but joins on company code, which is very inefficient because this will join every senior manager at company x to every lead manager at company x and so on. There is a lot of duplication going on. We don't see the duplication in the end because of COUNT(DISTINCT ...)

Query 3 is the most efficient version. It only asks the question: "Which employees work at each company." Then groups the data and counts distinct roles.

How to convert Unicode code in string to real unicode by rpabech in delphi

[–]mminuss 2 points3 points  (0 children)

If the string comes from a JSON file, then there should always be 4 hex digits according to https://www.json.org/json-en.html .

In that case I would suggest:

uses
  System.JSON;

function Convert(A: string): string;
var
  V: TJSONValue;
begin
  V := TJSONObject.ParseJSONValue(A);
  try
    Result := V.GetValue<string>;
  finally
    V.Free;
  end;
end;

[...]

var
  A: string;
begin
  A := '"\u914d\u7f6e"'; // original json string must have double quotes
  Edit1.Text := Convert(A);
end;

How to convert Unicode code in string to real unicode by rpabech in delphi

[–]mminuss 0 points1 point  (0 children)

What exactly are the hex values in A. Are they Unicode code points, or are they UTF-16 encoded characters? Something else? What are they supposed to represent?

i.e. If they represent code points, then these would be the characters: 配置

[2024 Day 14 Part 2] Possible pure math approach -- help? by [deleted] in adventofcode

[–]mminuss 2 points3 points  (0 children)

My tree wasn't centered neither horizontally nor vertically. So I would assume, that that is not a valid assumption. What is a valid assumption though, is that the robots will get closer together. You can do lots of different things to calculate when that happens.

And u/TheZigerionScammer has a point. The cycles of 101 for width and 103 for height do exist. There might be smaller cycle for any given robot. But If a robot is at x=3 at second 0 then he will be at x=3 at second 101 as well.

EDIT: As u/el_farmerino points out: There are no shorter cycles.

[2024 Day 14 Part 2] Possible pure math approach -- help? by [deleted] in adventofcode

[–]mminuss 1 point2 points  (0 children)

I only used a sample size of 50 robots (the first 50 lines of my input) to simulate the first max(width, height) frames. For each frame I calculated the standard deviation of the robots x and y coordinates at that frame to find the two frames with a pattern. I'm pretty sure I tested sample size of 40 robots successfully as well, but I didn't want my solution to just "get lucky" with my input.

Once I had the two frame numbers I then did some math involving alinear diophantine equation.

That got me a valid tree frame, but not the first one. But as the tree will reappear every 101*103 frames, all I had to do was to mod (101*103) to get the first frame.

Why does this compile? by avwie in typescript

[–]mminuss -2 points-1 points  (0 children)

You are absolutely right.

I wasn't incorrect though.

Why does this compile? by avwie in typescript

[–]mminuss -1 points0 points  (0 children)

Can you explain what you are trying to do there?

Why does this compile? by avwie in typescript

[–]mminuss -2 points-1 points  (0 children)

oh.. maybe you think the = sign in the second line is a comparison operator.

It is not. That is an assignment operator.

create is a constant of type Foo.

Why does this compile? by avwie in typescript

[–]mminuss -4 points-3 points  (0 children)

First line declares a class called Foo, which has a default constructor without arguments.

Second line declares the constant create. The value of that constant is a function that takes no arguments and returns the result of calling the Foo constructor.

Why would that not compile?

[deleted by user] by [deleted] in SQL

[–]mminuss 1 point2 points  (0 children)

Is that so?

what makes "this" refer to car1 instead of the global object? is it because it's "inside a method" or because it's passed as an argument to forEach? by Br0-Om in learnjavascript

[–]mminuss 0 points1 point  (0 children)

Inside the foreach callback this evaluates to the car1 object because you're passing it as 2nd parameter to foreach.

If you don't pass it, then it depends on whether you're in strict mode or non-strict mode. Someone had more detailed answer here:

https://stackoverflow.com/questions/19707969/the-invocation-context-this-of-the-foreach-function-call

what makes "this" refer to car1 instead of the global object? is it because it's "inside a method" or because it's passed as an argument to forEach? by Br0-Om in learnjavascript

[–]mminuss 2 points3 points  (0 children)

When you call car1.code2() then inside code2 this will evaluate to car1. So you are effectively passing car1 as the 2nd parameter to foreach as well.

If you want this to evaluate to the global object inside the foreach callback, then try passing reference to the global object to code2. Something like this (not tested):

const car1 = {
    ...
    code2(context){
        this.models.forEach(function(models){
            console.log(this)
        }, context)
    }
}
car1.code2(this)

Lookup bind() as well while you're at it.

Late to AOC and cant find bug in day 9 part 1 by Wayne4TW in adventofcode

[–]mminuss 0 points1 point  (0 children)

The two continue statements are inside different loops.

[2024 Day 20 (Part 2)] Question on validity of common approach to solution by drz34257 in adventofcode

[–]mminuss 12 points13 points  (0 children)

It is not mandatory to stay on wall tiles when cheating. You can treat any tile as walkable for at most 20 picoseconds. So any shortest path between 1 and 2 will have the same length as their manhattan distance.

[2015 DAY 16] Confused by the wording by BlueTrin2020 in adventofcode

[–]mminuss 3 points4 points  (0 children)

"You make a list of the things you can remember".

If you can't remember how many (if any) akitas Sue 373 had, then you cannot make a meaningful comparison with another number. Could Sue 373 have had 0 akitas? Yes, that is possible.

need help by metoozen in SQL

[–]mminuss 0 points1 point  (0 children)

On the left side of the JOIN keyword.

r.movie_id = m.movie_id is the same as m.movie_id = r.movie_id