share procedures and function with a postgresql connection lazarus / 16-Databases ---------------------------------------------------------------------- aviatorz · 2012-11-28 18:55 i am trying to make a class with only procedures and functions, some procedures need use a postgresql connection, for example. Code: [Select]... class var       {Variables de clases}       SQLquery:TSQLQuery;       Datasource:TDataSource;       Transaccion:TSQLTransaction;       PQConexion:TPQConnection;  ... class procedure StaticData.Inicializa_conexion(usuario,contrasena,host,db:string); begin      PQConexion.hostname:=host;      PQConexion.databaseName:=db;      PQConexion.username:=usuario;      PQConexion.password:=contrasena;      PQConexion.transaction:= Transaccion;      Transaccion.DataBase:=PQConexion;      SQLQuery.Transaction:=Transaccion;      Datasource.DataSet:=SQLQuery;      try         PQConexion.connected:=true;         Application.MessageBox(PChar('Conexion realizada con exito'),PChar('Conexion'),MB_ICONINFORMATION);      except        on e:exception do        begin          Application.MessageBox(PChar('Ha ocurrido el siguiente Error: '+e.Message),PChar('Error'),MB_ICONINFORMATION);          PQConexion.connected:=false;        end;      end; end; The problem is when i try to set a property of PQConexion, i see this error. Code: [Select]El proyecto X ha lanzado una excepcion de la clase 'External:SIGSEGV'. en direccion 403AD0 The error is when i try to put a value to a property of PQConexion Code: [Select]PQConexion.hostname:=host; ---------------------------------------------------------------------- Blaazen · 2012-11-28 18:59 Hello, Where do you call constructor ? Code: [Select]PQConexion:=TPQConnection.Create; ---------------------------------------------------------------------- aviatorz · 2012-11-28 19:05 Quote from: Blaazen on November 28, 2012, 07:59:56 pmHello, Where do you call constructor ? Code: [Select]PQConexion:=TPQConnection.Create; I tried that and i got Code: [Select]staticclase.pas(36,38) Error: Wrong number of parameters specified for call to "Create" staticclase.pas(68) Fatal: There were 1 errors compiling module, stopping But i put Code: [Select]PQConexion:=TPQConnection.Create(Application); and now the problem is solved, but is this correct? ---------------------------------------------------------------------- Blaazen · 2012-11-28 19:13 You have to call constructor before you use the PQConnection. No matter if it is global, local or class variable. In this case, good place can be initialization section. If it works then it's correct.