Forum > Databases

[Solved] SQLite | GetTableNames desnt work

(1/2) > >>

cpalx:
hello, i use
TSQLite3Connection
and i need The tebles names, so i use

TSQLite3Connection.GetTableNames(a Tstrings)

and i get a memory error

any idea?

molly:

--- Quote from: cpalx on February 14, 2018, 07:31:28 pm ---any idea?

--- End quote ---
without any code and exact error message ?, no idea.

In that case your guess is as good as mine....

Shot in the dark: you did not create your stringlist before passing it along to method GetTableNames...

cpalx:
================

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- SQLiteConn:= TSQLite3Connection.Create( nil );  Query:= TSQLQuery.Create( nil );  SQLiteTran:= TSQLTransaction.Create( nil );  SQLiteConn.Transaction:= SQLiteTran;  Query.Transaction:= SQLiteTran;  SQLiteTran.Action:= caCommitRetaining;  Query.DataBase:= SQLiteConn;  Error:= EmptyStr;   if DataBaseName = DBName then     DataBaseName:= ExtractFilePath( ParamStr( 0 ) ) + DBName ;   SQLiteConn.DatabaseName:= DataBaseName ;   try     SQLiteConn.Connected:= True;     Self.Connected:= SQLiteConn.Connected;   except on E: Exception do begin     Error:= E.ClassName + LineEnding + E.Message;     Self.Connected:= False;  end;  end;                            ================


================

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TSQLiteCache.GetTableNames( var List: Tstrings; ShowSystemTables: Boolean = False ): Boolean;begin   try   SQLiteConn.GetTableNames( List, ShowSystemTables );   result:= true  except on E: Exception do begin     Error:= E.ClassName + LineEnding + E.Message;     Result:= False;  end;  end;end;    ================

and i call:
==============

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var ListTableName: Tstrings;begin   ListTableName:= TStrings.Create;   if not  Cache.GetTableNames( ListTableName ) then      ShowMessage( Cache.Error );   ==============


And display error:
==============
EAbstractError
Abstract method called
==============

molly:

--- Quote from: cpalx on February 15, 2018, 03:06:43 am ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var ListTableName: Tstrings;begin   ListTableName:= TStrings.Create;   if not  Cache.GetTableNames( ListTableName ) then      ShowMessage( Cache.Error );   ==============


And display error:
==============
EAbstractError
Abstract method called
==============

--- End quote ---

Don't create directly from TStrings It is an abstract class. The warnings during compilation should have given you that hint.


--- Quote ---... Warning: Constructing a class "TStrings" with abstract method "Get"
... Warning: Constructing a class "TStrings" with abstract method "GetCount"
... Warning: Constructing a class "TStrings" with abstract method "Clear"
... Warning: Constructing a class "TStrings" with abstract method "Delete"
... Warning: Constructing a class "TStrings" with abstract method "Insert"

--- End quote ---

use:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var ListTableName: TstringList;begin   ListTableName:= TStringList.Create;   if not  Cache.GetTableNames( ListTableName ) then      ShowMessage( Cache.Error );   
more information. TStrings:

--- Quote ---TStrings implements an abstract class to manage an array of strings. It introduces methods to set and retrieve strings in the array, searching for a particular string, concatenating the strings and so on. It also allows an arbitrary object to be associated with each string.

It also introduces methods to manage a series of name=value settings, as found in many configuration files.

An instance of TStrings is never created directly, instead a descendant class such as TStringList should be created. This is because TStrings is an abstract class which does not implement all methods; TStrings also doesn't store any strings, this is the functionality introduced in descendants such as TStringList.

--- End quote ---

cpalx:
Thanks Molly, problem solved

Navigation

[0] Message Index

[#] Next page

Go to full version