Jump to content

aehimself

Members
  • Content Count

    1085
  • Joined

  • Last visited

  • Days Won

    23

Everything posted by aehimself

  1. aehimself

    Simple ORM

    Instead of “SELECT * FROM MyTable WHERE ID = 99” use “SELECT * FROM MyTable WHERE ID = :pID”, then assign the value 99 for the parameter named pID.
  2. A .dproj file refers to a Delphi project but the error message says it’s looking for a C++ builder license. I’m not sure what to do with this information though; is it possible that your file associations are off? You can reset all associations from the Tools menu somewhere, you can give it a try if Delphi is starting up without a project.
  3. Try updating your external dependencies. I had the very same issue with an older MySQL driver a while ago.
  4. aehimself

    Hosting a console in a Delphi Application

    Minimum code I used is: procedure TForm1.FormCreate(Sender: TObject); Var windowstyle: Integer; appthreadid: Cardinal; cmdhandle: THandle; Begin cmdhandle := FindWindow('ConsoleWindowClass', 'Command Prompt'); // Hide title bars and borders of launched application windowstyle := GetWindowLong(cmdhandle, GWL_STYLE); windowstyle := windowstyle - WS_CAPTION - WS_BORDER - WS_OVERLAPPED - WS_THICKFRAME; SetWindowLong(cmdhandle,GWL_STYLE,windowstyle); // Attach the container applications input thread to the launched ones, so that we receive user input appthreadid := GetWindowThreadProcessId(cmdhandle, nil); AttachThreadInput(GetCurrentThreadId, appthreadid, True); // Docking. Change the parent of the launched application WinApi.Windows.SetParent(cmdhandle, Self.Handle); SendMessage(Self.Handle, WM_UPDATEUISTATE, UIS_INITIALIZE, 0); UpdateWindow(cmdhandle); // Make the docked window fill all the client area of the container SetWindowPos(cmdhandle, 0, 0, 0, Self.ClientWidth, Self.ClientHeight, SWP_NOZORDER); // This prevents the parent control to redraw on the area of its child windows (the launched application) SetWindowLong(Self.Handle, GWL_STYLE, GetWindowLong(Self.Handle, GWL_STYLE) Or WS_CLIPCHILDREN); // SetForegroundWindow(WindowHandle); // SetFocus(WindowHandle); End; This does not take care of resizing the docked window if the form resizes and you also have to keep an eye on if / when your docked application closes. Also it includes no error checking / handling. The result is as expected:
  5. aehimself

    Createprocess won't die

    PING -t will continue to ping until you manually terminate it (usually Ctrl-C in your window). The code above does what it is told - read until the process ends; but the process will never die due to the -t switch. As your main thread is stuck in this loop you have but a handful of options: - Introduce a counter in the cycle. Exit the repeat-until cycle when the counter reaches a specific amount - Start a secondary thread before the loop, passing the process handle to it. The secondary thread can then kill the process at any time, causing the loop to break - You also can use a timer but you have to inject a message pump in your inner loop - Move this method to a thread and spam it across with "If Self.Terminated Then Exit". Start your thread and kill it any time from your main application with mythread.Terminate I'd go with option 4 as that is going to leave the UI useable during execution.
  6. aehimself

    Good data grid for VCL and FMX

    SMComponents does that and their grid comes with many other interesting features while being as simple as possible. It's even free...! I almost ended up replacing my own DBGrid descendant with these when I had enough of tinkering around trying to fix it's issues 🙂
  7. Yes, it is exposed as TStream, but internally it's a TMemoryStream if I recall correctly. So yes, typecasting is needed.
  8. AFFAIK it's a TMemoryStream, so you simply can call ContentStream.SaveToFile. You also can create a separate TFileStream and use .CopyFrom(ContentStream). just make sure position is 0 before calling .CopyFrom.
  9. aehimself

    VCL Wrap

    This is EXACTLY how I "injected" my own extended DBGrid in my app before I put it in an installable package. Good to know it's an "accepted" way of solving this 🙂
  10. In later Delphi versions there's a build in record for this, System.Hash.THashSHA2. If available, you also can use this so it doesn't depend on a DLL. Maybe v10+, I'm not sure though.
  11. aehimself

    Delphi Professional Database Connectivity

    As far as I know FireDac is present in Professional but you only get the sources in Enterprise. Having the sources can help you to debug issues or easily create your own descendants of it's components in case you need to extend functionality. If you need the sources but can not / don't want to upgrade to Enterprise you always can install a 3rd party library like Zeos.
  12. aehimself

    Delphi says "x is not a valid integer value"

    If StrToInt says a string is not a number thus it can not be converted, trust it, it's true. If you are really interested, you can use the function "Val" which will even tell you which character is causing it to fail. You might want to sanitize your input first for spaces or other non-printable characters which get there easily if you copy-paste from documents / websites. Also, consider what @Remy Lebeau said, and use a TSpinEdit or TNumberBox instead (you can check NumbersOnly in TEdit as well). This way the input won't even be accepted if the pasted string / typed character is not a number.
  13. aehimself

    VCL Styles Flickering

    I had extreme flickering of controls which were placed on TPanels. The solution was to enable ParentBackground of the TPanel when the current is the system style, otherwise set it to false. Flickering gone down with a huge margin.
  14. aehimself

    VCL and VCL styles - bugs and future

    I just would like to add one more thing to the list, VCL styles renders TRichView.CreateParented unusable. Microsoft advises to create a rich text editor for RTF manipulation. Imagine that you have a thread: TTransformatorThread = Class(TThread) strict private _document: TStream; protected Procedure Execute; Override; public Constructor Create(Const inDocument: TStream); ReIntroduce; End; constructor TTransformatorThread.Create(const inDocument: TStream); begin inherited Create(False); _document := inDocument; end; procedure TTransformatorThread.Execute; Var rtf: TRichEdit; wnd: HWND; a, max: Integer; begin inherited; _document.Position := 0; wnd := AllocateHwnd(nil); Try rtf := TRichEdit.CreateParented(wnd); Try rtf.Lines.LoadFromStream(_document); rtf.SelStart := Integer.MaxValue; max := rtf.SelStart; a := 0; While a < max Do Begin rtf.SelStart := a; rtf.SelLength := 1; rtf.SelAttributes.Color := clRed; a := rtf.SelStart + rtf.SelLength; End; _document.Size := 0; rtf.Lines.SaveToStream(_document); _document.Position := 0; Finally FreeAndNil(rtf); End; Finally DeAllocateHwnd(wnd); End; end; It recolors all sections text to red, but it's only for demonstration. Now, have the following code: TForm1 = class(TForm) ThreadWatchTimer: TTimer; RichEdit1: TRichEdit; procedure FormCreate(Sender: TObject); procedure ThreadWatchTimerTimer(Sender: TObject); strict private _doc: TMemoryStream; _thd: TTransformatorThread; end; procedure TForm1.FormCreate(Sender: TObject); begin _doc := TMemoryStream.Create; _doc.LoadFromFile('C:\Temp\MyDocument.rtf'); _thd := TTransformatorThread.Create(_doc); ThreadWatchTimer.Enabled := True; end; procedure TForm1.ThreadWatchTimerTimer(Sender: TObject); begin ThreadWatchTImer.Enabled := Assigned(_thd) And Not _thd.Finished; If Not Assigned(_thd) Then Exit; If _thd.Finished Then Begin RichEdit1.Lines.LoadFromStream(_doc); End; end; The theory is easy. You load the document in a stream, pass it to the thread to process and modify it, and when the thread finishes you load the modified content in the rich edit on the form. I know, passing a TStream screams of thread safety but it's simple enough for this demonstration. If you run this without any VCL style active, all works fine. If you set any style... it will load the document but the program will freeze. I suppose the StyleHook is attempting to stylize the hidden rich editor in a background thread, thus causing the lockup. Tested with D11.3, so I suppose previous installations are also affected. Edit: Added test project richeditstyle.7z
  15. aehimself

    String literals more then 255 chars

    I wrote a small method to convert any text (even multiple lines) to a "Delphi source file string". I'm sure there are limitations but does it's job just fine for me: Function ToDelphiString(Const outString: String): String; Const ADDITION = #39' + '#39; BREAKAT = 80; Var line, a, max: Integer; sb: TStringBuilder; strarr: TArray<String>; Begin sb := TStringBuilder.Create; Try sb.Append(#39); strarr := AdjustLineBreaks(outString).Split([sLineBreak]); For line := Low(strarr) To High(strarr) Do Begin max := strarr[line].Length Div BREAKAT; For a := 0 To max Do Begin sb.Append(strarr[line].Substring(a * BREAKAT, BREAKAT).Replace(#39, #39#39)); sb.Append(#39); If a <> max Then sb.Append(' +' + sLineBreak + #39); End; If line <> High(strarr) Then sb.Append(' + sLineBreak +' + sLineBreak + #39); End; Result := sb.ToString; Finally FreeAndNil(sb); End; End; You can use it to overcome the 255 character limitation.
  16. aehimself

    Panels and alignment

    You can also rearrange visible controls by setting the .Left property to the previous control's Left + 1. That way, it will be placed immediately after it. You might also want to wrap everything in Container.DiableAlign and .EnableAlign so you get the results you want to see.
  17. TJSONObject(TJSONObject(TArrayElement).GetValue('type')).GetValue<String>(message, messagestring); TJSONObject(TArrayElement).GetValue<Integer>('time', timeinteger); TJSONObject(TArrayElement).GetValue<String>('flex', flexboolean); Also, don't forget to wrap the inner code in a Try...Finally block so you free JSONValue no matter what.
  18. aehimself

    Disable then Enable a Procedure

    TMyForm = Class(TForm) strict private _doit: Boolean; [...] Procedure TMyForm.MyProc; Begin If Not _doit Then Exit; [...] End; TForm1..DBGrid2DblClick(Sender: TObject); Begin _doit := False; Try [...] Finally _doit := True; End; End;
  19. aehimself

    Hex Viewer

    You probably need to include ATBinHex and Vcl.Forms in your uses (include) list. Being a Delphi-only guy I'm afraid I'll not be able to give you the exact code for C++ projects 😞
  20. aehimself

    Hex Viewer

    I didn't change the component source, just cloned the repo from GitHub and installed it in Delphi. All the code I mentioned is in my application. It's a good thing because it's completely detached from the component. It's bad, because those have to be included in each application you use ATBinHex in. You can make a class helper with a public .Recolor method so you easily can recolor each instance after the style changed. You also can take it one step further, create your own ATBinHex descandant, and use AllocHWND to listen for CM_STYLECHANGED and recolor automatically. You still have to register the style hook somewhere else though. I continuously got AVs if I included it in the helper class constructor / unit initialization section. You need ScrollingStyleHook, otherwise scrollbars won't be themed AFAIK.
  21. aehimself

    Hex Viewer

    The first one is in my "uFixVCLStyles" unit initialization section. The second block is in the window / form constructor. Unfortunately coloring won't change if a different style is selected runtime and an ATBinHex component is already visible, but you can solve this by handling the CM_STYLECHANGED message and put the recoloring code in there.
  22. aehimself

    Hex Viewer

    VCL styling issue can easily be fixed: TStyleManager.Engine.RegisterStyleHook(TATBinHEX, TScrollingStyleHook); And of course: ATBinHex.Color := TStyleManager.ActiveStyle.GetStyleColor(scEdit); ATBinHex.TextColorHexBack := TStyleManager.ActiveStyle.GetStyleColor(scEdit); ATBinHex.Font.Color := TStyleManager.ActiveStyle.GetStyleFontColor(sfEditBoxTextNormal); ATBinHex.TextColorHex := TStyleManager.ActiveStyle.GetStyleFontColor(sfEditBoxTextNormal); ATBinHex.TextColorHex2 := TStyleManager.ActiveStyle.GetStyleFontColor(sfEditBoxTextNormal);
  23. aehimself

    Freeing a non-modal form

    You can use WIndows messages via PostMessage to notify the owner. With that said, if a third component is controlling the lifecycle of said form it's better to review your program design. E.g. have a class which is showing / hiding forms, and create your forms with (nil) as owner.
  24. aehimself

    App crash on close when windows style = windows

    Did you manage to consistently reproduce the issue? At me it seemed random, popped up once or twice before disappearing for days.
  25. aehimself

    ENG-US keyboard automatically added on app start

    Does the app call LoadKeyboardLayout without KLF_SETFORPROCESS?
×