title: delphi AV in the observer pattern with interfaces
body: <p>I would like to implement the observer pattern using Delphi.
  Here are an interface <code>ISubject</code> and a class <code>TWeatherData</code> that implements an observer.  </p>
  
  <pre><code>ISubject = interface
      procedure notifyObservers;
      procedure removeObserver(o: IObserver);
      procedure registerObserver(o: IObserver);
    end;
  
  TWeatherData = class(TInterfacedObject, ISubject)
    private
      observers: TList;
      FTemperature: Double;
      FHumidity: Double;
      FPressure: Double;
    public
      // ...
      procedure notifyObservers;
      procedure setMeasurements(ATemperature, AHumidity, APressure: Double);
    end;
  </code></pre>
  
  <p>I get an <em>Access Violation</em> about <em>read of address</em> when <code>TWeatherData.notifyObservers</code> executes</p>
  
  <pre><code>procedure TWeatherData.notifyObservers;
  var
    observer: ^IObserver;
  begin
    for observer in observers do
      observer.Update(FTemperature, FHumidity, FPressure); //oops -&gt; there raised AV.
  end;
  
  
  procedure TWeatherData.setMeasurements(ATemperature, AHumidity,
    APressure: Double);
  begin
    measurementsChanged; // and this one calls TWeatherData.notifyObservers;
  end;
  </code></pre>
  
  <p>The main program:</p>
  
  <pre><code>    weatherStation := TWeatherData.Create;
      currentConditionalDisplay := TCurrentConditionalDisplay.Create(weatherStation);
      weatherStation.setMeasurements(100.0, 58.0, 756.0); // a stack head of exception.
  </code></pre>