Is there, or is there ever going to be, a conditional operator in Delphi?

Such an operator isn’t part of the current Delphi version because it wasn’t part of the previous version, and demand wasn’t great enough to justify the cost of adding it. (You’ll find that explanation applies to lots of features you wish you had in lots of products.) Delphi provides a set of IfThen functions in … Read more

Converting TMemoryStream to ‘String’ in Delphi 2009

The code you have is unnecessarily complex, even for older Delphi versions. Why should fetching the string version of a stream force the stream’s memory to be reallocated, after all? function MemoryStreamToString(M: TMemoryStream): string; begin SetString(Result, PChar(M.Memory), M.Size div SizeOf(Char)); end; That works in all Delphi versions, not just Delphi 2009. It works when the … Read more

What is TMonitor in Delphi System unit good for?

TMonitor combines the notion of a critical section (or a simple mutex) along with a condition variable. You can read about what a “monitor” is here: http://en.wikipedia.org/wiki/Monitor_%28synchronization%29 Any place you would use a critical section, you can use a monitor. Instead of declaring a TCriticalSection, you can simple create a TObject instance and then use … Read more

Which variables are initialized when in Delphi?

Global variables are zero-initialized. Variables used in the context of the main begin..end block of a program can be a special case; sometimes they are treated as local variables, particularly for-loop indexers. However, in your example, r is a global variable and allocated from the .bss section of the executable, which the Windows loader ensures … Read more

What components and IDE add-ins do you install with Delphi? [closed]

My list: The Dev.Express Quantum grid: enhanced grid component: once you get the hang of this component, you can use it in all sorts of scenarios (at least I have) Dev.Express Quantum Tree list: if you know the grid component, you can use this component as well (treelist and grid combined) Dev.Express Express bars: menu … Read more

How do I make a PNG resource?

Example text file (named myres.rc): MYPNG RCDATA mypng.png Added to project: {$R ‘myres.res’ ‘myres.rc’} Example of loading at runtime: uses PngImage; var Png: TPngImage; begin Png := TPngImage.Create; try Png.LoadFromResourceName(HInstance, ‘MYPNG’); Image1.Picture.Graphic := Png; // Image1: TImage on the form finally Png.Free; end; end;

Delphi 2006-2010 error: “Cannot create file C:\Users\Admin\AppData\Local\Temp\EditorLineEnds.ttr”

There are three solutions to this that I am aware of: Try uninstalling the Windows security update KB2982791 which was already mentioned by Francisco Caffagni. This solved the issue for me (Windows 8.1 + Delphi 2007) but it might not be such a good idea to uninstall a Windows security update. Rename the file every … 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

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