-
Content Count
1030 -
Joined
-
Last visited
-
Days Won
22
Posts posted by aehimself
-
-
On 6/21/2023 at 5:01 PM, Rollo62 said:Wouldn't it be more clean to use the interposer without the intermediate class wrapper TSuperButton ?
https://zarko-gajic.iz.hr/delphi-interceptor-classes-tbutton-classtbutton/
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 🙂
-
On 6/25/2023 at 10:43 AM, Angus Robertson said:Because ICS does not have a native SHA-256 implementation, it now uses OpenSSL for digest operation.
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.
-
9 minutes ago, hackbrew said:I have set up some test databases in AWS RDS (MySQL, PostgreSQL, and MariaDB). Assuming I have the proper user permissions for basic CRUD operations, am I able to connect to the databases with Delphi Professional (v10.4)? If so, what if any advantage would upgrading to Delphi Enterprise provide me for this task?
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.
- 1
-
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.
-
On 3/29/2023 at 9:59 AM, balabuev said:Do I understand correctly that a control, which is not a TWinControl (for example, TLabel), has no way to implement flicker free drawing with VCL Styles turned on?
It seems that the parent form erases its own background via TFormStyleHook.PaintBackground not excluding child controls. This happens in both: Form.DoubleBuffered = False and Form.DoubleBuffered = True modes.
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.
-
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
-
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.
-
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.
-
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.
-
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;
- 1
-
Hex Viewer
in VCL
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 😞
-
Hex Viewer
in VCL
7 hours ago, CyberPeter said:Could you share the changed *.pas file where this change is made ?
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.
8 hours ago, CyberPeter said:I looked it up and it appears TATBinHex needs to inherit from TStyleHook
You need ScrollingStyleHook, otherwise scrollbars won't be themed AFAIK.
-
Hex Viewer
in VCL
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.
-
Hex Viewer
in VCL
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);
-
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.
- 1
-
51 minutes ago, GPRSNerd said:I can confirm that Delphi 11.3 has the issue fixed.
No more exception on close when the default style "Windows" was used/changed during runtime.
Did you manage to consistently reproduce the issue?
At me it seemed random, popped up once or twice before disappearing for days.
-
Does the app call LoadKeyboardLayout without KLF_SETFORPROCESS?
-
Fyi, D11.3 (in theory) solved some issues with UnregisterStyleHook.
Can not confirm, though.
-
Oh, I completely seem to have missed you are asking about the Delphi IDE..
Editor:
Ctrl-Shift-C
Ctrl-Shift-Up / Down
While debugging, F7 and Shift - F7 (I know people working withing with Delphi for 5+ years and didn't know about this)
Ctrl-Shift-E can be useful when it's working...
Ctrl + /
Ctrl + F12
Designer:
Alt + F12
Ctrl + H
- 1
-
Alt-F4? 🙂
Back to the topic, either fully configurable or as close to the competition as possible. You have better chance for new users to quickly feel comfortable using application if it behaves like something they already got used to (LibreOffice/OpenOffice vs. Word).
Also, for what function?
Ctrl-N usually means "New" something. If you do not have an action to create a new something, you can use it for nanobot deployment.
- 1
-
Not to depend on 3rd-party control applications, you should look in Windows APIs:
I personally never used this so it's possible that it's obsolete, needs elevation, you manually have to import it or all of the above. It should be a good starting point, though.
-
What if the form and all the controls are created runtime by the thread? Then once the thread is completed the main thread can show it.
I recall a post about a background thread being able to build and even show a form in VCL; it's just two threads should not access it the same time.
Even if so, maybe that is not even applicable under FMX...
Anyway, I thought it worth to ask.
-
Hello,
Are you still using Zeos to access the database? As all works fine it you have IB on the client, I do believe that you are missing some dependencies (like OpenSSL, Visual C runtime, etc) what the installation contains. I have no experience with IB, but Oracle needs a minimum of 3 .dlls for the library to function properly.
You can try to copy all libraries from an IB installation to a specific folder, set the LibraryPath to the driver there and attempt to connect. If it works, rename a random file to .old for example and try again. Repeat until nothing else can be renamed without breaking the connection attempt.
it's also possible that the installer puts additional files under any folder in your %PATH% environment variable, even extending it!
- 1
-
4 minutes ago, gkobler said:Just wait for D11.3 😉
I secretly hope that even after the release of 11.3 an LSP fix is going to be released for 11.2 since they figured out how to make one which is "best it's ever been".
It's considered a nice business practice to deliver a usable product what you actually got paid for.
TNetHttpRequest.ContentStream Save To File
in Network, Cloud and Web
Posted
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.