By default, the Result variable Result not initialized. It does not automatically refer to some instance of TStringList generated by the compiler. You need to set the value to Result . This means that there is such a line in your code:
Result := ...;
An expression of type Result.X reads the value of Result to get a reference to its member X , so you need to give the value of Result already. Larry's answer shows how to do this. It generates a new instance of TStringList , so the caller of this function needs to call Free on this object sometime.
But in the comment, you mention that you use this function as a means of accessing properties. It is inconvenient for callers to have free objects every time they read the property, so your whole plan may not be appropriate. Since it looks like you are trying to expose the description text, you might think about this:
function TfPackagedItemEdit.GetRTFDescription: TStrings; begin Result := richDescription.Lines; end;
First of all, note that I changed the return type to TStrings , which is essentially an abstract base class of all types of string lists in VCL. TStringList is one descendant, but TRichEdit.Lines does not use TStringList . Instead, it uses a specialized descendant of TStrings , which knows how to interact with the basic editing control.
Then note that I did not create any new objects. Instead, I returned the link directly to the Lines control. Users of your RTFDescription property no longer need to worry about freeing the object they receive.
source share