Jump to content

bravesofts

Members
  • Content Count

    83
  • Joined

  • Last visited

Community Reputation

24 Excellent

Recent Profile Visitors

1775 profile views
  1. bravesofts

    Screenshot a Component

    unit Main.View; interface uses {$REGION ' Defaults Units .. '} Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Buttons, Vcl.StdCtrls, {$ENDREGION} // System.Types; type TMainView = class(TForm) Lbl1: TLabel; Btn1: TButton; Pnl1: TPanel; Pnl2: TPanel; Btn2: TButton; Lbl2: TLabel; Btn3: TSpeedButton; BtnCapture: TButton; ImgCapturedCtrl: TImage; CmboBox_Ctrls: TComboBox; procedure FormCreate(Sender: TObject); procedure BtnCaptureClick(Sender: TObject); private function CaptureControl(aControl: TControl): TBitmap; inline; public { Public declarations } end; var MainView: TMainView; implementation {$R *.dfm} function TMainView.CaptureControl(aControl: TControl): TBitmap; var LDC: HDC; LRect: TRect; LCtrlHwnd: THandle; LOffset: TPoint; begin Result := TBitmap.Create; try LRect := aControl.BoundsRect; Result.SetSize(LRect.Width, LRect.Height); Result.Canvas.Brush.Color := clWhite; Result.Canvas.FillRect(Rect(0, 0, LRect.Width, LRect.Height)); Result.Canvas.Lock; try if aControl is TWinControl then begin LCtrlHwnd := TWinControl(aControl).Handle; LOffset := Point(0, 0); // No offset needed for TWinControl end else begin LCtrlHwnd := TWinControl(aControl.Parent).Handle; LOffset := aControl.BoundsRect.TopLeft; // Convert to parent-relative coordinates end; LDC := GetDC(LCtrlHwnd); try BitBlt(Result.Canvas.Handle, 0, 0, LRect.Width, LRect.Height, LDC, LOffset.X, LOffset.Y, SRCCOPY); finally ReleaseDC(LCtrlHwnd, LDC); end; finally Result.Canvas.Unlock; end; except Result.Free; raise; end; end; procedure TMainView.FormCreate(Sender: TObject); var I: Integer; begin CmboBox_Ctrls.Items.Clear; for I := 0 to Self.ComponentCount - 1 do if Self.Components[I] is TControl then CmboBox_Ctrls.Items.Add(Self.Components[I].Name); CmboBox_Ctrls.ItemIndex := 0; end; procedure TMainView.BtnCaptureClick(Sender: TObject); var LCtrl: TControl; LBmp: TBitmap; begin if CmboBox_Ctrls.ItemIndex <> -1 then begin LCtrl := FindComponent(CmboBox_Ctrls.Text) as TControl; if Assigned(LCtrl) then begin LBmp := CaptureControl(LCtrl); try ImgCapturedCtrl.Picture.Assign(LBmp); finally LBmp.Free; end; end; end; end; end. Dfm object MainView: TMainView Left = 0 Top = 0 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'MainView' ClientHeight = 297 ClientWidth = 705 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -18 Font.Name = 'Segoe UI' Font.Style = [] OnCreate = FormCreate PixelsPerInch = 144 TextHeight = 25 object Lbl1: TLabel Left = 417 Top = 33 Width = 33 Height = 25 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Lbl1' end object ImgCapturedCtrl: TImage Left = 18 Top = 117 Width = 304 Height = 176 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 end object Btn1: TButton Left = 558 Top = 18 Width = 125 Height = 47 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Btn1' TabOrder = 0 end object Pnl1: TPanel Left = 402 Top = 202 Width = 281 Height = 68 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Pnl1' TabOrder = 1 end object Pnl2: TPanel Left = 402 Top = 90 Width = 281 Height = 107 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Pnl2' TabOrder = 2 object Lbl2: TLabel Left = 174 Top = 27 Width = 33 Height = 25 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Lbl2' end object Btn3: TSpeedButton Left = 150 Top = 69 Width = 118 Height = 33 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 end object Btn2: TButton Left = 15 Top = 27 Width = 113 Height = 38 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Btn2' TabOrder = 0 end end object BtnCapture: TButton Left = 18 Top = 21 Width = 304 Height = 50 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 Caption = 'Get Control Capture' TabOrder = 3 OnClick = BtnCaptureClick end object CmboBox_Ctrls: TComboBox Left = 18 Top = 81 Width = 304 Height = 33 Margins.Left = 5 Margins.Top = 5 Margins.Right = 5 Margins.Bottom = 5 TabOrder = 4 Text = 'CmboBox_Ctrls' end end good luck..
  2. bravesofts

    VCL UI Design Challenge for Delphi Developers 💡

    Of course, yes! It's your hard work and dedication here, and you absolutely deserve not only a license but lifelong respect for your efforts! 🔥🚀
  3. bravesofts

    VCL UI Design Challenge for Delphi Developers 💡

    Windows Composition API Is Still WinAPI ? Even though it’s sometimes called the “composition API,” functions like SetWindowCompositionAttribute or DwmSetWindowAttribute are exported from system DLLs (e.g., user32.dll or dwmapi.dll) and thus part of the Windows API. On Windows 11, you can apply Acrylic (DWMSBT_ACRYLIC) or Mica (DWMSBT_MAINWINDOW) to a window without a custom GPU pipeline, and it’s still hardware-accelerated by DWM behind the scenes. Delphi Borderless Form Native Windows 11 Rounded Corners You can request real rounded corners via the Windows 11 API
  4. bravesofts

    VCL UI Design Challenge for Delphi Developers 💡

    Sorry for that. TStyleManager uses custom resizing instead of the native Windows border, meaning the window won't have a native border & shadow when resizing. The form should be fully resizable and draggable without lag. -- To help you move forward, try this technique first: Delphi Borderless Form This is a good starting point. Regarding rounded corners, the challenge primarily targets Windows 11, but support for older versions down to XP is still important. -- For the glass blur effect, you should use the provided Windows API. Otherwise, if you implement your own workaround, the blur effect must run on a separate thread to ensure UI interactions remain smooth. -- Third-party components are not allowed. The window resizing and movement must be smoothly updated without high CPU usage. The app should run as fast and responsively as possible. --- Thank you for your interest! 😊
  5. bravesofts

    VCL UI Design Challenge for Delphi Developers 💡

    You have earned an abundance of love and respect over the years, especially through your outstanding contributions to UI design. I know you can do it—haha, you've already proven yourself time and time again!
  6. bravesofts

    VCL UI Design Challenge for Delphi Developers 💡

    You have earned an abundance of love and respect over the years, especially through your outstanding contributions to UI design. I know you can do it—haha, you've already proven yourself time and time again!
  7. bravesofts

    VCL UI Design Challenge for Delphi Developers 💡

    No, the background is not a static image. The form background is dynamically captured in real-time, just like a real glass window. It continuously updates to reflect any changes happening behind the form, creating a true transparent and blurred glass effect. 🚀
  8. 🔥 Who can accurately recreate this UI in Delphi VCL? 🔥 ---- 👉 Rules of the challenge: No third-party components – Only pure VCL! Windows API calls only – No hacks like setting a blurred wallpaper. True glass blur effect – The UI must feature real-time Gaussian Blur, not a fake overlay. Resizable & smooth movement – The form should be fully resizable and draggable without lag. Performance separation – The blur effect must run on a separate thread, ensuring that UI interactions stay smooth. Native Windows 11 style – The form should have real rounded corners, using the native Windows 11 API. Update on the challenge requirements: Regarding Resizing, and even Moving, the developer may revert the form’s design to be Normal in terms of background and borders (to make it easier for everyone to participate and to minimize code for smoother application performance). Regarding updating the background when the form does not move, you are also not required to provide this background capture (meaning we want everyone to participate, thank you). --- Happy birthday and a new year for Delphi—and every year, becomes stronger and better... --- 🚀 Fun fact: The login form shown in the image is actually running on Windows XP! 🤯 💬 Can you achieve this in Delphi VCL? Post your best attempt below! 👇 ----
  9. I finally found the best solution for this problem: Just put GPControls on TIKPageViewPage of TIKPageView (magically faster rendering happens) -- embedding GPControls on a TIKPageViewPage (from TIKPageView) dramatically improves the rendering performance—essentially making it "magically" faster. My Github Repo here
  10. Question About Optimizing GPControls Performance: I have a question if you don't mind: How can I make GPControls paint faster? I'm using multiple TscGPxxx controls in my form, and when resizing the form (especially with controls set to align/resize), I experience flickering and freezing. The entire form becomes unresponsive during resizing. Is there an efficient way to optimize rendering and improve performance when handling multiple GP controls? Any best practices or recommended settings to reduce redraw lag? Thanks in advance for your help!
  11. sorry, i can't understand your question --- are you trying to make more than one property read from single universal function, or you are trying to build a record for converting strings to integers ? --- or are you trying to build a dictionary of integers based on given strings ? this is what i can help for, if i get exactly what you want: if a dictionary: unit API.MyDictionary; interface uses System.SysUtils, System.Generics.Collections; type TDictionaryContainer = TDictionary<string, Integer>; TMyDictionary = class private fStrDictionary: TDictionaryContainer; function GetValueOrDefault(const aKey: string): Integer; procedure Log(const aMessage: string); public constructor Create(const aStrList: array of string); destructor Destroy; override; procedure AddOrUpdateKey(const aKey: string; aValue: Integer); procedure RemoveKey(const aKey: string); function TryGetValue(const aKey: string; out aValue: Integer): Boolean; property Dictionary: TDictionaryContainer read fStrDictionary; property Values[const aKey: string]: Integer read GetValueOrDefault; end; implementation { TMyDictionary } constructor TMyDictionary.Create(const aStrList: array of string); var I: Integer; begin fStrDictionary := TDictionaryContainer.Create; Log('Dictionary created.'); for I := Low(aStrList) to High(aStrList) do begin fStrDictionary.Add(aStrList[I], 0); // Initialize all keys with a default value of 0 Log(Format('Key "%s" added with default value 0.', [aStrList[I]])); end; end; destructor TMyDictionary.Destroy; begin Log('Dictionary destroyed.'); fStrDictionary.Free; inherited; end; procedure TMyDictionary.Log(const aMessage: string); begin // Simple console output for logging. // Replace this with your custom logging if needed. Writeln('[LOG] ', aMessage); end; procedure TMyDictionary.AddOrUpdateKey(const aKey: string; aValue: Integer); begin if fStrDictionary.ContainsKey(aKey) then begin fStrDictionary.AddOrSetValue(aKey, aValue); Log(Format('Key "%s" updated with value %d.', [aKey, aValue])); end else begin fStrDictionary.Add(aKey, aValue); Log(Format('Key "%s" added with value %d.', [aKey, aValue])); end; end; procedure TMyDictionary.RemoveKey(const aKey: string); begin if not fStrDictionary.ContainsKey(aKey) then begin Log(Format('Failed to remove key "%s": Key not found.', [aKey])); raise Exception.CreateFmt('Key "%s" does not exist in the dictionary.', [aKey]); end; fStrDictionary.Remove(aKey); Log(Format('Key "%s" removed.', [aKey])); end; function TMyDictionary.GetValueOrDefault(const aKey: string): Integer; begin if not fStrDictionary.TryGetValue(aKey, Result) then begin Result := 0; // Default value Log(Format('Key "%s" not found. Returning default value %d.', [aKey, Result])); end else Log(Format('Key "%s" found with value %d.', [aKey, Result])); end; function TMyDictionary.TryGetValue(const aKey: string; out aValue: Integer): Boolean; begin Result := fStrDictionary.TryGetValue(aKey, aValue); if Result then Log(Format('Key "%s" found with value %d.', [aKey, aValue])) else Log(Format('Key "%s" not found.', [aKey])); end; end. the dpr console test: program DictionaryPrj; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, API.MyDictionary in 'API\API.MyDictionary.pas'; procedure TestMyDictionary; var MyDict: TMyDictionary; Value: Integer; begin // Create the dictionary with initial keys MyDict := TMyDictionary.Create(['Key1', 'Key2']); try MyDict.AddOrUpdateKey('Key1', 10); MyDict.AddOrUpdateKey('Key3', 15); MyDict.TryGetValue('Key2', Value); MyDict.Values['Key1']; MyDict.Values['Key4']; // Returns default value (0) MyDict.RemoveKey('Key1'); MyDict.AddOrUpdateKey('Key1', 100); MyDict.Dictionary.Items['Key1']; finally MyDict.Free; end; end; begin try TestMyDictionary; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. i hope this what you looking for..
  12. bravesofts

    Introducing TRange<T>

    Thank you for your questions and feedback! I understand—it’s a lot to go through! That was long for a reason: I know many people don’t have much time to browse a repo, so I wrote everything necessary to make it easier for them, especially on mobile devices. Still, I’ll consider shortening it for better clarity. Thanks for the feedback! My class specifically handles the IsInRange case. In the demo, I used TPoint (a record) and a custom comparer to determine if a point is within a range of two points. While equality or ordering functions aren’t implemented yet, I believe they would work similarly. Adding these is something I plan to explore in future updates and It would be great if you’d like to contribute by adding this functionality—it’d be much appreciated! 😊 To be honest, I’ve never used this functionality before in my life. I didn’t publish this class to boast or to tell people, “Look how skilled I am in Delphi.” In reality, I’m a very simple and self-taught Delphi developer, and I’m proud of that, of course. I’m still in the process of learning and discovering what amazing capabilities and skills can be unlocked in Delphi. I might try DUnit or DUnitX in the future, but for now, I’m focused on exploring and growing my understanding of the language. Like I mentioned before, I’m not as good a programmer as you might think—I’m just a self-taught Delphi enthusiast. Honestly, I think I just love Delphi and its tools, but when it comes to GitHub or any other tools, they’re not really my thing. I’ve never worked as a programmer or developer in a professional capacity, and tools like Agile or Git aren’t even on my radar. I guess you could call me a jungle developer! 😊 That said, I appreciate the feedback and will try to improve the repo organization in the future. Thanks for the feedback!
  13. bravesofts

    How to open form2 then close form1

    hidding instance of TForm1 doesn't mean is closed!! --- Creating a Form2 instance without an owner by passing nil in Create(nil) can lead to a memory leak if an exception occurs!! The code lacks proper cleanup for Form2. A better practice is to use a try..finally block to ensure Form2 is freed, even if an exception occurs. Form2 := TForm2.Create(nil); try Form2.ReceivedValue := TButton(Sender).Caption; Form2.Position := poScreenCenter; Form2.ShowModal; finally Form2.Free; end; When Form1 is the main form, closing it will terminate the entire application. To handle this scenario while still achieving the desired behavior (hiding Form1 and showing Form2 modally), you can modify the code as follows: Avoid Global Form Variables: Avoid using Form2 as a global variable unless necessary. Use local variables whenever possible: Updated Code with Form1 as MainForm: procedure TForm1.Button1Click(Sender: TObject); var LNewForm2: TForm2; begin // Hide the MainForm (Form1) Self.Hide; try // Create and display Form2 LNewForm2 := TForm2.Create(nil); try LNewForm2.ReceivedValue := TButton(Sender).Caption; // Pass value to Form2 LNewForm2.Position := poScreenCenter; if LNewForm2.ShowModal = mrOk then begin // Show Form1 again if Form2 was accepted Self.Show; end else begin // Handle Cancel logic (if needed) Self.Close; end; finally LNewForm2.Free; // Ensure Form2 is freed end; except on E: Exception do begin // Show the MainForm back if any exception occurs Self.Show; raise; // Re-raise the exception end; end; end;
×