Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Conexión con bases de datos (https://www.clubdelphi.com/foros/forumdisplay.php?f=2)
-   -   Funciones y Procedimientos en DLL (https://www.clubdelphi.com/foros/showthread.php?t=94406)

webmasterplc 26-01-2020 22:49:10

Funciones y Procedimientos en DLL
 
Buenas hasta ahora me ha ido muy bien con delphi agradecido d este foro he ido aprendiendo mucho hoy me acarrea na duda me gustaría pasar las funciones y los procedimientos de una aplicación a dll y luego llamarlos desde el código.

esta es una función que uso y con este tipo de funciones no tengo problemas

Código Delphi [-]
function ceros_izq(strValue: String; intNewWidth: Integer): String; stdcall;
var intOldWidth, I: Integer;
begin
  try
    strValue := Trim (StrValue);
    if strValue = '' then
      strValue := '0';
    if StrToInt(strValue) < 0 then
      strValue := '0';
  except
    on EConvertError do strValue := '0';
  end;
  intOldWidth := Length(strValue);
  if intOldWidth < intNewWidth then
    for I := 1 to intNewWidth - intOldWidth do
      strValue := '0' + strValue;
  Result := strValue;
end;

el problema o la tranca se me presento en las funciones o procedimientos que tienen acceso a datos como esta
Código Delphi [-]
procedure actualizar (ncomprobante:Integer);stdcall;
var
pncomprobante:Integer;
begin
    pncomprobante:=ncomprobante+1;
    with datos.sqactualizar do
    begin
    Close;
    SQL.Clear;
    SQL.Add('UPDATE configuracion set conf_comprobante=:pncomprobante');
    ParamByName('pncomprobante').AsInteger:=pncomprobante;
    ExecSQL;
    end;
end;
uso mydac y en otros proyectos zeoslib y tendria que crear los componentes en tiempo de ejecución y no se si a cada dll tendria que crear una conexion y pasarle los parametros, hasta donde seria recomendado hacerlo asi o si usare recursos indebidamente

webmasterplc 27-01-2020 04:52:58

lo estaba intentando asi haciendo pruebas

Código Delphi [-]
var
    connexion: TMyConnection;


{$R *.res}
function conectar (server,usuario,clave,base:string;puerto:Integer):Boolean;

    begin

      connexion.Create(nil);
      connexion.Server:=server;
      connexion.Username:=usuario;
      connexion.Password:=clave;
      connexion.Database:=base;
      connexion.Port:=puerto;
      connexion.Connected:=True;

    end;
procedure guardar (dato1,dato2:string);stdcall;
  var
  consulta:TMyQuery;
    begin
    conectar('127.0.0.1','root','0000','finanzas',3305);
    with consulta do
    begin
      Create(nil);
      connexion:=connexion;
      SQL.Add('insert into (conf_agente,config_rif)');
      SQL.Add('values (:pdato1,:pdato2)');
      ParamByName('pdato1').AsString:=dato1;
      ParamByName('pdato2').AsString:=dato2;
      Execute;
    end;
    consulta.Free;
    connexion.Free;
    end;
exports guardar;


La franja horaria es GMT +2. Ahora son las 14:08:59.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi