How do i return an object from a function in Delphi without causing Access Violation?

后端 未结 10 1449
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 14:54

I have a delphi function that returns a TStringList, but when I return a value and try to use it I get a Access Violation Error i.e

myStringList := FuncStringLis         


        
10条回答
  •  耶瑟儿~
    2021-02-13 15:22

    Don't free the object before you are done invoking the methods on it. You are currently invoking the Count method on a destroyed object, hence the error.

    Why don't you create the string list in the calling function instead, and pass its reference to the method that fills it? Or make the string list a member of a class, and free it when you free the class that owns it?

提交回复
热议问题