Call to AddObject give stack overflow

Hello,

I have a small demo object

TSum = class(TObject)
public
constructor Create;
published
function Add(a, b: Integer): Integer;
end;

which is added with AddObject

I run this script

var
Sum: TSum;
begin
Sum := TSum.Create;
ShowMessage(IntToStr(Sum.Add(5, 6)));
Sum.Free;
end.

It gives stack overflow in search for properties and methods. What is wrong?

Chris

Comments

  • edited 2:04AM
    1) you should add classes by AddClass, not AddObject.
    2) you can't use published method - you should define it by AddMethod (see the documentation how to do this).

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.