Jump to content

aehimself

Members
  • Content Count

    1073
  • Joined

  • Last visited

  • Days Won

    23

Everything posted by aehimself

  1. Yes, that was my fear too. Solution is rather easy though - don't use overloads πŸ™‚ I started to experiment and came to the realization that Self can be used in a class function / procedure. It only won't reference an instance, only the class of the calling object - even if it is a child. The below works perfectly: TBase = Class strict protected Function GetAsJSON: String; Virtual; Procedure SetAsJSON(inJSONString: String); Virtual; public Var1: Integer; Class Function New(inJSONString: String): TBase; Class Function New2(inInteger: Integer): TBase; Virtual; Property AsJSON: String Read GetAsJSON Write SetAsJSON; End; TChild = Class(TBase) strict protected Function GetAsJSON: String; Override; Procedure SetAsJSON(inJSONString: String); Override; public Var2: String; Class Function New2(inInteger: Integer; inString: String): TChild; ReIntroduce; End; // Class Function TBase.New(inJSONString: String): TBase; Begin Result := Self.Create; Result.AsJSON := inJSONString; End; Class Function TBase.New2(inInteger: Integer): TBase; Begin Result := Self.Create; Result.Var1 := inInteger; End; Class Function TChild.New2(inInteger: Integer; inString: String): TChild; Begin Result := TChild(inherited New2(inInteger)); Result.Var2 := inString; End; I don't like that there are two "New" methods now, but it feels a lot more clean.
  2. @Attila Kovacs Yep, just tested your theory and it does not work:
  3. Did not pay enough attention when writing the example πŸ™‚ Let me correct myself: TBase = Class public Var1: Integer; Class Function New(inJSONString: String): TBase; Overload; Virtual; Class Function New(inVar1: Integer): TBase; Overload; Virtual; End; TChild = Class(TBase) public Var2: String; Class Function New(inJSONString: String): TChild; ReIntroduce; Overload; Class Function New(inVar1: Integer; inVar2: String): TChild; ReIntroduce; Overload; End;
  4. aehimself

    Best practices for handling a Stalled thread

    Killing a thread is not a good idea in about 99% of the times πŸ™‚ The best case is that it will leak memory and / or abandon TCP connections. Worst case? It can leave corrupted temporary files around, render your application unusable and requiring a restart or even leave the system in an unbootable state (depending what it is doing which gets forcefully interrupted). Sometimes you have no other option though... There are some REALLY good advices there. Maybe you can launch the image processing in a child process - in regards to the host applications state killing a process can be less painful than a killing a thread.
  5. aehimself

    Open Url From Current Line

    There you go, I found it: https://dictionary.cambridge.org/us/dictionary/english/sarcasm I'll try to act like an adult and stop this discussion right here. If you would like to learn more about coding styles, Google is - as always - your friend. In the mean time, please learn how not to get offended when people say their favorite color is not the same as yours.
  6. aehimself

    Open Url From Current Line

    I'm no expert, but I'd say it's... nesting, which is... unnecessary? 😐
  7. aehimself

    Open Url From Current Line

    No, it's not. @Anders Melander said: "It's based on the experience that unnecessary nesting makes the code harder to read." which is not false and not an assumption. It's a general statement. I only can quote myself. Don't get offended. We are talking about personal preferences here.
  8. aehimself

    Open Url From Current Line

    There's always a connection. It's not spaghetti, it's tentacle code!
  9. aehimself

    Open Url From Current Line

    For me the changes make sense what @Anders Melander mentioned. But please - do not be OFFENDED. We are NOT saying it's bad code. As stated above - it's only PREFERENCE. πŸ™‚
  10. aehimself

    Open Url From Current Line

    I'm a fan of early returns, I use them all the times. For me it does improve readability but my colleagues complain that it makes it harder for them. This is a matter of preference IMO, nothing else.
  11. aehimself

    Combining several applications into one

    I respectfully disagree. I had issues with focus and modals not being true modals but otherwise it's working pretty all right. I have to admit that I docked quite simple applications (like PUTTY) until now, though.
  12. aehimself

    [legal] Need help with Packet Sniffer in Delphi

    Try not to modify the packets at all. Some games have cheat detection and disguise the "I caught you, cheater" message with a simple crash.
  13. Well, you are effectively - almost - doing the same πŸ™‚ This is a difference in point of views by different coders / companies. Sustain mode means only to fix critical bugs for me. Main window is frozen? Live with it; it's only visual, not critical.
  14. aehimself

    Combining several applications into one

    This is actually a really good idea. Call the .EXE's and dock their window into your application, like a new tabsheet. And until the clients are happy, you can work on the refactoring πŸ™‚
  15. What you see is how a specific operating system is handling unresponsive windows. It's not only your program, it's all which are freezing the main thread (therefore blocks message processing). If you don't mind getting your hand dirty by writing REALLY BAD code you can get away with periodically calling Application.ProcessMessages during your long operation: Procedure StartLongOperaton; Begin Operation1; Application.ProcessMessages; Operation2; Application.ProcessMessages; End; or Procedure WorkWithDataSet(inDataSet: TDataSet); Begin inDataSet.First; While Not inDataSet.Eof Do Begin DoSomethingWithRecord; inDataSet.Next; Application.ProcessMessages; End; End; ...but if you don't know what you are doing, you'll quickly face more issues than just a frozen window. PeekMessage works, because it is forcing the processing of windows messages, therefore your form will APPEAR not frozen. Application.ProcessMessages does the same, it's basically a better wrapper for it. The real solution is... well, you guessed it: threads. There is no such thing as a method is "not possible to put in a thread".
  16. aehimself

    Combining several applications into one

    When I reached a point like this in the past I always went for a full refactor. It's painful, it's slow, adding no new features at all (maybe even removing some...?) but you always can reuse chunks of code to help to finish faster. In the end it worths the effort, trust me. I had an application I was maintaining for 10 years (7 threads plus VCL logic written in Unit1.pas, with names like Button1 or Thread1) when I decided that it was too messy. It took about 3 months to rewrite the whole thing from scratch but implementing proper class inheritance and separation of data access, business logic and UI. Adding a new feature in the past took days or weeks, now it is a matter of hours. As an addition, I cannot tell how many bugs were fixed just by cleaning the code up. It's a tremendous and scary job. But knowing the result I'd definitely do it again.
  17. aehimself

    Styled DBGrid OnDrawDataCell

    Hello, In Delphi 10.3.3 I have a DBGrid component with the following handler: procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); Var r: TRect; begin If ZQuery1.RecNo Mod 2 = 0 Then Begin r := Rect; InflateRect(r, -1, -1); DBGrid1.Canvas.Lock; Try DBGrid1.Canvas.Pen.Color := clRed; DBGrid1.Canvas.Pen.Width := 2; DBGrid1.Canvas.MoveTo(r.Left, r.Top); DBGrid1.Canvas.LineTo(r.Right, r.Top); FInally DBGrid1.Canvas.Unlock; End; End; end; Everything works fine: Until the moment when I enable VCL Styles. At first, it appears okay: But if you start to click (especially try to drag and drop column headers) things start to fall apart: This does not seem to happen when there are no Styles enabled. Anyone has an idea on what is this and how to fix it? Thanks!
  18. aehimself

    Styled DBGrid OnDrawDataCell

    Soooo... the bad thing is that without major changes the original project started to work correctly and I don't know why!!! Especially since the raw DBGrid seems to have this issue and I don't remember fixing anything in my descendant...
  19. aehimself

    Styled DBGrid OnDrawDataCell

    Yes, original code was without .Lock and .Unlock but since it started to glitch out I decided to include it (and it remained). As for the Mod 2 it is no mystery, only my mistake: took the shots before changing the value - was experimenting with a lot of things before asking. Invalidating after a column drag will not be the solution - as this is only the sample code, and this is how I could recreate the issue. In the original project some lines are drawn correctly, some are in black (no matter that the color is set to red), some does not appear at all even without dragging involved.
  20. aehimself

    Controlling MS Word Window from Delphi form

    Completely agree with @David Heffernan here. From what I imagine your app is like, you would have easier (and more user friendly) results looking into writing a Word plugin instead.
  21. aehimself

    How to restore Windows Store

    Forget about dism and SFC, those commands never fixed any issues since I'm working with computers πŸ™‚ The command you are looking for is wsreset, I think I had to use it a couple of times on my Insider PC. https://www.thewindowsclub.com/reset-windows-store-cache
  22. aehimself

    Windows product ID (from the registry)...

    To be honest I am not 100% sure about it, but I think no. WMI is storing information in it's own database, which is a piece of junk. Back in the days when I was a sysadmin we had to rebuild countless corrupted WMI databases πŸ™‚ Wikipedia also seems to confirm that it's separate from Registry: "Windows Management Instrumentation (WMI) consists of a set of extensions to the Windows Driver Model that provides an operating system interface through which instrumented components provide information and notification." https://en.wikipedia.org/wiki/Windows_Management_Instrumentation
  23. aehimself

    Windows product ID (from the registry)...

    Don't rely on the registry, it easily can be overwritten! Even if it's temporary, it can confuse your application. I found this code in the Internet, which I extended to generate an MD5 hash with DCPCrypt. Remove it if you don't need / have it and use it if you want. HWID.7z
  24. aehimself

    Debugger in 10.3.3 is useless :'(

    Please tell me that Oracle VirtualBox is not using incremental/differential snapshots (like VMware does)! If yes, creating a snapshot and continuing to use the VM will eat up your disk space quicker than you could say "upgrade"!
  25. I personally never used FireDAC, and it shouldn't be an issue at all, but here we go. Maybe the driver waits for commiting the transaction? Also you can try not to clear, but simply say qry.SQL.Text := 'DROP TABLE USERS'. It will also trigger the change in the TStrings (which I guess the SQL property is) but it worths a try...
Γ—