Lazarus_SQLite完美框架4源文件下载,一定要放在D:\lazarus\project2
目录下,不要问为什么.
链接:https://pan.baidu.com/s/14nTKCCoA0lVB2jYvXMADgQ
提取码:evyp
相关文件打包下载 链接:https://pan.baidu.com/s/1gouuR8IfAHnwvNQ5YvZvSg
提取码:8i2s
01]去官网https://www.sqlite.org/download.html下载对应的SQlite3.dll
02]设置SQLQuery1.SQL 原理图:
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放在工程目录下
拖一个SQLDBLibraryLoader1放在界面上,设置它的ConnectionType和LibraryName
最后,设置它的Enabled为True后,一定要绝对路径
再拖一个SQLConnector1,一定要绝对路径
设置SQLDBLibraryLoader1的Enabled为False
select * from userinfo
原理图:
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 1(MEMO)显示明细
方法1:设置DBGrid1的Options的dgDisplayMemoTest为True即可
方法2: https://forum.lazarus.freepascal.org/index.php/topic,19339.msg110012.html#msg110012
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过程
procedure TForm1.DBGridOnGetText(Sender: TField; var aText: string; DisplayText: Boolean); begin if (DisplayText) then Text := Sender.AsString; end;
023]Lazarus DBGrid隔行颜色交替,很简单,只需设置AlternateColor指定颜色就可以。
0241]DBGrid1的dgEditing属性一定要设为True,
0242]DBGrid1接收回车后的事件
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState ); begin If (Key = 13) and (SQLQuery1.State=dsEdit) then SQLQuery1.Post;
end;
0243]SQLQuery1的3个属性必须设为True;
效果:
一定要设计时,能显示所有数据
出现这个错误,要SQLDBLibraryLoader1它的Enabled为False
缺失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 注册一下
数据库文件缺失