Last active
January 26, 2018 12:31
-
-
Save maiquealmeida/ab12e98b07b1185c9802a357295da40f to your computer and use it in GitHub Desktop.
Define o caminho para o banco de dados SQLite ainda em tempo de execução (útil para aplicativos multidevice).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure TDM.DataModuleCreate(Sender: TObject); | |
var | |
nomeBanco : string; | |
dbPath : string; | |
begin | |
nomeBanco := 'database.db'; | |
dbPath := ''; | |
try | |
with FDConn do | |
begin | |
if Connected then | |
Close; | |
Params.Values['DriverID'] := 'SQLite'; | |
{$IFDEF IOS} | |
dbPath := TPath.Combine(TPath.GetDocumentsPath, nomeBanco); | |
{$ENDIF} | |
{$IFDEF ANDROID} | |
dbPath := TPath.Combine(TPath.GetDocumentsPath, nomeBanco); | |
{$ENDIF} | |
{$IFDEF MSWINDOWS} | |
{$IFDEF DEBUG} | |
dbPath := System.SysUtils.GetCurrentDir + '/../../' + nomeBanco; | |
{$ELSE} | |
dbPath := System.SysUtils.GetCurrentDir + '/' + nomeBanco; | |
{$ENDIF} | |
{$ENDIF} | |
Params.Values['Database'] := dbPath; | |
Connected := true; | |
end; | |
except | |
on E: Exception do | |
ShowMessage('Erro de conexão com o banco de dados: ' + E.Message); | |
end; | |
end; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment