Page 1 of 1

TOraQuery and TOraSession

Posted: Tue 10 Jun 2008 13:11
by oppofix
Hi everybody,
I have a TOraSession inside a dataModule
called DM1.DataModule1.odacSession; in many functions
i need to realize some SELECT, using for this aim
some TOraQuery objects.
I don't want to create in the module DM1.DataModule1
many TOraQuery objects, above all because
i need to use them in many private functions,
so the objects would be too many.

But if i try to open a TOraQuery object in a function
implementation, the result is an error telling me
that there is a Write Memory Error.
I do as follows:

Function XYZ(...): integer;

var
odacQuery1: TOraQuery;

begin

odacQuery1.Session:= DM1.DataModule1.odacSession
...
...

end;

What am i doing wrong?
Thanks for any answers.
Fabrizio De Pietri

Posted: Wed 11 Jun 2008 07:13
by Plash
You should call constructor of TOraQuery - Create before you use TOraQuery object, and you should call Free method after you finish work with TOraQuery object.

Code: Select all

Function XYZ(...): integer; 
var 
  odacQuery1: TOraQuery; 
begin 
  odacQuery1 := TOraQuery.Create(nil);
  try
    odacQuery1.Session:= DM1.DataModule1.odacSession 
    odacQuery1.SQL.Add('select 1 from dual');
    odacQuery1.Open;
    ...
    odacQuery1.Close;
  finally
    odacQuery1.Free;
  end;
end;