Ver Mensaje Individual
  #2  
Antiguo 29-05-2024
Avatar de Matorral
Matorral Matorral is offline
Miembro
 
Registrado: oct 2006
Ubicación: Ferrol-Galicia
Posts: 46
Reputación: 0
Matorral Va por buen camino
Hola¡¡

Cita:
Empezado por egostar Ver Mensaje
Hola

En este caso lo que yo intentaría es crear una DLL con Delphi 7 que haga esa operación y regrese el dato esperado.

Saludos
Lo había intentado por medio de una dll cuando me lo dijo pgranados y el resultado obtenido con Delphi 11 era diferente al esperado (1414835712).

Ahora puse un showmessage en la dll para ver la diferencia digito a digito y ya no entiendo nada. Cuando ejecuto la funcion los dígitos pares (wClave1[i]) no tienen valor

Os paso la dll hecha en Delphi7...

Código Delphi [-]
library dllCodifica;

{ 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
  SysUtils,
  Classes,
  Dialogs;

{$R *.res}

function Codifica (v : string): int64; stdcall;
var wClave1: string;
    i:integer;
    j: int64;
begin

   j:=0;
   wclave1 := v;

   for i:=1 to Length(wClave1) do  begin
      j:=j*255+ord(wClave1[i]);

        showmessage(' Después de operacion '+chr(10)+chr(13)+
                 'i = '+inttostr(i)+chr(10)+chr(13)+
                 'j = '+inttostr(j)+chr(10)+chr(13)+
                 'wClave1[i] = '+wClave1[i]+chr(10)+chr(13)+
                 'ord(wClave1[i]) = '+inttostr(ord(wClave1[i]))+chr(10)+chr(13)+
                 'j:=j*255+ord(wClave1[i]) = '+inttostr(j*255+ord(wClave1[i]))+chr(10)+chr(13)+
                 'j:=j*7 = '+inttostr(j*7));
   end;

   j:=j*7;

   Result:=j;

end;

exports Codifica;

begin
end.

y este es la rutina en Delphi 12 que consume la dll...

Código Delphi [-]
unit CODIFICA;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

var Lib : THandle;
    dllCodifica: function(v:String):int64; stdcall;


implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.caption:=IntToStr(dllCodifica(edit1.Text));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

    Lib:=LoadLibrary('dllCodifica.dll');
    dllCodifica := GetProcAddress(Lib,'Codifica');

end;

end.

Desde Delphi 12, al introducir '1111' en el edit y luego al hacer click en el boton, muestra el resultado digito a digito, y en los digitos pares aparece un valor nulo en wClave1[i].

Desde Delphi 7 da el valor esperado.

No entiendo nada, se me escapa.


Gracias¡¡
__________________
Inieeeesssstademiviiiiidaaaaa.
Responder Con Cita