Autor Beitrag
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Di 21.12.10 16:10 
Also so(?):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  Stream: TResourceStream;
begin
  Stream := TResourceStream.Create(hInstance, 'Datei1', RT_RCDATA);  showmessage('Gefunden');  
  try
   Stream.SaveToFile(Tempverzeichnis);
  finally
   Stream.Free;
  end;
end;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 21.12.10 17:13 
Wenn in der Variablen Tempverzeichnis nicht nur dieses sondern auch der Dateiname drin ist, ja.

Dass TResourceStream auch SaveToFile hat, wusste ich gar nicht. Dann brauchst du natürlich keinen TFileStream.
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Di 21.12.10 17:57 
Vielen Dank!

Doch noch eine Frage:
Ich habe einen Komponente, die eine DLL benötigt. Also wird das Programm nicht gestartet, weil die DLL ja benötigt wird.
Wie schaff ich es, dass erst die DLL ins Tempverzeichnis kopiert wird und dann die Komponente aufgerufen wird?
Momentan kopier ich die DLL ins Tempverzeichnis vor dem Initialisieren der Appllication.

Was mach ich falsch?
delphi10
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 447
Erhaltene Danke: 2

W2K, XP, Vista64, Win7 64
RAD-Studio 2010
BeitragVerfasst: Di 21.12.10 18:21 
user profile iconLittleBen hat folgendes geschrieben Zum zitierten Posting springen:
Vielen Dank!

Doch noch eine Frage:
Ich habe einen Komponente, die eine DLL benötigt. Also wird das Programm nicht gestartet, weil die DLL ja benötigt wird.
Wie schaff ich es, dass erst die DLL ins Tempverzeichnis kopiert wird und dann die Komponente aufgerufen wird?
Momentan kopier ich die DLL ins Tempverzeichnis vor dem Initialisieren der Appllication.

Was mach ich falsch?


Schreib die Kopieranweisung in die *.DPR

_________________
Salus populi suprema lex esto
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Di 21.12.10 18:28 
Das meinte ich mit
Zitat:
Momentan kopier ich die DLL ins Tempverzeichnis vor dem Initialisieren der Appllication


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
program Project1;
       
uses
  Forms,
  Classes,
  Windows,
  SysUtils,
  Unit1 in 'Unit1.pas' {Form1};
         
{$R *.res}
{$R MyRes.res}
           
var Res: TResourceStream;
    t: string;
begin
 t:= SysUtils.GetEnvironmentVariable('temp');

 Res := TResourceStream.Create(hInstance, 'Datei1', RT_RCDATA);
            
 try
   Res.SavetoFile(t+'\DieDll');
 finally
  Res.Free;
 end;
            
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
delphi10
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 447
Erhaltene Danke: 2

W2K, XP, Vista64, Win7 64
RAD-Studio 2010
BeitragVerfasst: Di 21.12.10 19:04 
Verstehe ich jetzt nicht. Was soll daran falsch sein oder nicht funktionieren?

_________________
Salus populi suprema lex esto
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Di 21.12.10 19:36 
Ich auch nicht :D

Sobald ich die Komponente aus der "Uses" entferne funktioniert ja auch alles...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 21.12.10 19:59 
Wie schon früher erwähnt:
Die DLL muss danach dann dynamisch mit LoadLibrary geladen werden. Wenn das die Interface-Unit der DLL derzeit nicht macht, musst du das so umschreiben, dass es dynamisch geladen wird.

Es ist eben etwas Aufwand dabei, wenn du dich nicht an die Standards halten möchtest (DLL einfach normal mitliefern).
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Di 21.12.10 20:20 
Also in die *.dpr einfach noch dazu:
ausblenden Delphi-Quelltext
1:
LoadLibrary(PChar(t+'DieDLL'));					

???

@jaenicke: Ich habe vorhin auf deiner Seite "SJ Bubble Breaker Clone" runtergeladen. Du hast da so ein schönes Setup. Wie hast du das hinbekommen?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 21.12.10 20:24 
Naja, du musst die Funktionen aus der DLL schon auch noch laden. Also alles was bis jetzt statisch in der Interface-Unit steht, musst du auf dynamisches Laden umstellen.

Die Setups mache ich mit dem kostenlosen Open Source Tool InnoSetup:
www.jrsoftware.org/isinfo.php

Es gibt auch noch andere ähnliche Tools, aber für normale Projekte halte ich InnoSetup für das beste. Insbesondere weil es in Delphi geschrieben ist und man damit auch Pascal Skripte erstellen kann um eigenen Code während des Setups auszuführen. Meistens reicht für kleine Projekte aber auch die Standardfunktionalität.
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Di 21.12.10 20:31 
Naja, dann lass ich das mit den Ressourcen. Nachdem du mir so ein tolles Programm gegeben hast!! Vielen Danke!
TomasB
Hält's aus hier
Beiträge: 5

Win98SE
Delphi5 Standard
BeitragVerfasst: Mi 22.12.10 00:06 
Hallo,

zu diesem Thema hätte ich eine Frage: Sqlite wird normalerweise als DLL benutzt. Disqlite ist eine Sqlite-Variante für Delphi, bei der Sqlite direkt in der Exe landet. Wenn man Disqlite benutzt, hat man am Ende also nur eine einzige Exe, die selbständig lauffähig ist. Weiss jemand, wie der Autor von Disqlite das erreicht hat? Wie binde ich eine DLL, deren C-Quelltext ich habe, so in Delphi ein? Geht es auch ohne den Quelltext (und ohne PEbundle)? Das wäre ja die gesuchte Lösung für die ursprüngliche Frage.

Tomas
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Sa 08.10.11 13:17 
Nun möchte ich dieses Thema nochmal aufgreifen, da das dynamische Laden der sqlite3.dll ansteht. Wenn ich die DLL in das temporäre Verzeichnis speicher, was muss ich dann in der folgenden Unit tun, um die DLL von dort zu laden.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
unit SQLite3;

{
  Simplified interface for SQLite.
  Updated for Sqlite 3 by Tim Anderson (tim@itwriting.com)
  Note: NOT COMPLETE for version 3, just minimal functionality
  Adapted from file created by Pablo Pissanetzky (pablo@myhtpc.net)
  which was based on SQLite.pas by Ben Hochstrasser (bhoc@surfeu.ch)
}


{$IFDEF FPC}
  {$MODE DELPHI}
  {$H+}            (* use AnsiString *)
  {$PACKENUM 4}    (* use 4-byte enums *)
  {$PACKRECORDS C} (* C/C++-compatible record packing *)
{$ELSE}
  {$MINENUMSIZE 4} (* use 4-byte enums *)
{$ENDIF}

interface

const
{$IF Defined(MSWINDOWS)}
  SQLiteDLL = 'sqlite3.dll';  // Hier muss das irgendwie hin (oder?)
{$ELSEIF Defined(DARWIN)}
  SQLiteDLL = 'libsqlite3.dylib';
  {$linklib libsqlite3}
{$ELSEIF Defined(UNIX)}
  SQLiteDLL = 'sqlite3.so';
{$IFEND}

// Return values for sqlite3_exec() and sqlite3_step()

const
  SQLITE_OK          =  0// Successful result
  (* beginning-of-error-codes *)
  SQLITE_ERROR       =  1// SQL error or missing database
  SQLITE_INTERNAL    =  2// An internal logic error in SQLite
  SQLITE_PERM        =  3// Access permission denied
  SQLITE_ABORT       =  4// Callback routine requested an abort
  SQLITE_BUSY        =  5// The database file is locked
  SQLITE_LOCKED      =  6// A table in the database is locked
  SQLITE_NOMEM       =  7// A malloc() failed
  SQLITE_READONLY    =  8// Attempt to write a readonly database
  SQLITE_INTERRUPT   =  9// Operation terminated by sqlite3_interrupt()
  SQLITE_IOERR       = 10// Some kind of disk I/O error occurred
  SQLITE_CORRUPT     = 11// The database disk image is malformed
  SQLITE_NOTFOUND    = 12// (Internal Only) Table or record not found
  SQLITE_FULL        = 13// Insertion failed because database is full
  SQLITE_CANTOPEN    = 14// Unable to open the database file
  SQLITE_PROTOCOL    = 15// Database lock protocol error
  SQLITE_EMPTY       = 16// Database is empty
  SQLITE_SCHEMA      = 17// The database schema changed
  SQLITE_TOOBIG      = 18// Too much data for one row of a table
  SQLITE_CONSTRAINT  = 19// Abort due to contraint violation
  SQLITE_MISMATCH    = 20// Data type mismatch
  SQLITE_MISUSE      = 21// Library used incorrectly
  SQLITE_NOLFS       = 22// Uses OS features not supported on host
  SQLITE_AUTH        = 23// Authorization denied
  SQLITE_FORMAT      = 24// Auxiliary database format error
  SQLITE_RANGE       = 25// 2nd parameter to sqlite3_bind out of range
  SQLITE_NOTADB      = 26// File opened that is not a database file
  SQLITE_ROW         = 100// sqlite3_step() has another row ready
  SQLITE_DONE        = 101// sqlite3_step() has finished executing

  SQLITE_INTEGER = 1;
  SQLITE_FLOAT   = 2;
  SQLITE_TEXT    = 3;
  SQLITE_BLOB    = 4;
  SQLITE_NULL    = 5;

  SQLITE_UTF8     = 1;
  SQLITE_UTF16    = 2;
  SQLITE_UTF16BE  = 3;
  SQLITE_UTF16LE  = 4;
  SQLITE_ANY      = 5;

  SQLITE_STATIC    {: TSQLite3Destructor} = Pointer(0);
  SQLITE_TRANSIENT {: TSQLite3Destructor} = Pointer(-1);

type
  TSQLiteDB = Pointer;
  TSQLiteResult = ^PAnsiChar;
  TSQLiteStmt = Pointer;

type
  PPAnsiCharArray = ^TPAnsiCharArray; 
  TPAnsiCharArray = array[0 .. (MaxInt div SizeOf(PAnsiChar))-1of PAnsiChar;

type
  TSQLiteExecCallback = function(UserData: Pointer; NumCols: integer; ColValues:
    PPAnsiCharArray; ColNames: PPAnsiCharArray): integer; cdecl;
  TSQLiteBusyHandlerCallback = function(UserData: Pointer; P2: integer): integer; cdecl;

  //function prototype for define own collate
  TCollateXCompare = function(UserData: pointer; Buf1Len: integer; Buf1: pointer;
    Buf2Len: integer; Buf2: pointer): integer; cdecl;
    

function SQLite3_Open(filename: PAnsiChar; var db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_open';
function SQLite3_Close(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_close';
function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdeclexternal SQLiteDLL name 'sqlite3_exec';
function SQLite3_Version(): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_libversion';
function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_errmsg';
function SQLite3_ErrCode(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_errcode';
procedure SQlite3_Free(P: PAnsiChar); cdeclexternal SQLiteDLL name 'sqlite3_free';
function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdeclexternal SQLiteDLL name 'sqlite3_get_table';
procedure SQLite3_FreeTable(Table: TSQLiteResult); cdeclexternal SQLiteDLL name 'sqlite3_free_table';
function SQLite3_Complete(P: PAnsiChar): boolean; cdeclexternal SQLiteDLL name 'sqlite3_complete';
function SQLite3_LastInsertRowID(db: TSQLiteDB): int64; cdeclexternal SQLiteDLL name 'sqlite3_last_insert_rowid';
procedure SQLite3_Interrupt(db: TSQLiteDB); cdeclexternal SQLiteDLL name 'sqlite3_interrupt';
procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdeclexternal SQLiteDLL name 'sqlite3_busy_handler';
procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer); cdeclexternal SQLiteDLL name 'sqlite3_busy_timeout';
function SQLite3_Changes(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_changes';
function SQLite3_TotalChanges(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_total_changes';
function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdeclexternal SQLiteDLL name 'sqlite3_prepare';
function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdeclexternal SQLiteDLL name 'sqlite3_prepare_v2';
function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer; cdeclexternal SQLiteDLL name 'sqlite3_column_count';
function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_column_name';
function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_column_decltype';
function SQLite3_Step(hStmt: TSqliteStmt): integer; cdeclexternal SQLiteDLL name 'sqlite3_step';
function SQLite3_DataCount(hStmt: TSqliteStmt): integer; cdeclexternal SQLiteDLL name 'sqlite3_data_count';

function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer; cdeclexternal SQLiteDLL name 'sqlite3_column_blob';
function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer; cdeclexternal SQLiteDLL name 'sqlite3_column_bytes';
function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double; cdeclexternal SQLiteDLL name 'sqlite3_column_double';
function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer; cdeclexternal SQLiteDLL name 'sqlite3_column_int';
function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_column_text';
function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer; cdeclexternal SQLiteDLL name 'sqlite3_column_type';
function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64; cdeclexternal SQLiteDLL name 'sqlite3_column_int64';
function SQLite3_Finalize(hStmt: TSqliteStmt): integer; cdeclexternal SQLiteDLL name 'sqlite3_finalize';
function SQLite3_Reset(hStmt: TSqliteStmt): integer; cdeclexternal SQLiteDLL name 'sqlite3_reset';

// 
// In the SQL strings input to sqlite3_prepare() and sqlite3_prepare16(),
// one or more literals can be replace by a wildcard "?" or ":N:" where
// N is an integer.  These value of these wildcard literals can be set
// using the routines listed below.
// 
// In every case, the first parameter is a pointer to the sqlite3_stmt
// structure returned from sqlite3_prepare().  The second parameter is the
// index of the wildcard.  The first "?" has an index of 1.  ":N:" wildcards
// use the index N.
// 
// The fifth parameter to sqlite3_bind_blob(), sqlite3_bind_text(), and
//sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
//text after SQLite has finished with it.  If the fifth argument is the
// special value SQLITE_STATIC, then the library assumes that the information
// is in static, unmanaged space and does not need to be freed.  If the
// fifth argument has the value SQLITE_TRANSIENT, then SQLite makes its
// own private copy of the data.
// 
// The sqlite3_bind_* routine must be called before sqlite3_step() after
// an sqlite3_prepare() or sqlite3_reset().  Unbound wildcards are interpreted
// as NULL.
// 

type
  TSQLite3Destructor = procedure(Ptr: Pointer); cdecl;

function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer;
  ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
cdeclexternal SQLiteDLL name 'sqlite3_bind_blob';
function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer;
  Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
cdeclexternal SQLiteDLL name 'sqlite3_bind_text';
function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_double';
function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_int';
function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_int64';
function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_null';

function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_parameter_index';

function sqlite3_enable_shared_cache(Value: integer): integer; cdeclexternal SQLiteDLL name 'sqlite3_enable_shared_cache';

//user collate definiton
function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer;
  UserData: pointer; xCompare: TCollateXCompare): integer; cdeclexternal SQLiteDLL name 'sqlite3_create_collation';

function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;

implementation

uses
  SysUtils;

function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
begin
  case SQLiteFieldTypeCode of
    SQLITE_INTEGER: Result := 'Integer';
    SQLITE_FLOAT: Result := 'Float';
    SQLITE_TEXT: Result := 'Text';
    SQLITE_BLOB: Result := 'Blob';
    SQLITE_NULL: Result := 'Null';
  else
    Result := 'Unknown SQLite Field Type Code "' + IntToStr(SQLiteFieldTypeCode) + '"';
  end;
end;

function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;
begin
  case SQLiteErrorCode of
    SQLITE_OK: Result := 'Successful result';
    SQLITE_ERROR: Result := 'SQL error or missing database';
    SQLITE_INTERNAL: Result := 'An internal logic error in SQLite';
    SQLITE_PERM: Result := 'Access permission denied';
    SQLITE_ABORT: Result := 'Callback routine requested an abort';
    SQLITE_BUSY: Result := 'The database file is locked';
    SQLITE_LOCKED: Result := 'A table in the database is locked';
    SQLITE_NOMEM: Result := 'A malloc() failed';
    SQLITE_READONLY: Result := 'Attempt to write a readonly database';
    SQLITE_INTERRUPT: Result := 'Operation terminated by sqlite3_interrupt()';
    SQLITE_IOERR: Result := 'Some kind of disk I/O error occurred';
    SQLITE_CORRUPT: Result := 'The database disk image is malformed';
    SQLITE_NOTFOUND: Result := '(Internal Only) Table or record not found';
    SQLITE_FULL: Result := 'Insertion failed because database is full';
    SQLITE_CANTOPEN: Result := 'Unable to open the database file';
    SQLITE_PROTOCOL: Result := 'Database lock protocol error';
    SQLITE_EMPTY: Result := 'Database is empty';
    SQLITE_SCHEMA: Result := 'The database schema changed';
    SQLITE_TOOBIG: Result := 'Too much data for one row of a table';
    SQLITE_CONSTRAINT: Result := 'Abort due to contraint violation';
    SQLITE_MISMATCH: Result := 'Data type mismatch';
    SQLITE_MISUSE: Result := 'Library used incorrectly';
    SQLITE_NOLFS: Result := 'Uses OS features not supported on host';
    SQLITE_AUTH: Result := 'Authorization denied';
    SQLITE_FORMAT: Result := 'Auxiliary database format error';
    SQLITE_RANGE: Result := '2nd parameter to sqlite3_bind out of range';
    SQLITE_NOTADB: Result := 'File opened that is not a database file';
    SQLITE_ROW: Result := 'sqlite3_step() has another row ready';
    SQLITE_DONE: Result := 'sqlite3_step() has finished executing';
  else
    Result := 'Unknown SQLite Error Code "' + IntToStr(SQLiteErrorCode) + '"';
  end;
end;

function ColValueToStr(Value: PAnsiChar): AnsiString;
begin
  if (Value = nilthen
    Result := 'NULL'
  else
    Result := Value;
end;


end.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 08.10.11 13:41 
Du musst jede Funktion so umschreiben, dass sie nicht mehr statisch aus der DLL geladen wird, sondern dynamisch. Sprich vom Prinzip her:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
type
  TSQLiteDLLLoader = class
  public
    type
      EDLLNotLoadedException = class(Exception)
      public
        constructor Create(const ARoutine: string); overload;
      end;
  strict private
    type
      TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
    var
      FSQLiteDLLHandle: THandle
      FSQLite3_Open: TSQLite3_Open;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
  end;

constructor TSQLiteDLLLoader.EDLLNotLoadedException.Create(const ARoutine: string);
begin
  inherited Create('The SQLite library was not loaded before calling ' + ARoutine);
end;
  
function TSQLiteDLLLoader.LoadDLL(ADLLPath: string): Boolean;
begin
  FSQLiteDLLHandle := LoadLibrary(ADLLPath);
  Result := FSQLiteDLLHandle <> 0;
  if Result then
  begin
    @FSQLite3_Open := GetProcAddress(FMyDLLHandle, "SQLite3_Open");
  end;
end;

procedure TSQLiteDLLLoader.UnloadDLL;
begin
  if FSQLiteDLLHandle <> 0 then
  begin
    FreeLibrary(FSQLiteDLLHandle);
    FMyDLLHandle := 0;
  end;
end;

function TSQLiteDLLLoader.SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
begin
  if Assigned(FSQLite3_Open) then
    Result := FSQLite3_Open(PAnsiChar(AFilename), db)
  else
    raise EDLLNotLoadedException.Create('SQLite3_Open');
end;
Ungetestet natürlich.
Du könntest theoretisch auch die Funktionsfelder public machen und direkt darauf zugreifen, aber dann würde es ohne konkrete Meldung einfach nur knallen, wenn die DLL nicht vorher geladen wurde.

// EDIT:
Für alte Delphiversionen (vor 2006) musst du die Deklarationen entsprechend ändern.
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Sa 08.10.11 14:10 
Okay...das sieht nach viel Arbeit aus. Von der Logik her habe ich es verstanden, aber wie der der Aufbau aussehen soll nicht. Würde das so in etwa stimmen?

EDIT: Habe mir nun die Arbeit gemacht:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
unit sqlite3;

{$IFDEF FPC}
  {$MODE DELPHI}
  {$H+}            (* use AnsiString *)
  {$PACKENUM 4}    (* use 4-byte enums *)
  {$PACKRECORDS C} (* C/C++-compatible record packing *)
{$ELSE}
  {$MINENUMSIZE 4} (* use 4-byte enums *)
{$ENDIF}

interface

const
  SQLITE_OK          =  0// Successful result
  (* beginning-of-error-codes *)
  SQLITE_ERROR       =  1// SQL error or missing database
  SQLITE_INTERNAL    =  2// An internal logic error in SQLite
  SQLITE_PERM        =  3// Access permission denied
  SQLITE_ABORT       =  4// Callback routine requested an abort
  SQLITE_BUSY        =  5// The database file is locked
  SQLITE_LOCKED      =  6// A table in the database is locked
  SQLITE_NOMEM       =  7// A malloc() failed
  SQLITE_READONLY    =  8// Attempt to write a readonly database
  SQLITE_INTERRUPT   =  9// Operation terminated by sqlite3_interrupt()
  SQLITE_IOERR       = 10// Some kind of disk I/O error occurred
  SQLITE_CORRUPT     = 11// The database disk image is malformed
  SQLITE_NOTFOUND    = 12// (Internal Only) Table or record not found
  SQLITE_FULL        = 13// Insertion failed because database is full
  SQLITE_CANTOPEN    = 14// Unable to open the database file
  SQLITE_PROTOCOL    = 15// Database lock protocol error
  SQLITE_EMPTY       = 16// Database is empty
  SQLITE_SCHEMA      = 17// The database schema changed
  SQLITE_TOOBIG      = 18// Too much data for one row of a table
  SQLITE_CONSTRAINT  = 19// Abort due to contraint violation
  SQLITE_MISMATCH    = 20// Data type mismatch
  SQLITE_MISUSE      = 21// Library used incorrectly
  SQLITE_NOLFS       = 22// Uses OS features not supported on host
  SQLITE_AUTH        = 23// Authorization denied
  SQLITE_FORMAT      = 24// Auxiliary database format error
  SQLITE_RANGE       = 25// 2nd parameter to sqlite3_bind out of range
  SQLITE_NOTADB      = 26// File opened that is not a database file
  SQLITE_ROW         = 100// sqlite3_step() has another row ready
  SQLITE_DONE        = 101// sqlite3_step() has finished executing

  SQLITE_INTEGER = 1;
  SQLITE_FLOAT   = 2;
  SQLITE_TEXT    = 3;
  SQLITE_BLOB    = 4;
  SQLITE_NULL    = 5;

  SQLITE_UTF8     = 1;
  SQLITE_UTF16    = 2;
  SQLITE_UTF16BE  = 3;
  SQLITE_UTF16LE  = 4;
  SQLITE_ANY      = 5;

  SQLITE_STATIC    {: TSQLite3Destructor} = Pointer(0);
  SQLITE_TRANSIENT {: TSQLite3Destructor} = Pointer(-1);

type
  TSQLiteDB = Pointer;
  TSQLiteResult = ^PAnsiChar;
  TSQLiteStmt = Pointer;

type
  PPAnsiCharArray = ^TPAnsiCharArray; 
  TPAnsiCharArray = array[0 .. (MaxInt div SizeOf(PAnsiChar))-1of PAnsiChar;

type
  TSQLiteExecCallback = function(UserData: Pointer; NumCols: integer; ColValues:
    PPAnsiCharArray; ColNames: PPAnsiCharArray): integer; cdecl;
  TSQLiteBusyHandlerCallback = function(UserData: Pointer; P2: integer): integer; cdecl;

  //function prototype for define own collate
  TCollateXCompare = function(UserData: pointer; Buf1Len: integer; Buf1: pointer;
    Buf2Len: integer; Buf2: pointer): integer; cdecl;

// Hier deine Klasse
type
  TSQLiteDLLLoader = class
  public
    type
      EDLLNotLoadedException = class(Exception)
      public
        constructor Create(const ARoutine: string); overload;
      end;
  strict private
    type
      TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
      TSQLite3_Close = function(db: TSQLiteDB): integer; cdecl;
      TSQLite3_Exec = function(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl;
      TSQLite3_Version = function(): PAnsiChar; cdecl;
      TSQLite3_ErrMsg = function(db: TSQLiteDB): PAnsiChar; cdecl;
      TSQLite3_ErrCode = function(db: TSQLiteDB): integer; cdecl;
      TSQlite3_Free = procedure(P: PAnsiChar); cdecl;
      TSQLite3_GetTable = function(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl;
      TSQLite3_FreeTable = procedure(Table: TSQLiteResult); cdecl;
      TSQLite3_Complete = function(P: PAnsiChar): boolean; cdecl;
      TSQLite3_LastInsertRowID = function(db: TSQLiteDB): int64; cdecl;
      TSQLite3_Interrupt = procedure(db: TSQLiteDB): integer; cdecl;
      TSQLite3_BusyHandler = procedure(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl;
      TSQLite3_BusyTimeout = procedure(db: TSQLiteDB; TimeOut: integer); cdecl;
      TSQLite3_Changes = function(db: TSQLiteDB): integer; cdecl;
      TSQLite3_TotalChanges = function(db: TSQLiteDB): integer; cdecl;
      TSQLite3_Prepare = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
      TSQLite3_Prepare_v2 = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
      TSQLite3_ColumnCount = function(hStmt: TSqliteStmt): integer; cdecl;
      TSQLite3_ColumnName = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
      TSQLite3_ColumnDeclType = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
      TSQLite3_Step = function(hStmt: TSqliteStmt): integer; cdecl;
      TSQLite3_DataCount = function(hStmt: TSqliteStmt): integer; cdecl;
      TSQLite3_ColumnBlob = function(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl;
      TSQLite3_ColumnBytes = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
      TSQLite3_ColumnDouble = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
      TSQLite3_ColumnInt = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
      TSQLite3_ColumnText = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
      TSQLite3_ColumnType = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
      TSQLite3_ColumnInt64 = function(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl;
      TSQLite3_Finalize = function(hStmt: TSqliteStmt): integer; cdecl;
      TSQLite3_Reset = function(hStmt: TSqliteStmt): integer; cdecl;
    var
      FSQLiteDLLHandle: THandle
      FSQLite3_Open: TSQLite3_Open;
      FSQLite3_Close: TSQLite3_Close;
      FSQLite3_Exec: TSQLite3_Exec;
      FSQLite3_Version: TSQLite3_Version;
      FSQLite3_ErrMsg: TSQLite3_ErrMsg;
      FSQLite3_ErrCode: TSQLite3_ErrCode;
      FSQlite3_Free: TSQlite3_Free;
      FSQLite3_GetTable: TSQLite3_GetTable;
      FSQLite3_FreeTable: TSQLite3_FreeTable;
      FSQLite3_Complete: TSQLite3_Complete;
      FSQLite3_LastInsertRowID: TSQLite3_LastInsertRowID;
      FSQLite3_Interrupt: TSQLite3_Interrupt;
      FSQLite3_BusyHandler: TSQLite3_BusyHandler;
      FSQLite3_BusyTimeout: TSQLite3_BusyTimeout;
      FSQLite3_Changes: TSQLite3_Changes;
      FSQLite3_TotalChanges: TSQLite3_TotalChanges;
      FSQLite3_Prepare: TSQLite3_Prepare;
      FSQLite3_Prepare_v2: TSQLite3_Prepare_v2;
      FSQLite3_ColumnCount: TSQLite3_ColumnCount;
      FSQLite3_ColumnName: TSQLite3_ColumnName;
      FSQLite3_ColumnDeclType: TSQLite3_ColumnDeclType;
      FSQLite3_Step: TSQLite3_Step;
      FSQLite3_DataCount: TSQLite3_DataCount;
      FSQLite3_ColumnBlob: TSQLite3_ColumnBlob;
      FSQLite3_ColumnBytes: TSQLite3_ColumnBytes;
      FSQLite3_ColumnDouble: TSQLite3_ColumnDouble;
      FSQLite3_ColumnInt: TSQLite3_ColumnInt;
      FSQLite3_ColumnText: TSQLite3_ColumnText;
      FSQLite3_ColumnType: TSQLite3_ColumnType;
      FSQLite3_ColumnInt64: TSQLite3_ColumnInt64;
      FSQLite3_Finalize: TSQLite3_Finalize;
      FSQLite3_Reset: TSQLite3_Reset;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
    function SQLite3_Close(db: TSQLiteDB): integer;
    function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
    function SQLite3_Version(): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_libversion';
    function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar; cdeclexternal SQLiteDLL name 'sqlite3_errmsg';
    function SQLite3_ErrCode(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_errcode';
    procedure SQlite3_Free(P: PAnsiChar); cdeclexternal SQLiteDLL name 'sqlite3_free';
    function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
    procedure SQLite3_FreeTable(Table: TSQLiteResult); cdeclexternal SQLiteDLL name 'sqlite3_free_table';
    function SQLite3_Complete(P: PAnsiChar): boolean; cdeclexternal SQLiteDLL name 'sqlite3_complete';
    function SQLite3_LastInsertRowID(db: TSQLiteDB): int64; cdeclexternal SQLiteDLL name 'sqlite3_last_insert_rowid';
    procedure SQLite3_Interrupt(db: TSQLiteDB); cdeclexternal SQLiteDLL name 'sqlite3_interrupt';
    procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
    procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer); cdeclexternal SQLiteDLL name 'sqlite3_busy_timeout';
    function SQLite3_Changes(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_changes';
    function SQLite3_TotalChanges(db: TSQLiteDB): integer; cdeclexternal SQLiteDLL name 'sqlite3_total_changes';
    function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_Step(hStmt: TSqliteStmt): integer;
    function SQLite3_DataCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
    function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
    function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
    function SQLite3_Finalize(hStmt: TSqliteStmt): integer;
    function SQLite3_Reset(hStmt: TSqliteStmt): integer;
  end;

type
  TSQLite3Destructor = procedure(Ptr: Pointer); cdecl;

// Diese Funktionen müssen ja auch noch in die Klasse?

function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer;
  ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
cdeclexternal SQLiteDLL name 'sqlite3_bind_blob';
function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer;
  Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
cdeclexternal SQLiteDLL name 'sqlite3_bind_text';
function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_double';
function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_int';
function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_int64';
function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_null';

function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
  cdeclexternal SQLiteDLL name 'sqlite3_bind_parameter_index';

function sqlite3_enable_shared_cache(Value: integer): integer; cdeclexternal SQLiteDLL name 'sqlite3_enable_shared_cache';

//user collate definiton
function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer;
  UserData: pointer; xCompare: TCollateXCompare): integer; cdeclexternal SQLiteDLL name 'sqlite3_create_collation';

function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;

implementation

uses
  SysUtils;



// HIER DIE GANZEN FUNKTIONEN UMGESCHRIEBEN


function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
begin
  case SQLiteFieldTypeCode of
    SQLITE_INTEGER: Result := 'Integer';
    SQLITE_FLOAT: Result := 'Float';
    SQLITE_TEXT: Result := 'Text';
    SQLITE_BLOB: Result := 'Blob';
    SQLITE_NULL: Result := 'Null';
  else
    Result := 'Unknown SQLite Field Type Code "' + IntToStr(SQLiteFieldTypeCode) + '"';
  end;
end;

function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;
begin
  case SQLiteErrorCode of
    SQLITE_OK: Result := 'Successful result';
    SQLITE_ERROR: Result := 'SQL error or missing database';
    SQLITE_INTERNAL: Result := 'An internal logic error in SQLite';
    SQLITE_PERM: Result := 'Access permission denied';
    SQLITE_ABORT: Result := 'Callback routine requested an abort';
    SQLITE_BUSY: Result := 'The database file is locked';
    SQLITE_LOCKED: Result := 'A table in the database is locked';
    SQLITE_NOMEM: Result := 'A malloc() failed';
    SQLITE_READONLY: Result := 'Attempt to write a readonly database';
    SQLITE_INTERRUPT: Result := 'Operation terminated by sqlite3_interrupt()';
    SQLITE_IOERR: Result := 'Some kind of disk I/O error occurred';
    SQLITE_CORRUPT: Result := 'The database disk image is malformed';
    SQLITE_NOTFOUND: Result := '(Internal Only) Table or record not found';
    SQLITE_FULL: Result := 'Insertion failed because database is full';
    SQLITE_CANTOPEN: Result := 'Unable to open the database file';
    SQLITE_PROTOCOL: Result := 'Database lock protocol error';
    SQLITE_EMPTY: Result := 'Database is empty';
    SQLITE_SCHEMA: Result := 'The database schema changed';
    SQLITE_TOOBIG: Result := 'Too much data for one row of a table';
    SQLITE_CONSTRAINT: Result := 'Abort due to contraint violation';
    SQLITE_MISMATCH: Result := 'Data type mismatch';
    SQLITE_MISUSE: Result := 'Library used incorrectly';
    SQLITE_NOLFS: Result := 'Uses OS features not supported on host';
    SQLITE_AUTH: Result := 'Authorization denied';
    SQLITE_FORMAT: Result := 'Auxiliary database format error';
    SQLITE_RANGE: Result := '2nd parameter to sqlite3_bind out of range';
    SQLITE_NOTADB: Result := 'File opened that is not a database file';
    SQLITE_ROW: Result := 'sqlite3_step() has another row ready';
    SQLITE_DONE: Result := 'sqlite3_step() has finished executing';
  else
    Result := 'Unknown SQLite Error Code "' + IntToStr(SQLiteErrorCode) + '"';
  end;
end;

function ColValueToStr(Value: PAnsiChar): AnsiString;
begin
  if (Value = nilthen
    Result := 'NULL'
  else
    Result := Value;
end;


end.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 08.10.11 17:34 
Ja, das sieht so richtig aus und die restlichen Funktionen müssen auch in die Klasse, ja.
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: Sa 08.10.11 17:44 
Beim Versuch das zu kompilieren gibt's Fehlermeldungen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
type
  TSQLiteDLLLoader = class
  public
    type  // END erwartet TYPE gefunden
      EDLLNotLoadedException = class(Exception) // Undefinierter Bezeichner Exception
      public
        constructor Create(const ARoutine: string); overload;
      end;
  strict private  // = erwartet aber private gefunden
    type
      TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
    var
      FSQLiteDLLHandle: THandle
      FSQLite3_Open: TSQLite3_Open;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
  end;


Finde diese Abschnitt auch sehr seltsam. Wie schreibt man ihn um?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 08.10.11 21:31 
Für Delphi 7? Das müsste so gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
uses
  Classes;

type
  EDLLNotLoadedException = class(Exception)
  public
    constructor Create(const ARoutine: string); overload;
  end;

  TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;

  TSQLiteDLLLoader = class
  private
    FSQLiteDLLHandle: THandle
    FSQLite3_Open: TSQLite3_Open;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
  end;
Nested types und strict gab es in den Uraltversionen leider noch nicht. Aber die Typdefinitionen müssen nur lose außerhalb der Klasse hin, dann klappt das. Und die Klasse Exception ist in der Unit Classes deklariert glaube ich (grad keine Lust zu schauen ;-)).
LittleBen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 258
Erhaltene Danke: 4

Win 7, Mac OS
Delphi 7
BeitragVerfasst: So 09.10.11 02:09 
Gut, soweit funktionierts schonmal. Mir ist gerade aufgefallen, dass ich manche Funktionen in die Klasse gemacht habe, dich gar nicht mit der DLL zutun haben:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
// Hier deine Klasse
type
  EDLLNotLoadedException = class(Exception)
  public
    constructor Create(const ARoutine: string); overload;
  end;

  TSQLite3_Open = function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
  TSQLite3_Close = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_Exec = function(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl;
  TSQLite3_Version = function(): PAnsiChar; cdecl;
  TSQLite3_ErrMsg = function(db: TSQLiteDB): PAnsiChar; cdecl;
  TSQLite3_ErrCode = function(db: TSQLiteDB): integer; cdecl;
  TSQlite3_Free = procedure(P: PAnsiChar); cdecl;
  TSQLite3_GetTable = function(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl;
  TSQLite3_FreeTable = procedure(Table: TSQLiteResult); cdecl;
  TSQLite3_Complete = function(P: PAnsiChar): boolean; cdecl;
  TSQLite3_LastInsertRowID = function(db: TSQLiteDB): int64; cdecl;
  TSQLite3_Interrupt = procedure(db: TSQLiteDB); cdecl;
  TSQLite3_BusyHandler = procedure(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl;
  TSQLite3_BusyTimeout = procedure(db: TSQLiteDB; TimeOut: integer); cdecl;
  TSQLite3_Changes = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_TotalChanges = function(db: TSQLiteDB): integer; cdecl;
  TSQLite3_Prepare = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
  TSQLite3_Prepare_v2 = function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
  TSQLite3_ColumnCount = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_ColumnName = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_ColumnDeclType = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_Step = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_DataCount = function(hStmt: TSqliteStmt): integer; cdecl//z.B Diese
  TSQLite3_ColumnBlob = function(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl//z.B Diese
  TSQLite3_ColumnBytes = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl//z.B Diese
  TSQLite3_ColumnDouble = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl//z.B Diese
  TSQLite3_ColumnInt = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl//z.B Diese
  TSQLite3_ColumnText = function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
  TSQLite3_ColumnType = function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
  TSQLite3_ColumnInt64 = function(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl;
  TSQLite3_Finalize = function(hStmt: TSqliteStmt): integer; cdecl;
  TSQLite3_Reset = function(hStmt: TSqliteStmt): integer; cdecl;

  TSQLiteDLLLoader = class
  private
    FSQLiteDLLHandle: THandle;
    FSQLite3_Open: TSQLite3_Open;
    FSQLite3_Close: TSQLite3_Close;
    FSQLite3_Exec: TSQLite3_Exec;
    FSQLite3_Version: TSQLite3_Version;
    FSQLite3_ErrMsg: TSQLite3_ErrMsg;
    FSQLite3_ErrCode: TSQLite3_ErrCode;
    FSQlite3_Free: TSQlite3_Free;
    FSQLite3_GetTable: TSQLite3_GetTable;
    FSQLite3_FreeTable: TSQLite3_FreeTable;
    FSQLite3_Complete: TSQLite3_Complete;
    FSQLite3_LastInsertRowID: TSQLite3_LastInsertRowID;
    FSQLite3_Interrupt: TSQLite3_Interrupt;
    FSQLite3_BusyHandler: TSQLite3_BusyHandler;
    FSQLite3_BusyTimeout: TSQLite3_BusyTimeout;
    FSQLite3_Changes: TSQLite3_Changes;
    FSQLite3_TotalChanges: TSQLite3_TotalChanges;
    FSQLite3_Prepare: TSQLite3_Prepare;
    FSQLite3_Prepare_v2: TSQLite3_Prepare_v2;
    FSQLite3_ColumnCount: TSQLite3_ColumnCount;
    FSQLite3_ColumnName: TSQLite3_ColumnName;
    FSQLite3_ColumnDeclType: TSQLite3_ColumnDeclType;
    FSQLite3_Step: TSQLite3_Step;
    FSQLite3_DataCount: TSQLite3_DataCount;
    FSQLite3_ColumnBlob: TSQLite3_ColumnBlob;
    FSQLite3_ColumnBytes: TSQLite3_ColumnBytes;
    FSQLite3_ColumnDouble: TSQLite3_ColumnDouble;
    FSQLite3_ColumnInt: TSQLite3_ColumnInt;
    FSQLite3_ColumnText: TSQLite3_ColumnText;
    FSQLite3_ColumnType: TSQLite3_ColumnType;
    FSQLite3_ColumnInt64: TSQLite3_ColumnInt64;
    FSQLite3_Finalize: TSQLite3_Finalize;
    FSQLite3_Reset: TSQLite3_Reset;
  public
    function LoadDLL(ADLLPath: string): Boolean;
    procedure UnloadDLL;
    function SQLite3_Open(AFilename: AnsiString; var db: TSQLiteDB): Integer;
    function SQLite3_Close(db: TSQLiteDB): integer;
    function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
    function SQLite3_Version(): PAnsiChar;
    function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar;
    function SQLite3_ErrCode(db: TSQLiteDB): integer;
    procedure SQlite3_Free(P: PAnsiChar);
    function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
    procedure SQLite3_FreeTable(Table: TSQLiteResult);
    function SQLite3_Complete(P: PAnsiChar): boolean;
    function SQLite3_LastInsertRowID(db: TSQLiteDB): int64;
    procedure SQLite3_Interrupt(db: TSQLiteDB);
    procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
    procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer);
    function SQLite3_Changes(db: TSQLiteDB): integer;
    function SQLite3_TotalChanges(db: TSQLiteDB): integer;
    function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
    function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_Step(hStmt: TSqliteStmt): integer;
    function SQLite3_DataCount(hStmt: TSqliteStmt): integer;
    function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
    function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
    function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
    function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
    function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
    function SQLite3_Finalize(hStmt: TSqliteStmt): integer;
    function SQLite3_Reset(hStmt: TSqliteStmt): integer;
  end;
Die muss ich dort wieder raus machen, oder???

EDIT: Ach, dann habe ich noch eine kleine Frage zu diesem Teil:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
function TSQLiteDLLLoader.LoadDLL(ADLLPath: string): Boolean;
begin
  FSQLiteDLLHandle := LoadLibrary(ADLLPath);
  Result := FSQLiteDLLHandle <> 0;
  if Result then
  begin
    @FSQLite3_Open := GetProcAddress(FMyDLLHandle, "SQLite3_Open"); // Was ist FMyDLLHandle und wo ist/soll sie deklariert sein?
                                                                    // Oder ist FMyDLLHandle = FSQLiteDLLHandle?
                                                                    // Du meintest doch sicher 'SQLite3_Open'
  end;
end;

procedure TSQLiteDLLLoader.UnloadDLL;
begin
  if FSQLiteDLLHandle <> 0 then
  begin
    FreeLibrary(FSQLiteDLLHandle);
    FMyDLLHandle := 0;  // ??
  end;
end;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 09.10.11 09:01 
Öhm, ja, FMyDLLHandle ist übriggeblieben, ich habe zuerst nur ein Beispiel im Browser angefangen zu tippen und dann doch die Open-Funktion und die richtige DLL genommen. ;-)

Welche Funktionen du brauchst und drin haben willst / musst, musst du doch selbst wissen, aber was du mit nicht mit der DLL zu tun meinst, sehe ich gerade nicht. :gruebel: