Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Crear una DLL y depurar sus errores (https://www.clubdelphi.com/foros/showthread.php?t=61807)

FGarcia 22-11-2008 21:38:35

Crear una DLL y depurar sus errores
 
Hola!
Aqui, como siempre con preguntas raras.

Como he mencionado en otros hilos uso la biblioteca TComPort para hacer mis interfaces seriales con delphi 7. Siempre la he usado con aplicaciones de windows y su interface grafica sin problemas pero...ahora necesito que el componente de comunicacion (ComPort) se encapsule en una DLL para ser usado desde otro programa (vb.net o c#). Ya he creado la DLL y esta me funciona sin problemas para configurar los ajustes del puerto, abrir y cerrar el puerto pero tengo problemas para almacenar y recuperar los ajustes configurados al puerto (Baudios, Bits, Paridad, Handshacking, etc) me aparece la clasica ventana de error.....:mad:

Explico:

ComPort posee una propiedad llamada StoreSettings la cual permite guardar los datos de configuracion si se han cambiado y otra llamada LoadSettings que nos permite recuperar los ultimos ajustes. Estos son guardados en un archivo INI o en el registro de windows segun seleccion.

Cita:

Storing and loading settings

Application can easily store and load serial port settings using StoreSettings and LoadSettings methods. Settings can be stored into configuration file or registry. StoredProps property determines which properties need to be stored.

Example (Registry)

begin
// store settings to registry(Almacena ajustes)
ComPort1.StoreSettings(stRegistry, '\HKEY_LOCAL_MACHINE\Software\ComPortTest');
// load settings (recupera ajustes)
ComPort1.LoadSettings(stRegistry, '\HKEY_LOCAL_MACHINE\Software\ComPortTest');
end;

Example (Configuration file)

begin
// store settings to configuration file (Almacena ajustes)
ComPort1.StoreSettings(stIniFile, 'c:\ComPortTest.ini');
// load settings (recupera ajustes)
ComPort1.LoadSettings(stIniFile, 'c:\ComPortTest.ini');
end;
Pues bien yo he hecho esto usando los INI:

Código Delphi [-]
//Un procedimiento para guardar los ajustes y que sera llamado desde la aplicacion que usa la DLL
 
procedure GuardarConfiguracion(archivo: PChar); stdCall;
begin
  PuertoS.StoreSettings(stIniFile, strPas(Archivo)); //nombre y ruta de tipo String
end;
 
//Un procedimiento para recuperar los ajustes y que sera llamado desde la aplicacion que usa la DLL
 
procedure CargarConfiguracion(archivo: PChar); stdCall;
begin
  PuertoS.LoadSettings(stIniFile, strPas(Archivo));
end;

Actualmente estoy probando desde delphi el uso de esta dll

Código Delphi [-]
//Para Guardar los ajustes
procedure TForm1.btnStoreCFGClick(Sender: TObject);
var
  Archivo: string;
begin
  Archivo := ExtractFilePath(ParamStr(0)) + 'CommCfg.ini';
  GuardarConfiguracion(pchar(Archivo));
end;
 
 
//Para Recuperar los ajustes
procedure TForm1.btnLoadCFGClick(Sender: TObject);
var
  Archivo: string;
begin
  Archivo := ExtractFilePath(ParamStr(0)) + 'CommCfg.ini';
  CargarConfiguracion(pchar(Archivo));
end;

Tambien segun el mensaje que aparece al iniciar una DLL

Código Delphi [-]
library comScale;
 
{ 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
  ShareMem,
  SysUtils,
  Classes,
  Forms,
  Dialogs,
  CPort;
  
{$R *.res}

El mensaje de Horror:

Código Delphi [-]
---------------------------
Debugger Exception Notification
---------------------------
Project UsaComScale.exe raised exception class EComPort with message 'Failed to store settings'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help   
---------------------------

 
//el otro mensaje a continuacion
 
---------------------------
Application Error
---------------------------
Exception EComPort in module ComScale.dll at 0006326E.
 

---------------------------
Aceptar   
---------------------------

¿Alguna sugerencia? Como siempre estoy abierto a todas las propuestas que sirvan para resolver esto. Gracias.

cHackAll 23-11-2008 02:51:37

Código Delphi [-]
procedure GuardarConfiguracion(archivo: PChar); stdCall;
begin
  MessageBox(0, archivo, nil, 0); // para comprobar que la ruta esta bien...
  PuertoS.StoreSettings(stIniFile, strPas(Archivo)); //nombre y ruta de tipo String
end;

FGarcia 24-11-2008 17:24:01

Ya esta comprobado, de hecho olvide decir que SI crea el archivo en la carpeta donde se ejecuta la aplicacion, solo que no escribe nada. Manipule los ajustes para poder ver cambios, pero no, no logra escribir nada.

FGarcia 26-11-2008 23:33:54

Pues.....continuo con esto.

Como comente en mi post anterior, SI se crea el archivo INI pero no se escribe nada en el. La declaracion del componente ComPort para Guardar y cargar ajustes efectuados es:

Código Delphi [-]
 
//Guardar Configuraciones en el INI
procedure TCustomComPort.StoreIniFile(IniFile: TIniFile);
begin
  if spBasic in FStoredProps then
  begin
    IniFile.WriteString(Name, 'Port', Port);
    IniFile.WriteString(Name, 'BaudRate', BaudRateToStr(BaudRate));
    if BaudRate = brCustom then
      IniFile.WriteInteger(Name, 'CustomBaudRate', CustomBaudRate);
    IniFile.WriteString(Name, 'StopBits', StopBitsToStr(StopBits));
    IniFile.WriteString(Name, 'DataBits', DataBitsToStr(DataBits));
    IniFile.WriteString(Name, 'Parity', ParityToStr(Parity.Bits));
    IniFile.WriteString(Name, 'FlowControl', FlowControlToStr(FlowControl.FlowControl));
  end;
  if spOthers in FStoredProps then
  begin
    IniFile.WriteString(Name, 'EventChar', CharToStr(EventChar));
    IniFile.WriteString(Name, 'DiscardNull', BoolToStr(DiscardNull));
  end;
  if spParity in FStoredProps then
  begin
    IniFile.WriteString(Name, 'Parity.Check', BoolToStr(Parity.Check));
    IniFile.WriteString(Name, 'Parity.Replace', BoolToStr(Parity.Replace));
    IniFile.WriteString(Name, 'Parity.ReplaceChar', CharToStr(Parity.ReplaceChar));
  end;
  if spBuffer in FStoredProps then
  begin
    IniFile.WriteInteger(Name, 'Buffer.OutputSize', Buffer.OutputSize);
    IniFile.WriteInteger(Name, 'Buffer.InputSize', Buffer.InputSize);
  end;
  if spTimeouts in FStoredProps then
  begin
    IniFile.WriteInteger(Name, 'Timeouts.ReadInterval', Timeouts.ReadInterval);
    IniFile.WriteInteger(Name, 'Timeouts.ReadTotalConstant', Timeouts.ReadTotalConstant);
    IniFile.WriteInteger(Name, 'Timeouts.ReadTotalMultiplier', Timeouts.ReadTotalMultiplier);
    IniFile.WriteInteger(Name, 'Timeouts.WriteTotalConstant', Timeouts.WriteTotalConstant);
    IniFile.WriteInteger(Name, 'Timeouts.WriteTotalMultiplier', Timeouts.WriteTotalMultiplier);
  end;
  if spFlowControl in FStoredProps then
  begin
    IniFile.WriteString(Name, 'FlowControl.ControlRTS', RTSToStr(FlowControl.ControlRTS));
    IniFile.WriteString(Name, 'FlowControl.ControlDTR', DTRToStr(FlowControl.ControlDTR));
    IniFile.WriteString(Name, 'FlowControl.DSRSensitivity', BoolToStr(FlowControl.DSRSensitivity));
    IniFile.WriteString(Name, 'FlowControl.OutCTSFlow', BoolToStr(FlowControl.OutCTSFlow));
    IniFile.WriteString(Name, 'FlowControl.OutDSRFlow', BoolToStr(FlowControl.OutDSRFlow));
    IniFile.WriteString(Name, 'FlowControl.TxContinueOnXoff', BoolToStr(FlowControl.TxContinueOnXoff));
    IniFile.WriteString(Name, 'FlowControl.XonXoffIn', BoolToStr(FlowControl.XonXoffIn));
    IniFile.WriteString(Name, 'FlowControl.XonXoffOut', BoolToStr(FlowControl.XonXoffOut));
    IniFile.WriteString(Name, 'FlowControl.XoffChar', CharToStr(FlowControl.XoffChar));
    IniFile.WriteString(Name, 'FlowControl.XonChar', CharToStr(FlowControl.XonChar));
  end;
end;
 
 
// Cargar configuraciones desde el INI
procedure TCustomComPort.LoadIniFile(IniFile: TIniFile);
begin
  if spBasic in FStoredProps then
  begin
    Port := IniFile.ReadString(Name, 'Port', Port);
    BaudRate := StrToBaudRate(IniFile.ReadString(Name, 'BaudRate', BaudRateToStr(BaudRate)));
    if BaudRate = brCustom then
      CustomBaudRate := IniFile.ReadInteger(Name, 'CustomBaudRate', 9600);
    StopBits := StrToStopBits(IniFile.ReadString(Name, 'StopBits', StopBitsToStr(StopBits)));
    DataBits := StrToDataBits(IniFile.ReadString(Name, 'DataBits', DataBitsToStr(DataBits)));
    Parity.Bits := StrToParity(IniFile.ReadString(Name, 'Parity', ParityToStr(Parity.Bits)));
    FlowControl.FlowControl := StrToFlowControl(
      IniFile.ReadString(Name, 'FlowControl', FlowControlToStr(FlowControl.FlowControl)));
  end;
  if spOthers in FStoredProps then
  begin
    EventChar := StrToChar(IniFile.ReadString(Name, 'EventChar', CharToStr(EventChar)));
    DiscardNull := StrToBool(IniFile.ReadString(Name, 'DiscardNull', BoolToStr(DiscardNull)));
  end;
  if spParity in FStoredProps then
  begin
    Parity.Check := StrToBool(IniFile.ReadString(Name, 'Parity.Check', BoolToStr(Parity.Check)));
    Parity.Replace := StrToBool(IniFile.ReadString(Name, 'Parity.Replace', BoolToStr(Parity.Replace)));
    Parity.ReplaceChar := StrToChar(IniFile.ReadString(Name, 'Parity.ReplaceChar', CharToStr(Parity.ReplaceChar)));
  end;
  if spBuffer in FStoredProps then
  begin
    Buffer.OutputSize := IniFile.ReadInteger(Name, 'Buffer.OutputSize', Buffer.OutputSize);
    Buffer.InputSize := IniFile.ReadInteger(Name, 'Buffer.InputSize', Buffer.InputSize);
  end;
  if spTimeouts in FStoredProps then
  begin
    Timeouts.ReadInterval := IniFile.ReadInteger(Name, 'Timeouts.ReadInterval', Timeouts.ReadInterval);
    Timeouts.ReadTotalConstant := IniFile.ReadInteger(Name, 'Timeouts.ReadTotalConstant', Timeouts.ReadTotalConstant);
    Timeouts.ReadTotalMultiplier := IniFile.ReadInteger(Name, 'Timeouts.ReadTotalMultiplier', Timeouts.ReadTotalMultiplier);
    Timeouts.WriteTotalConstant := IniFile.ReadInteger(Name, 'Timeouts.WriteTotalConstant', Timeouts.WriteTotalConstant);
    Timeouts.WriteTotalMultiplier := IniFile.ReadInteger(Name, 'Timeouts.WriteTotalMultiplier', Timeouts.WriteTotalMultiplier);
  end;
  if spFlowControl in FStoredProps then
  begin
    FlowControl.ControlRTS := StrToRTS(IniFile.ReadString(Name, 'FlowControl.ControlRTS', RTSToStr(FlowControl.ControlRTS)));
    FlowControl.ControlDTR := StrToDTR(IniFile.ReadString(Name, 'FlowControl.ControlDTR', DTRToStr(FlowControl.ControlDTR)));
    FlowControl.DSRSensitivity := StrToBool(IniFile.ReadString(Name, 'FlowControl.DSRSensitivity', BoolToStr(FlowControl.DSRSensitivity)));
    FlowControl.OutCTSFlow := StrToBool(IniFile.ReadString(Name, 'FlowControl.OutCTSFlow', BoolToStr(FlowControl.OutCTSFlow)));
    FlowControl.OutDSRFlow := StrToBool(IniFile.ReadString(Name, 'FlowControl.OutDSRFlow', BoolToStr(FlowControl.OutCTSFlow)));
    FlowControl.TxContinueOnXoff := StrToBool(IniFile.ReadString(Name, 'FlowControl.TxContinueOnXoff', BoolToStr(FlowControl.TxContinueOnXoff)));
    FlowControl.XonXoffIn := StrToBool(IniFile.ReadString(Name, 'FlowControl.XonXoffIn', BoolToStr(FlowControl.XonXoffIn)));
    FlowControl.XonXoffOut := StrToBool(IniFile.ReadString(Name, 'FlowControl.XonXoffOut', BoolToStr(FlowControl.XonXoffOut)));
    FlowControl.XoffChar := StrToChar(IniFile.ReadString(Name, 'FlowControl.XoffChar', CharToStr(FlowControl.XoffChar)));
    FlowControl.XonChar := StrToChar(IniFile.ReadString(Name, 'FlowControl.XonChar', CharToStr(FlowControl.XonChar)));
  end;
end;

No encuentro cual puede ser la razon de que no escriba en el archivo INI creado.

Gracias por la ayuda


La franja horaria es GMT +2. Ahora son las 13:25:23.

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