title: Access violation in Lazarus
body: <p>I've been doing my university project and I've stumbled upon problem I cannot solve.
  After declaring variable (a pointer to TButton) I cannot use it. I'll copy a part of my code to help show the problem.</p>
  
  <p>So before the implementation I have</p>
  
  <pre><code>private
      prevButton : ^TButton;
  </code></pre>
  
  <p>After that I use OnClick procedure with my buttons</p>
  
  <pre><code>procedure TForm2.MissingButtonClick(Sender : TObject);
  var
      b : TButton;
  begin
       b := Sender as TButton;
       prevButton := @b;
       showmessage(prevButton^.Caption);
  end; 
  </code></pre>
  
  <p>And caption is shown no problem. But then when I use my OnClick procedure and try to change labels caption I get access violation.</p>
  
  <pre><code>procedure TForm2.LabelClick(Sender : TObject);
  var
      l : TLabel;
  begin
       l := Sender as TLabel;
       if prevButton = nil then
          showmessage('nil');
       if prevButton &lt;&gt; nil then begin
          showmessage(prevButton^.Caption);
          l.Caption := (prevButton^.Caption);
          prevButton^.OnClick := @AlreadyClicked;
          prevButton^.Free;
          prevButton^ := nil;
          prevButton := nil;
          refreshLabels(words);
       end;
  end;
  </code></pre>
  
  <p>So here is the question, why can't I use my variable in this procedure if I could use it without problem second earlier in other procedure.</p>
  
  <p>Cheers.</p>