Which language elements can be annotated using attributes language feature of Delphi?

Interesting question! You can declare attributes on almost anything, the problem is retrieving them using RTTI. Here’s a quick console demo of declaring custom attributes for: Enums Function type Procedure type Method type (of object) Aliased type Record type Class type Record type that’s internal to a class Record field Record method Class instance field … Read more

Fluent interface in Delphi

Everybody is just writing about negative issues so let’s stress some positive issues. Errr, the only positive issue – less (in some cases much less) typing. I wrote GpFluentXMLBuilder just because I hate typing tons of code while creating XML documents. Nothing more and nothing less. The good point with fluent interfaces is that you … Read more

Delphi – Equivalent to C#’s ternary operator? [duplicate]

Of course you can use IfThen(SomeBooleanExpression, IfTrueReturnValue, IfFalseReturnValue) where the return values are numeric (uses Math) or string (uses StrUtils). But notice that this will evaluate both arguments in all cases — there is no lazy evaluation, so it is not as efficient as the ?: operator in C#, where only the right operand is … Read more

How to compare double in delphi?

The Math.pas unit includes functions such as SameValue(), IsZero(), CompareValue() which handle floating type comparisons and equality. const EPSILON = 0.0000001; begin if CompareValue(p, pMax, EPSILON) = GreaterThanValue then ShowMessage(‘p greater than pMax’); The constant GreaterThanValue is defined in Types.pas If you’re comparing very large values you shouldn’t use a constant for epsilon, instead your … Read more

How can I tell if another instance of my program is already running?

As Jon first suggested, you can try creating a mutex. Call CreateMutex. If you get a non-null handle back, then call GetLastError. It will tell you whether you were the one who created the mutex or whether the mutex was already open before (Error_Already_Exists). Note that it is not necessary to acquire ownership of the … Read more

How to use the TTaskDialog?

If you can’t find the documentation, then write it: The Hello World of a Task Dialog with TTaskDialog.Create(Self) do try Caption := ‘My Application’; Title := ‘Hello World!’; Text := ‘I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ‘ + ‘in the Microsoft Windows Vista operating system. Am I not … Read more

How can I mark a property as deprecated in delphi?

No, this is not possible. According to the documentation, The ‘hint’ directives platform, deprecated, and library may be appended to any declaration. These directives will produce warnings at compile time. Hint directives can be applied to type declarations, variable declarations, class, interface, and structure declarations, field declarations within classes or records, procedure, function, and method … Read more

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