0

I'm trying to connect to my postgresql database using Lazarus pascal. I get this error towards the end of compilation (F9).

mainform.pas(112,35) Error: Wrong number of parameters specified for call to "Create"

Here's my code:

  dbConn:= TSQLConnection.Create(nil);    
  dbConn.HostName := '<IP goes here>';    
  dbConn.DatabaseName:= 'dbMydb';    
  dbconn.UserName:='me';    
  dbConn.Password:='pas';    
  dbConn.Open;

  //Bind the Transaction AND Query components to the DB connection

  dbQuery_Menu := TSQLQuery.Create; //This is the line with the error    
  dbQuery_Menu.Database := dbConn;    
  dbQuery_Menu.Transaction := dbTrans ;

I'm really exhausted trying to figure this out... Any help please...

The above code was adapted from here.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
itsols
  • 5,406
  • 7
  • 51
  • 95
  • For those who bump into the same issue or would like to fix this, here's the code: http://pastebin.com/RSBkusDM – itsols Oct 31 '12 at 03:52

1 Answers1

2

It seems which the documentation is outdated, the TSQLQuery descends from the TCustomSQLQuery class where the constructor is defined like

 constructor Create(AOwner : TComponent); override; 

So you need to modify your code like this

dbQuery_Menu :=TSQLQuery.Create(nil); 
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Thank you for your time. Unfortunately, I get the **same** error. Thinking it could be a permissions thing, I even tried this: `dbQuery_Menu.SQL.Text:= 'Select 5+6 as Ans';` but the result is the same. Even tried putting `nil` into all the creates (connection, transaction and query) but nothing seems to change. I'm starting to think it's a bug with Lazarus. – itsols Oct 31 '12 at 03:40
  • Are you tell me which you are getting the same error `Wrong number of parameters specified for call to "Create"` after of modify the code with me suggested code? – RRUZ Oct 31 '12 at 04:00
  • Oh no, I'm so sorry for any cofusion... The past few days has been hectic and I've got more lost than ever before... I'm able to run it like you said either putting `nil` or the name of a component on the form. But now it crashes when the query opens. – itsols Oct 31 '12 at 04:11
  • Sorry about that confusion... For this question, I accept your answer. But I just can't get the code to open the query. BTW, am doing it all through code - not using the components on the top tab. – itsols Oct 31 '12 at 04:12
  • here is the other question - it's where the program crashes when the query is being opened. http://stackoverflow.com/questions/13138271/lazarus-free-pascal-delphi-runerror-211#comment17873017_13138271 – itsols Oct 31 '12 at 04:16