![](/img/trans.png)
[英]Deploying Android App (developed in Delphi FireMonkey) to Google Play Store
[英]Deploying SQLite database to Android with Delphi FireMonkey
我試圖使用delphi使用SQLite數據庫部署應用程序在Android模擬器上運行,並使用查詢結果填充組合框。
我已經測試了Win32應用程序上的所有代碼,一切都按預期工作,但是當我部署SQLite數據庫並嘗試在模擬器上運行應用程序時,我引發了帶有“帶消息的TDBXError”的異常,並且ErrorMessage包含'沒有這樣的桌子:汽車'
以下是我的表單的代碼。
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
begin
// Populate Manufacturer box
SQLConnection1.Connected := True;
SQLQuery1.SQL.Clear;
SQLQuery1.Close;
SQLQuery1.SQL.Add('SELECT DISTINCT manufacturer FROM cars');
try
SQLQuery1.Open;
cbManufac.Items.Clear;
while not SQLQuery1.Eof do
begin
cbManufac.Items.Add(SQLQuery1.Fields[0].AsString);
SQLQuery1.Next;
end;
finally
SQLQuery1.Close;
end;
end;
procedure TForm1.SQLConnection1BeforeConnect(Sender: TObject);
begin
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
SQLConnection1.Params.Values['ColumnMetadataSupported'] := 'False';
SQLConnection1.Params.Values['Database'] :=
System.IOUtils.TPath.Combine(TPath.GetDocumentsPath, 'cars.sqlite');
{$ENDIF}
end;
end.
我已確保將System.IOUtils添加到用途中,並在我的項目部署設置下添加了我的數據庫文件。
如果我激活Win32並測試應用程序,則組合框條目添加得很好。
在表單設計器上我使用TSQLConnection和TSQLQuery
任何人都可以指出我正確的方向。
謝謝
在Deployment Manager中,將數據庫的遠程路徑設置為assets\\external
。 (有關assets\\internal
和assets\\external
之間的區別,請參閱此處的文檔 。)
將BeforeConnect
事件代碼更改為:
procedure TForm1.SQLConnection1BeforeConnect(Sender: TObject);
begin
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
SQLConnection1.Params.Values['ColumnMetadataSupported'] := 'False';
SQLConnection1.Params.Values['Database'] :=
TPath.Combine(TPath.GetSharedDocumentsPath, 'cars.sqlite');
{$ENDIF}
end;
要查看TPath.GetSharedDocumentsPath
和其他位置的物理位置,請參閱支持的目標平台上的標准RTL路徑功能 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.