title: How do you get a reference to a TQuery object created in a WITH statement?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/791181/reference-object-instance-created-using-with-in-delphi">Reference object instance created using &ldquo;with&rdquo; in Delphi</a>  </p>
  </blockquote>
  
  
  
  <p>One method that I use to create query objects in Delphi follows the first code sample.  It gives me a reference to the object and I can then pass the object to a function.</p>
  
  <pre><code>procedure SomeProcedure;
  var
    qry: TQuery;
  begin
    qry := TQuery.Create(nil);
  
    with qry do
    begin
      Connection := MyConn;
      SQL.Text := 'SELECT * FROM PEOPLE';
      Open;
  
      funcDisplayDataSet(qry);
      Free;
    end;
  
  end;
  </code></pre>
  
  <p>Is it also possible to do this in a WITH statement where your Create object in contained in the WITH statement?</p>
  
  <pre><code>procedure SomeProcedure;
  begin
    with TQuery.Create(nil) do
    begin
      Connection := MyConn;
      SQL.Text := 'SELECT * FROM PEOPLE';
      Open;
  
      funcDisplayDataSet( ??? );  // Here I'm unsure how to pass the object created...
      Free;
    end;
  end;
  </code></pre>
  
  <p>Can I pass this dynamic object to a function like `funcDisplayDataSet(TQuery)?  </p>
  
  <blockquote>
    <p>I just would like to know if this is possible.  I'm not looking for a
    summary on why the WITH statement is bad or good.  There are other
    posts on StackOver flow with that discussion.*</p>
  </blockquote>