Home > Back-end >  How to debug the Delphi access violation at address error
How to debug the Delphi access violation at address error

Time:09-27

Code has no problem
 
Var
Form1: TForm1;
S: a string;

Implementation

{$R *. DFM}

Procedure TForm1. Button1Click (Sender: TObject);//display user data
The begin
S:='select r1_F1 as "user" gonghaowu, r1_F2 as "user name", r1_F3 as "user password" from Rule_SysUsers_Info';
With query1 do
The begin
The close;
SQL. The Clear;
SQL. Add (s);
The open;
end;
end;
Procedure TForm1. Button2Click (Sender: TObject);//add user information
Var SQLSTR: string;
The begin
: SQLSTR="insert into Rule_SysUsers_Info (r1_F1 r1_F2, r1_F3) values (: : f1, f2, f3) ';
With query1 do
The begin
The close;
SQL. The Clear;
SQL. The Add (SQLSTR);
Params. Parambyname (' f1 '). The value:=edit1. Text;
Params. Parambyname (' f2 '). The value:=edit2. Text;
Params. Parambyname (' f3 '). The value:=edit3. Text;
Execsql;
end;
With query1 do
The begin
The close;
SQL. The Clear;
SQL. Add (s);
The open;
end;
end;
End.

CodePudding user response:

Params. Parambyname (' f1 '). The value:=edit1. Text;
Params. Parambyname (' f2 '). The value:=edit2. Text;
Params. Parambyname (' f3 '). The value:=edit3. Text;

Estimate the parameters is
These parameters need to add good static, not dynamic recognition, you add parameters in the design environment to do

Pay attention to when parameter is of type String

CodePudding user response:

Problems in the following code
: SQLSTR="insert into Rule_SysUsers_Info (r1_F1 r1_F2, r1_F3) values (: : f1, f2, f3) ';
.
SQL. The Add (SQLSTR);
You just increase the SQL statement to query of SQL, the runtime Delphi is not automatically create params item, and then you direct the item of params assignment
Params. Parambyname (' f1 '). The value:=edit1. Text;
Params. Parambyname (' f2 '). The value:=edit2. Text;
Params. Parambyname (' f3 '). The value:=edit3. Text;
Must be crossed,
To assign a value to a generated in the design of SQL statements, Delphi params automatically, can direct assignment,
Two, dynamically create, add three statements in your code
Params. CreateParam (ftString, 'f1' ptInput);
Params. CreateParam (ftString, 'f2', ptInput);
Params. CreateParam (ftString, 'f3, ptInput);
Params. Parambyname (' f1 '). The value:=edit1. Text;
Params. Parambyname (' f2 '). The value:=edit2. Text;
Params. Parambyname (' f3 '). The value:=edit3. Text;

CodePudding user response:

Tried, still have the mistake

CodePudding user response:

There is no test environment, suggest trying Tform1 closing, query1. Close;

CodePudding user response:

When debugging in Params. Parambyname (' f1 '). The value:=edit1. Text; Set a breakpoint to check the Params. Cout value and item,

CodePudding user response:

Want to clear, errors exactly where a line out of the building Lord
Still, after the generated EXE files, execute came out, or open in the IDE environment when the PROJECT is out?

Many times, always forget the QUERY in the IDE environment of the ACTIVE set to FALSE

Another possibility, the original poster is not the QUERY of the CONNECTION setup?

The original poster should clarify their own development environment conditions, this problem should be relatively, appear on your computer, on the other computer won't appear

CodePudding user response:

 

Procedure TForm1. Button2Click (Sender: TObject);//add user information
Var SQLSTR, s: a string;
The begin
S:='select r1_F1 as "user" gonghaowu, r1_F2 as "user name", r1_F3 as "user password" from Rule_SysUsers_Info';
: SQLSTR="insert into Rule_SysUsers_Info (r1_F1 r1_F2, r1_F3) values (' % s', '% s',' % s') '.
SQLSTR=Format (SQLSTR, [edit1 Text, edit1. Text, edit1. Text]);
With query1 do
The begin
The close;
SQL. The Clear;
SQL. The Add (SQLSTR);
Execsql;
end;
With query1 do
The begin
The close;
SQL. The Clear;
SQL. Add (s);
The open;
end;
end;

CodePudding user response:

Well, the parameter format to write wrong, should be
SQLSTR=Format (SQLSTR, [edit1 Text, edit2. Text, edit3. Text]);

CodePudding user response:

This kind of mistake is not Create in object, and then references are out, the landlord to check

CodePudding user response:

Learn
  • Related