My application give me the error "Access violation at address 00511050 in module 'app.exe'. Read of address 000001AA" when I execute the following code:
Oracle Package
--------------
1 CREATE OR REPLACE PACKAGE my_package
2 AS
3 TYPE ref_cursor IS REF CURSOR;
4
5 FUNCTION my_resultset RETURN ref_cursor;
6 END my_package;
7
8 CREATE OR REPLACE PACKAGE BODY my_package AS
9 FUNCTION my_function
10 RETURN ref_cursor IS
11 my_cursor ref_cursor;
12 BEGIN
13 OPEN my_cursor FOR
14 SELECT field1, field2, field3
15 FROM ATable;
16
17 RETURN my_cursor;
18 END;
19 END my_package;
Delphi Code
-----------
1 procedure TMainForm.PopulateGrid;
2 var
3 Query: TOracleQuery;
4 Cursor: TOracleQuery;
5 begin
6 try
7 Query := TOracleQuery.Create(Application);
8 Cursor := TOracleQuery.Create(Application);
9
10 Query.Session := OracleSession;
11
12 Query.SQL.Add('begin');
13 Query.SQL.Add(' :result := my_package.my_function;');
14 Query.SQL.Add('end;');
15
16 Query.DeleteVariables;
17
18 Query.DeclareVariable('result', otCursor);
19 Query.SetComplexVariable('result', Cursor);
20
21 Query.Execute;
22 Cursor.Execute;
23
24 while not Cursor.Eof do
25 Do something...
26
27 if Assigned(Query) then
28 FreeAndNil(Query);
29
30 if Assigned(Cursor) then
31 FreeAndNil(Cursor);
32 except
33 On E:Exception do
34 begin
35 if Assigned(Query) then
36 FreeAndNil(Query);
37
38 if Assigned(Cursor) then
39 FreeAndNil(Cursor);
40
41 raise Exception.Create('(!' + Self.ClassName + '.PopulateGrid) - ' + #13#10 +
42 E.Message);
43 end;
44 end;
45 end;
When the delphi code hits line 21, I get the error. I have stepped through and made sure that all variables are set correctly (the session is valid), etc.
When I ran the same query using a Data bound TOracleDataSet everything worked fine.
I am running Delphi 6, DOA 3.4.6 on Windows XP (SP1) against Oracle 9i, Release 9.2.0.4.0
Any ideas ?
Regards,
Farzad Battiwalla
Snr. Developer
Retail Solutions LLC
[This message has been edited by farzadb (edited 17 October 2003).]
Oracle Package
--------------
1 CREATE OR REPLACE PACKAGE my_package
2 AS
3 TYPE ref_cursor IS REF CURSOR;
4
5 FUNCTION my_resultset RETURN ref_cursor;
6 END my_package;
7
8 CREATE OR REPLACE PACKAGE BODY my_package AS
9 FUNCTION my_function
10 RETURN ref_cursor IS
11 my_cursor ref_cursor;
12 BEGIN
13 OPEN my_cursor FOR
14 SELECT field1, field2, field3
15 FROM ATable;
16
17 RETURN my_cursor;
18 END;
19 END my_package;
Delphi Code
-----------
1 procedure TMainForm.PopulateGrid;
2 var
3 Query: TOracleQuery;
4 Cursor: TOracleQuery;
5 begin
6 try
7 Query := TOracleQuery.Create(Application);
8 Cursor := TOracleQuery.Create(Application);
9
10 Query.Session := OracleSession;
11
12 Query.SQL.Add('begin');
13 Query.SQL.Add(' :result := my_package.my_function;');
14 Query.SQL.Add('end;');
15
16 Query.DeleteVariables;
17
18 Query.DeclareVariable('result', otCursor);
19 Query.SetComplexVariable('result', Cursor);
20
21 Query.Execute;
22 Cursor.Execute;
23
24 while not Cursor.Eof do
25 Do something...
26
27 if Assigned(Query) then
28 FreeAndNil(Query);
29
30 if Assigned(Cursor) then
31 FreeAndNil(Cursor);
32 except
33 On E:Exception do
34 begin
35 if Assigned(Query) then
36 FreeAndNil(Query);
37
38 if Assigned(Cursor) then
39 FreeAndNil(Cursor);
40
41 raise Exception.Create('(!' + Self.ClassName + '.PopulateGrid) - ' + #13#10 +
42 E.Message);
43 end;
44 end;
45 end;
When the delphi code hits line 21, I get the error. I have stepped through and made sure that all variables are set correctly (the session is valid), etc.
When I ran the same query using a Data bound TOracleDataSet everything worked fine.
I am running Delphi 6, DOA 3.4.6 on Windows XP (SP1) against Oracle 9i, Release 9.2.0.4.0
Any ideas ?
Regards,
Farzad Battiwalla
Snr. Developer
Retail Solutions LLC
[This message has been edited by farzadb (edited 17 October 2003).]