Assigned vs nil

TL;DR The official documentation states Assigned(P) corresponds to the test P <> nil for a pointer variable, and @P <> nil for a procedural variable. Hence, for a non-procedural pointer variable (such as a variable of type PInteger, PMyRec, TBitmap, TList<integer>, or TFormClass), Assigned(P) is the same thing as P <> nil. However, for a … Read more

Delphi: How to organize source code to increase compiler performance?

Some things that could slow down the compiler Redundant units in your uses clause. See this question for a link to CnPack. Not explicitly adding units to your project file. You’ve already seem to have covered that. Changed compiler settings, most notably include TDD32 info. Try to get rid of unused units in your uses … Read more

Interfaces and properties

No. Interfaces are implemented as function tables (basically a simple virtual method table) and the compiler needs to know there’s a function to map the property onto. You can declare a property on an interface, but it has to have functions as getter/setter values, not fields. You can make it read-only or write-only, though.

Best way to sort an array

You can add pointers to the elements of the array to a TList, then call TList.Sort with a comparison function, and finally create a new array and copy the values out of the TList in the desired order. However, if you’re using the next version, D2009, there is a new collections library which can sort … Read more

How to open an URL with the default browser with FireMonkey cross-platform applications?

Regarding the answer of mjn, I have written the following unit. I have successfully tested it on Windows but I don’t have an OSX to test it on this platform. If someone can confirm it works, I’d appreciate. unit fOpen; interface uses {$IFDEF MSWINDOWS} Winapi.ShellAPI, Winapi.Windows; {$ENDIF MSWINDOWS} {$IFDEF POSIX} Posix.Stdlib; {$ENDIF POSIX} type TMisc … Read more

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

How to access private methods without helpers?

If there is extended RTTI info generated for the class private members – fields and/or methods you can use it to gain access to them. Of course, accessing through RTTI is way slower than it was through class helpers. Accessing methods: var Base: TBase2; Method: TRttiMethod; Method := TRttiContext.Create.GetType(TBase2).GetMethod(‘UsefullButHidden’); Method.Invoke(Base, []); Accessing variables: var Base: … Read more

What’s the difference between public and published class members in Delphi?

The compiler generates RTTI (Run-Time Type Information) metadata for published members, but not for public members (by default). The main effect of this is that the published properties of an object will appear in the Object Inspector at design time. I do not know if you are writing components, but if you do, you probably … 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

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