Skip to content

Instantly share code, notes, and snippets.

@maiquealmeida
Last active January 26, 2018 12:31
Show Gist options
  • Save maiquealmeida/ab12e98b07b1185c9802a357295da40f to your computer and use it in GitHub Desktop.
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).
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