Results 1 to 4 of 4

Thread: Need a little help with properties and classes.

  1. #1

    Need a little help with properties and classes.

    Im toying around a little with delphi, and Im trying to make a board game.
    It's a game of go 19x19.

    I works fine and do all the stuff I want it to do etx. But I want to use a more OOP approach. So I make my a class called TGoban. (a go-board is called goban fyi)

    It contains a "private" 2-dimensional array called matrix. And here is the problem. I want it to be a property, but everytime I try to change a value in my matrix it gives me stack overflow. I use a prpperty write function addStone(x,y, stone) which also is a member of TGoban of course, so I dont think its because access errors.

    If I make TGoban.matrix public, then this works:
    mygoban.matrix[6,3] := 3;
    but this still doesnt:
    addStone(x,y, stone); //stack overflow

    (addStone(x,y,stone) basicly does this: matrix[x,y] := stone; )

    It loses its whole purpouse with properties if I make it public.This just confuses me alot, so I thought you guys might have an idea of what Im doing wrong.

    Im in school now, so I have no source atm. So if someone doesn't see any fundamental errors. I'll just bring some source in a day or two.

    Thanks for any help.
    This signature has been ripped from someone else. Im not imaginative nor skillful enough to come up with something like this on my own.

  2. #2

    Need a little help with properties and classes.

    [pascal] type
    TTest = class
    private
    FBoard: array[0..7, 0..7] of Integer;
    function GetValue(Row, Col: Integer): Integer;
    procedure SetValue(Row, Col, NewValue: Integer);
    public
    property Board[Row, Col: Integer]: Integer read GetValue write SetValue; default;
    end;

    //...

    function TTest.GetValue(Row, Col: Integer): Integer;
    begin
    Result := FBoard[row, col];
    end;

    procedure TTest.SetValue(Row, Col, NewValue: Integer);
    begin
    FBoard[row, col] := NewValue;
    end;[/pascal]
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    Need a little help with properties and classes.

    Probably the reason that you got a stack overflow was because you were reading/writing the property in the property read/write method, instead of the field, so it would keep on calling itself until it ran out of stack.
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  4. #4

    Need a little help with properties and classes.

    ohhh!! Now I get it! Thanks! :)
    This signature has been ripped from someone else. Im not imaginative nor skillful enough to come up with something like this on my own.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •