Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Access Violation on XE2, advice needed.
Mon, Jan 21 2013 11:35 PMPermanent Link

Mario Enríquez

Open Consult

Could somebody please share some advice on this snippet?

I'm getting an Access Violation when I run the following code...

function TsegDbUsuarios.GetUsuario(pId: string): TmkUsuario;
var
 usr: TmkUsuario;
begin
 qryGetUserInfo.SessionName := APP_SESSION; // <------------- AV Raised here....
 qryGetUserInfo.DatabaseName := APP_DB;

 qryGetUserInfo.Close;
 qryGetUserInfo.ParamByName('Username').Value := pId;
 qryGetUserInfo.Open;

 usr := TmkUsuario.Create;
 if not qryGetUserInfo.IsEmpty then
 begin
   usr.Usuario := Trim(qryGetUserInfo.FieldByName('Name').AsString);
   usr.Contrasena := qryGetUserInfo.FieldByName('Password').AsString;
   usr.Comentarios := qryGetUserInfo.FieldByName('Description').AsString;
   usr.EmpleadoAsignado := '';
   usr.EsAdministrador := EsAdministrador(pId);
 end;
 qryGetUserInfo.Close;

 Result := usr;
end;

qryGetUserInfo is defined this way...

 object qryGetUserInfo: TEDBQuery
   DatabaseName = 'DB'
   SessionName = 'AppSession'
   SQL.Strings = (
     'select Name, Password, Description'
     '   from Configuration.Users'
     '      where Name = :Username')
   Params = <
     item
       DataType = ftString
       Name = 'Username'
       ParamType = ptInput
     end>
   ReadOnly = True
   Left = 304
   Top = 16
 end

However, I have another TEDBQuery in the same TDataModule as is working as expected.

Does anybody had an idea of what is missing?

Development is done with Delphi XE2 (32bit App) on Win7 64Bits.

Regards,
Mario
Tue, Jan 22 2013 5:38 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Mario


Assuming APP_SESSION is a simple string the only thing that can be wrong is that qryGetUserInfo is not instantiated or has been freed. Looking at the code in edbcomps all the query will do when SessionName is set is unprepare itself so it doesn't matter if the session is there or not.

Have you put a breakpoint on that line of code and checked to see if the query is nil?

Roy Lambert [Team Elevate]
Tue, Jan 22 2013 5:43 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Mario,

Where are you calling GetUsuario from?
You are perhaps calling it before the qryGetUserInfo component has been
created ...

--
Fernando Dias
[Team Elevate]
Tue, Jan 22 2013 4:09 PMPermanent Link

Mario Enríquez

Open Consult

Yep, you're right, calling before it was created.... duh!

(Note to myself, Stop playing with fancy instanciation methods and focus more on actual work!)

Regards,
Mario

"Fernando Dias" wrote:

Mario,

Where are you calling GetUsuario from?
You are perhaps calling it before the qryGetUserInfo component has been
created ...

--
Fernando Dias
[Team Elevate]
Image