Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>Result</code> variable is not initialized by default. It doesn't automatically refer to some compiler-generated <code>TStringList</code> instance. You need to assign a value to <code>Result</code>. That means having a line like this somewhere in your code:</p> <pre><code>Result := ...; </code></pre> <p>An expression like <code>Result.X</code> is <em>reading</em> the value of <code>Result</code> in order to get a reference to its <code>X</code> member, so you need to have given <code>Result</code> a value already. <a href="https://stackoverflow.com/questions/977480/return-value-of-function-might-be-undefined/977505#977505">Larry's answer</a> demonstrates how to do that. It generates a <em>new</em> <code>TStringList</code> instance, so the caller of this function needs to call <code>Free</code> on that object sometime.</p> <p>But in a comment, you mention that you're using this function as a property accessor. It's inconvenient for callers to have to free objects every time they read a property, so your whole plan might be inappropriate. Since it looks like you're trying to expose the description text, you might want to consider this instead:</p> <pre><code>function TfPackagedItemEdit.GetRTFDescription: TStrings; begin Result := richDescription.Lines; end; </code></pre> <p>Notice first that I've changed the return type to <code>TStrings</code>, which is essentially the abstract base class of all kinds of string lists throughout the VCL. <code>TStringList</code> is one descendant, but <code>TRichEdit.Lines</code> doesn't use <code>TStringList</code>. Instead, it uses a specialized <code>TStrings</code> descendant that knows how to interact with the underlying rich edit control.</p> <p>Next, notice that I have not created any new objects. Instead, I have returned a reference directly to the control's <code>Lines</code> property. Users of your <code>RTFDescription</code> property no longer need to worry about freeing the object they get.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload