我需要在运行时设置/运行 fdconnection 和 fdquery。但是怎么做?
我在我的代码中尝试这个:
var
LocalConnection: TFDConnection;
LicencasTable: TFDQuery;
FDPhysMySQLDriverLink1: TFDPhysMySQLDriverLink;
FDGUIxWaitCursor1: TFDGUIxWaitCursor;
oParams: TStrings;
begin
LocalConnection := TFDConnection.Create(Self);
FDPhysMySQLDriverLink1 := TFDPhysMySQLDriverLink.Create(Self);
FDGUIxWaitCursor1 := TFDGUIxWaitCursor.Create(Self);
FDPhysMySQLDriverLink1.VendorLib := ExtractFilePath(Application.exename)+'libmysql.dll';
try
if Variaveis.hostbd <> '' then begin
oParams := TStringList.Create;
oParams.Add('Server=' + Variaveis.hostbd);
oParams.Add('Database='+Variaveis.databasebd);
oParams.Add('User_Name='+Variaveis.usuariobd);
oParams.Add('Password='+Variaveis.password);
oParams.Add('DriverID=MySQL');
LocalConnection.Params.UserName := Variaveis.usuariobd;
LocalConnection.Params.Password := Variaveis.password;
FDManager.AddConnectionDef('bloqueio', 'MySQL', oParams);
LocalConnection.DriverName := 'MySQL';
LocalConnection.LoginPrompt := false;
LocalConnection.Connected := true;
if LocalConnection.Connected then
// Busca o registro do sistema no bd
LicencasTable := TFDQuery.Create(Self);
LicencasTable.Connection := LocalConnection;
ShowMessage(Pchar(LicencasTable.Connection));
LicencasTable.Close;
LicencasTable.SQL.Clear;
ShowMessage('Before open');
LicencasTable.Open('select * from licencas');
ShowMessage('After open');
LicencasTable.Active := true;
if LicencasTable.Active then begin
ShowMessage('Active');
end;
if not LicencasTable.Active then begin
ShowMessage('This is not Active');
end;
end;
except
oParams.Free;
end;
一切正常,直到到达“ LicencasTable.Open('select * from licencas'); ”
query.open 根本不起作用,也没有给我任何错误。为什么打不开,也不显示错误?
我忘了做什么?