Possible Duplicate:
Reference object instance created using “with” in Delphi
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.
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;
Is it also possible to do this in a WITH statement where your Create object in contained in the WITH statement?
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;
Can I pass this dynamic object to a function like `funcDisplayDataSet(TQuery)?
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.*