Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Delphi para la web
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-01-2021
Punzo Punzo is offline
Miembro
 
Registrado: abr 2006
Posts: 96
Poder: 19
Punzo Va por buen camino
Componente indy dentro de una dll

Buen día a todos, hay algunos factores a tomar en cuenta para hacer una dll con indy 10.6.2 y su componente TidTCPClient?, ya que quiero convertir un exe, que funciona sin problemas, y al pasarlo a dll, me genera Access Violations, en 2 partes que con el exe no lo hace; lo más raro de todo, es que lo hace bien la primera vez, dejo la parte del código(comento las parte donde me da el error), dónde tengo el problema, gracias de antemano.
Código Delphi [-]
procedure TfmConfiguracion.btCargaFamiliasClick(Sender: TObject);
var
  R, Codigo :String;
  JF :TJSONObject;
  Familia :TFamilia;
  NumB, i :Integer;
begin
if (edCaja.Text <> '') and (edTurno.Text <> '') then
  begin
    if NumFam = 0 then
      begin
        SetLength(AFam, NumFam + 1);
        AFam[NumFam] := '000000';
        Codigo := AFam[NumFam];
      end
      else if (Sender is TFamilia) then
        begin
          SetLength(AFam, NumFam + 1);
          AFam[NumFam] := (Sender as TFamilia).Codigo;
          Codigo := AFam[NumFam];
        end
        else
          begin
            Codigo := AFam[NumFam];
          end;
    //  Aquí me manda un Access Violation, la tercera vez que le doy click al boton que dice "cerveza", 
    //  pero no me da el error si le doy click al boton que dice "brandy"
    ClienConLocal.SendCmd('carga_familia ' + Codigo + ' ' + edCaja.Text + ' ' + edTurno.Text + ' ' + IDCliente);
    R := ClienConLocal.LastCmdResult.Text.Text;
    JF := TJSONObject.Parse(R) as TJSONObject;
    NumB := JF['botones'].Count;
    if (NumB > 0) or (JF.S['ayb_fam'] = 'F') then
      begin
        LimpiarPanel(pnFamilias);
        Inc(NumFam);
      end
      else
        begin
          if MessageDlg('¿Estás seguro de agregar ' + (Sender as Tfamilia).Descripcion + ' a Terminados?',
                        mtConfirmation, [mbYes, mbNo], 0, mbYes) = mrYes then
            begin
              LlenarGrid(Sender);
            end;
        end;

    for i := 1 to NumB do
      begin
        Familia := TFamilia.Create(pnFamilias);//Despúes de 3 veces de darle click, me manda el Acces Violation
        Familia.Descripcion := TBase64Encoding.Base64.Decode(JF['botones'].ArrayValue.O[i - 1].S['descrip']);
        Familia.Caption := TBase64Encoding.Base64.Decode(JF['botones'].ArrayValue.O[i - 1].S['descrip']);
        Familia.Codigo := JF['botones'].ArrayValue.O[i - 1].S['codigo'];
        Familia.Precio :=  JF['botones'].ArrayValue.O[i - 1].S['precio'];
        Familia.Impto1 := JF['botones'].ArrayValue.O[i - 1].S['impto1'];
        Familia.Impto2 := JF['botones'].ArrayValue.O[i - 1].S['impto2'];
        Familia.Imprime := JF['botones'].ArrayValue.O[i - 1].S['imprime'];
        Familia.Servicio := JF['botones'].ArrayValue.O[i - 1].S['servicio'];
        Familia.AyB_Fam := JF['botones'].ArrayValue.O[i - 1].S['tipo_ayb'];
        if JF['botones'].ArrayValue.O[i - 1].S['terminado'] = 'S' then
          Familia.Terminado := True
        else
          Familia.Terminado := False;
        Familia.Enabled := Familia.Terminado;
        if JF['botones'].ArrayValue.O[i - 1].S['indica'] <> '' then
          Familia.Indicaciones := JF['botones'].ArrayValue.O[i - 1].S['indica'];
        if JF['botones'].ArrayValue.O[i - 1].S['sugerencias'] <> '' then
          Familia.Sugerencias := JF['botones'].ArrayValue.O[i - 1].S['sugerencias'];
        Familia.Parent := pnFamilias;
        Familia.Font.Size := 10;
        Familia.WordWrap := True;
        Familia.Width := 90;
        Familia.Height := 90;
        Familia.Margins.Left := 5;
        Familia.Margins.Top := 5;
        Familia.Margins.Right := 5;
        Familia.Margins.Bottom := 5;
        Familia.OnClick := btCargaFamiliasClick;
      end;
  end
  else
    ShowMessage('Los campos Caja y Turno son obligatorios');
end;

Última edición por Casimiro Notevi fecha: 06-01-2021 a las 23:38:28.
Responder Con Cita
  #2  
Antiguo 07-01-2021
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.275
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Lo más sencillo es que crees un pequeño proyecto (o dos uno para el EXE y otro para la DLL) donde se reproduzca el error y con el mínimo código posible y lo subas (como ZIP).
De esa forma podemos probarlo y darte la solución, de otra forma es difícil saber qué puede estar pasando...


Cita:
Empezado por Punzo Ver Mensaje
lo más raro de todo, es que lo hace bien la primera vez
Eso puede ser indicativo de que algo en la DLL no se está cargando/descargando correctamente. Y al hacerlo la segunda vez falla.
Enl código de la DLL sería útil para saber qué está pasando.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.

Última edición por Neftali [Germán.Estévez] fecha: 08-01-2021 a las 13:06:48.
Responder Con Cita
  #3  
Antiguo 07-01-2021
Punzo Punzo is offline
Miembro
 
Registrado: abr 2006
Posts: 96
Poder: 19
Punzo Va por buen camino
Muchas gracias por la ayuda, de hecho este código es el que tengo en el proyecto en .exe, y funciona sin problemas, de ahí mi duda de que tengo, que tomar en cuenta para hacer este tipo de conversión de .exe a .dll con el componente TidTCPClient, la .dll la estoy haciendo dinámica, entonces puede ser que no este cargando bien la .dll?
Responder Con Cita
  #4  
Antiguo 07-01-2021
Punzo Punzo is offline
Miembro
 
Registrado: abr 2006
Posts: 96
Poder: 19
Punzo Va por buen camino
Este es el código de mi .dll
Código Delphi [-]
library ConfiguraciónPDVDLL;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  System.SysUtils,
  System.Classes,
  VCL.Forms,
  Windows,
  IdTCPClient,
  Dialogs,
  UConfiguracion in 'UConfiguracion.pas' {fmConfiguracion},
  UdmConexion in 'UdmConexion.pas' {dmConexion: TDataModule},
  UFamilia in '..\..\UnitsCompartidas\UFamilia.pas',
  JsonDataObjects in '..\..\UnitsCompartidas\JsonDataObjects.pas',
  uErrorDescrip in '..\..\UnitsCompartidas\uErrorDescrip.pas';

var
  DLLApp :TApplication;

{$R *.res}

procedure Crear(ParentApp :TApplication; var ClienCon :TIdTCPClient; IDClien :String); stdcall;
begin
  Application := ParentApp;
  //ShowMessage({'IDCliente param DLL: ' + IDCliente +} ' Port: ' + IntToStr(ClienCon.Port));
  fmConfiguracion := TfmConfiguracion.Create(nil);
  fmConfiguracion.Show;
  fmConfiguracion.ClienConLocal := ClienCon;
  IDCliente := IDClien;
  if Not(fmConfiguracion.ClienConLocal.Connected) then
    fmConfiguracion.ClienConLocal.Connect;
end;

procedure DLLUnload(Reason: Integer); register;
begin
  if Reason = DLL_PROCESS_DETACH then
    Application := DLLApp;
end;

exports
  Crear;

begin
  isMultiThread := True;
  DLLApp := Application;
  DLLProc := @DLLUnload;
end.
Responder Con Cita
  #5  
Antiguo 08-01-2021
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.275
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
¿Has mirado el comentario que hay al principio del fichero?
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Componente Indy tidsnmp Er0s Internet 2 07-06-2018 10:04:30
Componente Indy TCPClient cmfab Varios 1 16-06-2014 14:29:05
Error con componente Indy Alexander Varios 1 04-07-2006 06:15:07
Componente Indy comba Internet 2 22-06-2005 16:00:24
Componente Indy FTPServer bochi Internet 5 19-12-2003 16:39:10


La franja horaria es GMT +2. Ahora son las 15:18:18.


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
Copyright 1996-2007 Club Delphi