On 21/09/16 06:30, Tomas Hajny wrote:
On Wed, September 21, 2016 07:29, Lars wrote:


Hi all, I am wondering what your thoughts are on this
idea: add the ability to do if assigned() on all
objects to prevent bugs, maybe as a compiler feature.

What would be the supposed "else" clause of your "if" statement? I assume
that the original action with the given object should not be ignored
silently, because that would lead to even more difficult debugging of such
bugs. Run-time error? But that is already happening with access violation
too. Or...?

Presumably this would be an assertion that something is assigned. A related test is that an object is a specific subtype before using it as such

  Assert(PageControl1.ActivePage.Controls[0] is TSynEdit);
  syn := TSynEdit(PageControl1.ActivePage.Controls[0]);

but I'd suggest that this is as much a refactoring problem as one which should be tackled by the compiler.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org

Reply via email to