Null pointer Exception in Pascal Script for Delphi in 64-bit

testcase.7z (6.7 KB)

Please download it from this page; you cannot do it by email. I’ve been experimenting with many scenarios, including

  1. The script that is loaded from a file wouldn’t compile when I tried to.
  2. It compiles when the identical piece of code is provided as an inline string.

Hi,

I can’t reproduce any failure in win64 mode:

Hi,

Many thanks for your assistance and for your prompt reply. Both the 32-bit and 64-bit versions had the issues with the function fixed.

2 Likes

Hi,

I’m experiencing an access violation for the same issue—a function returning a string—but this time, the function is producing a SQL query.

Does this require additional changes other than existing ones?

Hi,

Can you attach testcase that reproduced this AV, pls?

Hi,

Am just providing an outline of what exactly causing the AV.
testcase.7z (7.5 KB)

Hi,

can you use only std Delphi components, pls?
can you show call-stack, pls?

Hi,

Am facing problem when using SQL components. A normal Delphi function which returns string didn’t resulted in AV. Am attaching the call stack as requested.



Hi,

what exactly causes AV?
Self parameter is nil ?
better to rename Self parameter with something else like aQuery.

Hi,

I tried all the possible ways and finally when i changed the return value of the function GetQueryText to integer , then the self parameter has value i.e., not nil and no AV.

Hi,

your testcase seems incomplete, for example, you have FSQLConnection variable in login-pre.pas, but it isn’t initialized at all. it also can be a reason for failure …

can you use standard ADO/FireDAC/IBX/DBX/etc db components and create full qualified testcase that will show that PS works incorrectly, pls?

I just gave the outline for understanding, not the project am working with. In my project everything was initialized and perfect.
There was one more function returns Boolean which uses SQL, in that function i can see the self attribute contains all the stuff i.e., not null.

hi,

Attaching sample code.
testcase.7z (7.6 KB)

Hi,

you have AV here:

  CL: TPSRuntimeClassImporter;
..
  with CL.Add(TSQLQuery) do //<<<<<<<< cl = nil here
  begin
    RegisterConstructor(@TSQLQuery.Create, 'Create');
    RegisterMethod(@TSQLQueryGetQueryText, 'GetQueryText');

  end;

also update code as

  // Compiler.
  if not Compiler.Compile(script) then
  // Compile the Pascal script into bytecode.
  begin
// <------------- begin block 
    s := '';                                                   
    for I := 0 to Compiler.MsgCount - 1 do
      s := s+sLineBreak+Compiler.Msg[i].MessageToString;
    showMessage(s);
// <-------------- end block
    Compiler.Free;
    // Compiler.
    // You could raise an exception here.
    Exit;
  end;

it will show errors with PS code inside login-pre.pas

Am not getting AV at compiling script … It’s at Execute script.



image

Hi,

have you tested your testcase before uploading?

I have TSQLQuery.Create error …


can you create worked testcase that illustrates AV inside your login-pre.pas?

you can drop email to support@ for keeping privacy

I am unable to send you my functioning code since it involves certain sensitive information, without which I am unable to provide you with a complete working sample. You can see that there is a function in my previous example: AV is provided by the function TSQLQueryGetQueryText(Self: TSQLQuery): String, which returns a string. I don’t have AV if the identical method returns an integer.

Hi,

you have

function TSQLQueryGetQueryText(Self: TSQLQuery): String;
var
  i: Integer;
  s: string;
begin
  Result := Self.SQL.Text;
  s := Result;
end;

and

procedure login_Pre_0;
var
  s: string;
  Q: TSQLQuery;
begin
  Q := TSQLQuery.Create(nil);
  Q.SQLConnection := FSQLConnection;
  Q.SQL.Add('select * from temp_table');
  s := Q.GetQueryText;
end;

so you want to return 'select * from temp_table', is it correct ?

I don’t see any certain sensitive information here …

Yeah, I want to return sql.text. In the provided example , there is no sensitive info., but in order to provide you the working example then the problem arise.