Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 12 of 12 total
Thread Accessing objects with name as string
Thu, Feb 25 2016 5:20 PMPermanent Link

Matthew Jones

<Trinione> wrote:
> "Matthew Jones" wrote:
>
> << Probably best if you could post your real code, rather than my
> contrived (edited down from a real dialog) code. >>
>
> Hi:
> I receive 'Out of stack space ... Line 1' application error message when
> I try to run this code. What am I doing wrong?
>
> procedure TfrmMain.Button1Click(Sender: TObject);
> begin
>   if Not Assigned(frmTestGetSet) then
>     frmTestGetSet := TfrmTestGetSet.Create(nil);
>
>   frmTestGetSet.Code := 999;
>   ShowMessage(IntToStr(frmTestGetSet.Code));
> end;
>
>
> ////////// formTestGetSet  //////////
>
> type
>    TfrmTestGetSet = class(TForm)
>       procedure frmTestGetSetDblClick(Sender: TObject);
>    private
>       { Private declarations }                     
>       iCode: integer;
>       function GetCode: integer;
>       procedure SetCode(Code: integer);
>    public
>       { Public declarations }
>       property Code : integer read GetCode write SetCode;
>    end;
>
> var
>    frmTestGetSet: TfrmTestGetSet;
>
> implementation
>
> function TfrmTestGetSet.GetCode : integer;
> begin
>   result := Code;
> end;
>
> procedure TfrmTestGetSet.SetCode(Code: integer);
> begin
>   iCode := Code;
> end;
>
>

Your getCode references the property not the member variable so it will
recurse to stack death.

--
Matthew Jones
Thu, Feb 25 2016 8:43 PMPermanent Link

Trinione

<< Your getCode references the property not the member variable so it will recurse to stack death. >>

And that it was. Thank you very much. Most appreciated!

I have used both recommended solutions for various reasons already.
Previous PagePage 2 of 2
Jump to Page:  1 2
Image