Recent

Author Topic: DBAccess.Create not working  (Read 3691 times)

Milsa

  • Sr. Member
  • ****
  • Posts: 328
DBAccess.Create not working
« on: October 03, 2013, 07:34:24 pm »
What's wrong? TFormMain.FormCreate calls DBAccess.Create but it's not working. Constructor will finish on begin command.
I work with Lazarus 4.0, FPC 3.2.2, date 2025-05-03
This information is actual to: 3rd Aug 2025

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: DBAccess.Create not working
« Reply #1 on: October 03, 2013, 08:45:05 pm »
You are not instantiating your classes correctly. In form_main, instead of
Code: [Select]
DBAccess.Create(Self);
you should have
Code: [Select]
DBAccess:=TDBAccess.Create(Self);
Likewise in class_db_access in place of
Code: [Select]
SQLite3Connection.Create(AOwner);
you should have
Code: [Select]
SQLite3Connection:= TSQLite3Connection.Create(AOwner);
The same applies to your 'creation' of SQLTransaction.
You've also omitted to call the inherited Create constructor in TDBAccess.Create. The first line of TDBAccess.Create after begin should be
Code: [Select]
inherited Create;
I also recommend you change the declaration of DBAccess to
Code: [Select]
var DBAccess: TDBAccess=nil;
It is never be wrong to initialise a variable, and with pointer variables especially, it can often save your bacon when you realise you've got an unexpected nil value somewhere later in the program.
« Last Edit: October 03, 2013, 08:46:39 pm by howardpc »

Milsa

  • Sr. Member
  • ****
  • Posts: 328
Re: DBAccess.Create not working
« Reply #2 on: October 03, 2013, 09:10:43 pm »
Code: [Select]
DBAccess.Create(Self);This is correct Lazarus syntax (not Delphi).
I work with Lazarus 4.0, FPC 3.2.2, date 2025-05-03
This information is actual to: 3rd Aug 2025

Milsa

  • Sr. Member
  • ****
  • Posts: 328
Re: DBAccess.Create not working
« Reply #3 on: October 03, 2013, 09:22:56 pm »
Thank you. it works.

I've read that this syntax is correct but it's not working correctlly.
Code: [Select]
SQLite3Connection.Create(AOwner);It is reportedly same that:
Code: [Select]
SQLite3Connection := TSQLite3Connection.Create(AOwner);
« Last Edit: October 03, 2013, 09:47:24 pm by Milsa »
I work with Lazarus 4.0, FPC 3.2.2, date 2025-05-03
This information is actual to: 3rd Aug 2025

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: DBAccess.Create not working
« Reply #4 on: October 04, 2013, 02:08:57 am »
Code: [Select]
DBAccess.Create(Self);This is correct Lazarus syntax (not Delphi).
It is only 'correct' in the sense that it happens to compile without errors (unfortunately). It is incorrect in that it does not do what is needed, namely instantiate a new instance of the TDBAccess class.
As you have coded it, DBAccess is a global variable, and so will be set to nil by compiler code during initialization. Thereafter
Code: [Select]
DBAccess.Create(Self);
is in fact
Code: [Select]
nil.Create(Self);
Unsurprisingly this causes a SIGSEGV.

 

TinyPortal © 2005-2018