Highlight
---------

This constructor:

```delphi
constructor TCoords.Create(const AX, AY: Integer);
begin
    TCoords.Create(Point(AX, AY));
end;

```

has been confirmed malfunctioning in both Linux Lazarus 2 and Windows Delphi XE6.

Could this be a bug?

---

I am new to OOP in Lazarus / Delphi, excuse possible newbie error. Thank you.

I can't seem to understand why the following sequence of Lazarus / (Delphi-like) custom, very basic, an object will not work. I'm trying to debug this for hours already, since then I found:

**What works:**

Calling the one constructor without an argument, and calling the one with TPoint argument directly.

**What doesn't:**

Calling this one:

```delphi
constructor Create(const AX, AY: Integer);

```

However, I found this would work - But **only if** if called without its class name inside the constructor. Why is that causing trouble?

---

Declarations
------------

```delphi
// WORKS - this creates instance of TCoords initialized to PointOutOfReach
constructor Create; reintroduce;
// WORKS - this creates instance of TCoords initialized to user coordinates
constructor Create(const ACoords: TPoint);
// DOES NOT WORK, strangely returns Point(0, 0), if called with class name
// WORKS only if called without class name - confusing or error on my side?
constructor Create(const AX, AY: Integer);

```

---

Calls
-----

```delphi
// OK - WORKING
NewCoords := TCoords.Create;
NewCoords.X:=12;
NewCoords.Y:=120;
ShowMessage(NewCoords.X.ToString + ' : ' + NewCoords.Y.ToString);
NewCoords.Free;

// OK - WORKING
NewCoords := TCoords.Create(Point(12, 120));
ShowMessage(NewCoords.X.ToString + ' : ' + NewCoords.Y.ToString);
NewCoords.Free;

// NOT WORKING as expected
NewCoords := TCoords.Create(12, 120);
ShowMessage(NewCoords.X.ToString + ' : ' + NewCoords.Y.ToString);
NewCoords.Free;

```

---

Coords unit with TCoords object definition
------------------------------------------

```delphi
unit Coords;

{$mode objfpc}{$H+}

interface

uses
    Classes;

type
    // Flexible X,Y coordinates object.
    TCoords = class(TObject)

    // these declarations are accessible within this unit only
    private
        // this is the variable we are working with
        FCoords: TPoint;
        // property for this function is unnecessary, but I like it as it is
        function IsInitialized: Boolean;

    // these declarations are accessible to all
    public
        // this creates instance of TCoords initialized to PointOutOfReach
        constructor Create; reintroduce;
        // this creates instance of TCoords initialized to user coordinates
        constructor Create(const ACoords: TPoint);

        // THIS ONE DOES NOT WORK, strangely returns Point(0, 0)
        constructor Create(const AX, AY: Integer);

        // this indicates if instance was initialized or not by the user
        property Initialized: Boolean read IsInitialized;
        // this works directly with private FCoords variable storing coordinates
        property P: TPoint read FCoords write FCoords;
        // these two are shortcuts for X,Y coordinates' direct access
        property X: Integer read FCoords.X write FCoords.X;
        property Y: Integer read FCoords.Y write FCoords.Y;

    end;

implementation

var
  // this gets initialized when loading this unit
  PointOutOfReach: TPoint;

constructor TCoords.Create;
begin
    // this is the same as `inherited`, but I like to be explicit
    inherited Create;
    // since called without argument, we have to ensure, there is some nonsense
    FCoords := PointOutOfReach;
end;

constructor TCoords.Create(const ACoords: TPoint);
begin
    // this is the same as `Create`, but I like to be explicit
    TCoords.Create;
    // in the previous mandatory call we have initialized FCoords already
    // but to PointOutOfReach; here we overwrite it with user coordinates
    FCoords := ACoords;
end;

constructor TCoords.Create(const AX, AY: Integer);
begin
    // this is the same as `Create(TPoint)`, but I like to be explicit
//    TCoords.Create(Point(AX, AY));

    // Why can't I call the above, shouldn't it be the very same?
    Create(Point(AX, AY));
end;

function TCoords.IsInitialized: Boolean;
begin
    // this returns True in case FCoords has been initialized
    // initialized means here for the FCoords point to be different from PointOutOfReach
    // achieved either by calling `Create(APoint)`, or later overwriting PointOutOfReach
    Result := FCoords <> PointOutOfReach;
end;

initialization

    // initialize PointOutOfReach to "impossible" coordinates when loading unit
    PointOutOfReach := Point(MAXINT, MAXINT);

end.

```

---

Thank you in advance, I myself can't seem to see the difference between those two.

---

Major error corrected - no change
---------------------------------

Missing `overload;` in constructors' declarations has been corrected. Still getting 0,0 coords from the last constructor, sadly.