0
点赞
收藏
分享

微信扫一扫

(04)Lazarus上连接并显示SQlLite3数据库

Lazarus_SQLite完美框架2.zip   链接:https://pan.baidu.com/s/1jYiQ8Ivv52F54TEDSp5ELg
提取码:914p

 

相关文件打包下载  链接:https://pan.baidu.com/s/1gouuR8IfAHnwvNQ5YvZvSg
提取码:8i2s

01]去官网https://www.sqlite.org/download.html下载对应的SQlite3.dll

02]设置SQLQuery1.SQL 原理图:

   021]添加一行数据

   022]Lazarus中DBGrid (MEMO)显示明细

03]常见问题:

01]去官网https://www.sqlite.org/download.html下载对应的SQlite3.dll

32位Lazarus下载sqlite-dll-win-x86-3440200.zip

64位Lazarus下载sqlite-dll-win-x64-3440200.zip

   下载后,将SQlite3.dll放在工程目录下

(04)Lazarus上连接并显示SQlLite3数据库_sqlite

 拖一个SQLDBLibraryLoader1放在界面上,设置它的ConnectionType和LibraryName

 最后,设置它的Enabled为True后,一定要绝对路径

(04)Lazarus上连接并显示SQlLite3数据库_sqlite_02

  再拖一个SQLConnector1,一定要绝对路径

(04)Lazarus上连接并显示SQlLite3数据库_html_03

 设置SQLDBLibraryLoader1的Enabled为False

(04)Lazarus上连接并显示SQlLite3数据库_sqlite_04

02]设置SQLQuery1.SQL

select * from userinfo

原理图:

(04)Lazarus上连接并显示SQlLite3数据库_SQL_05

(04)Lazarus上连接并显示SQlLite3数据库_sqlite_06

021]添加一行数据

procedure TForm1.Button1Click(Sender: TObject);
begin
  SQLQuery1.Active:=false;
  SQLite3Connection1.ExecuteDirect('INSERT INTO  userinfo VALUES (8, ''asdf'', ''asdfasdf'')');
  SQLTransaction1.Commit;
  SQLQuery1.Active:=true;
end;

022]Lazarus中DBGrid (MEMO)显示明细

(04)Lazarus上连接并显示SQlLite3数据库_sqlite_07

(04)Lazarus上连接并显示SQlLite3数据库_SQL_08

 https://forum.lazarus.freepascal.org/index.php/topic,19339.msg110012.html#msg110012

(04)Lazarus上连接并显示SQlLite3数据库_SQL_09

procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
  Column: TColumn; AState: TGridDrawState);
var
  MyTextStyle: TTextStyle;
begin
  //选择要显示文本的列号
  if (DataCol = 1) or (DataCol = 2)then
  begin
    // The next is not neccesary but you can use it to adjust your text appearance.
    // you can change colors, font, size, as well other parameters.
    MyTextStyle := TDBGrid(Sender).Canvas.TextStyle;
    MyTextStyle.SingleLine := False;
    MyTextStyle.Wordbreak  := False;
    TDBGrid(Sender).Canvas.TextStyle := MyTextStyle;

    // Here how to show any text:
    // just assign an event procedure to OnGetText of the Field.
    Column.Field.OnGetText := @Form1.DBGridOnGetText;
  end;
end;

再手动添加Form1.DBGridOnGetText过程

 

(04)Lazarus上连接并显示SQlLite3数据库_sqlite_10

procedure TForm1.DBGridOnGetText(Sender: TField; var aText: string;
  DisplayText: Boolean);
begin
   if (DisplayText) then   Text := Sender.AsString;
end;

03]常见问题:

(04)Lazarus上连接并显示SQlLite3数据库_html_11

 出现这个错误,要SQLDBLibraryLoader1它的Enabled为False

(04)Lazarus上连接并显示SQlLite3数据库_html_12

 缺失api-ms-win-core-memory-l1-1-1.dll

 https://www.wenjian.net/down/api-ms-win-core-memory-l1-1-1.dll_907719.html

 在system32里用regsvr32 注册一下

数据库文件缺失

(04)Lazarus上连接并显示SQlLite3数据库_html_13

 

举报

相关推荐

0 条评论