SQLite Connection Errors lazarus / 16-Databases ---------------------------------------------------------------------- SteveF · 2009-04-06 20:04 I'm running into a problem in my continuing quest to figure out how Lazarus & Free Pascal work.  I've used & modified a tutorial for SQLite datasets posted here: http://www.geocities.com/camara_luiz/docs/dataset/dataset- tutorial-03.html My modifications work just fine as long as I leave the code that establishes the connection to the SQLite data file in the FormCreate event, as in the original tutorial.  As soon as the code is moved out of the FormCreate event, I start getting the following compiler errors: fmain.pas(80,16) Error: Identifier not found "NamesDS" fmain.pas(80,16) Error: Expression type must be class or record type fmain.pas(82,13) Error: Identifier not found "FileName" fmain.pas(83,14) Error: Identifier not found "TableName" fmain.pas(84,23) Error: Identifier not found "TableExists" fmain.pas(86,14) Error: Identifier not found "FieldDefs" fmain.pas(87,14) Error: Identifier not found "FieldDefs" fmain.pas(88,14) Error: Identifier not found "FieldDefs" fmain.pas(89,14) Error: Identifier not found "FieldDefs" fmain.pas(90,16) Error: Identifier not found "CreateTable" fmain.pas(92,8) Error: Identifier not found "SQL" fmain.pas(93,8) Error: Identifier not found "Open" the same set of errors is repeated for each dataset in the application.  Even something as simple as moving the code to its own procedure, and calling that procedure from the FormCreate event generates these errors. The ultimate goal here is to allow the hypothetical user to select the name and location of the SQLite data file used by the application.  As long as the link must be done in the FormCreate event, I don't see how that can happen. What needs to be done to get this to work?  Relevant code follows. SteveF procedure LinkToFile; begin                //setup link to data file  ForceDirectories(GetAppConfigDir(False));   With NamesDS do   begin    FileName := IncludeTrailingPathDelimiter(GetAppConfigDir(False)) + 'addressbook.db';    TableName := 'Names';    if not TableExists then    begin     FieldDefs.Clear;     FieldDefs.Add('NameID',ftAutoInc);     FieldDefs.Add('Fname',ftString);     FieldDefs.Add('Lname',ftString);     CreateTable;    end;    SQL := 'SELECT * FROM Names ORDER BY Lname, Fname';    Open;   end;   With AddrDS do   begin    FileName := IncludeTrailingPathDelimiter(GetAppConfigDir(False)) + 'addressbook.db';    TableName := 'Addresses';    if not TableExists then    begin     FieldDefs.Clear;     FieldDefs.Add('AddrID',ftAutoInc);     FieldDefs.Add('NameID',ftInteger);     FieldDefs.Add('AddrType',ftString);     FieldDefs.Add('Company',ftString);     FieldDefs.Add('Address',ftString);     FieldDefs.Add('Town',ftString);     FieldDefs.Add('State',ftString);     FieldDefs.Add('ZIP',ftString);     FieldDefs.Add('Nation',ftString);     CreateTable;    end;    Open;   end;   With PhonesDS do   begin    FileName := IncludeTrailingPathDelimiter(GetAppConfigDir(False)) + 'addressbook.db';    TableName := 'Phones';    if not TableExists then    begin     FieldDefs.Clear;     FieldDefs.Add('PhoneID',ftAutoInc);     FieldDefs.Add('NameID',ftInteger);     FieldDefs.Add('PhoneType',ftString);     FieldDefs.Add('Number',ftString);     CreateTable;    end;    Open;   end;   With wwwDS do   begin    FileName := IncludeTrailingPathDelimiter(GetAppConfigDir(False)) + 'addressbook.db';    TableName := 'WWW';    if not TableExists then    begin     FieldDefs.Clear;     FieldDefs.Add('wwwID',ftAutoInc);     FieldDefs.Add('NameID',ftInteger);     FieldDefs.Add('wwwType',ftString);     FieldDefs.Add('wwwData',ftString);     CreateTable;    end;    Open;   end; end; ---------------------------------------------------------------------- Vincent Snijders · 2009-04-07 07:36 Make LinkToFile a method of the form which contains the data access components. procedure TForm1.LinkToFile; Don't forget to add this method in the class declaration too. ---------------------------------------------------------------------- SteveF · 2009-04-13 20:16 Thanks, Vincent.  Your changes solved the problem.  I’m still learning about things here, and now I know to make sure that any procedures I write that are not events bound to a form or its controls do get bound to the form with which its being used.  After I made the change to the one procedure, I had some others which I added in the same manner, and they worked with no problems. Steve