Why is it bad practice to call an eventhandler from code?

It’s a question of how your program is organized. In the scenario you’ve described, the menu item’s behavior will be defined in terms of the button’s: procedure TJbForm.MenuItem1Click(Sender: TObject); begin // Three different ways to write this, with subtly different // ways to interpret it: Button1Click(Sender); // 1. “Call some other function. The name suggests … Read more

Is the compiler treatment of implicit interface variables documented?

If there is any documentation of this behavior, it will probably be in the area of compiler production of temporary variables to hold intermediate results when passing function results as parameters. Consider this code: procedure UseInterface(foo: IInterface); begin end; procedure Test() begin UseInterface(Create()); end; The compiler has to create an implicit temp variable to hold … Read more

Split a string into an array of strings based on a delimiter

you can use the TStrings.DelimitedText property for split an string check this sample program Project28; {$APPTYPE CONSOLE} uses Classes, SysUtils; procedure Split(Delimiter: Char; Str: string; ListOfStrings: TStrings) ; begin ListOfStrings.Clear; ListOfStrings.Delimiter := Delimiter; ListOfStrings.StrictDelimiter := True; // Requires D2006 or newer. ListOfStrings.DelimitedText := Str; end; var OutPutList: TStringList; begin OutPutList := TStringList.Create; try Split(‘:’, ‘word:doc,txt,docx’, … Read more

Is there a way to programmatically tell if particular block of memory was not freed by FastMM?

Even if such handler exist, it would be nearly useless, as everything, including DB would be shut down at the time when FastMM reports leaks. So, I suggest you to turn on LogErrorsToFile along with FullDebugMode conditionals in FastMM4Options.inc. This will give you a text file with leaks, which later you can parse and put … Read more

How do you extract local variable information (address and type) from a Delphi program or the compiler-generated debug info?

Check if any debugging symbols weren’t in binary. Also possible is using GDB (on Windows a port of it). It would be great if you found a .dbg or .dSYM file. They contain source code, eg. gdb> list foo 56 void foo() 57 { 58 bar(); 59 sighandler_t fnc = signal(SIGHUP, SIG_IGN); 60 raise(SIGHUP); 61 … Read more

How do I include a newline character in a string in Delphi?

In the System.pas (which automatically gets used) the following is defined: const sLineBreak = {$IFDEF LINUX} AnsiChar(#10) {$ENDIF} {$IFDEF MSWINDOWS} AnsiString(#13#10) {$ENDIF}; This is from Delphi 2009 (notice the use of AnsiChar and AnsiString). (Line wrap added by me.) So if you want to make your TLabel wrap, make sure AutoSize is set to true, … Read more

Are delphi variables initialized with a value by default?

Yes, this is the documented behaviour: Object fields are always initialized to 0, 0.0, ”, False, nil or whatever applies. Global variables are always initialized to 0 etc as well; Local reference-counted* variables are always initialized to nil or ”; Local non reference-counted* variables are uninitialized so you have to assign a value before you … Read more

Find out what process registered a global hotkey? (Windows API)

One possible way is to use the Visual Studio tool Spy++. Give this a try: Run the tool (for me, it’s at C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\spyxx_amd64.exe or you can download it). Note: there is spyxx.exe (32-bit version) and spyxx_amd64.exe (64-bit version) – if you don’t see anything in 64-bit use the 32-bit version (ie.catches … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)