Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Firebird e Interbase
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 13-05-2010
Aldo Aldo is offline
Miembro
 
Registrado: ene 2004
Posts: 46
Poder: 0
Aldo Va por buen camino
OK. Creo que lo mejor es lo que dices.

Aquí os va part edel código que tiene una clase para tratar un String y poder convertirlo en Pchar para que sea devuleto por la UDF en cuestión.

Código Delphi [-]
...
Type
   TUDFString = class
  private
    FString: PChar;
    FSize: Integer;
    FLength: Integer;
    procedure SetPChar(Value: PChar);
    function GetString: String;
    procedure SetString(Value: String);
    procedure SetSize(Value: Integer);
  public
    constructor Create;
    destructor Destroy; override;
    property AsString: String read GetString write SetString;
    property AsPChar: PChar read FString write SetPChar;
    property StrLength: Integer read FLength;
    property StrSize: Integer read FSize write SetSize;
  end;
...
threadvar
  gResult: TUDFString;
...

implementation

const
  ShrinkLen = 100;

constructor TUDFString.Create;
begin
  FString := nil;
  SetSize(ShrinkLen);
  FLength := 0;
end;

destructor TUDFString.Destroy;
begin
  if (Self <> nil) and (FSize > 0) then
    ReallocMem(FString, 0);
  inherited;
end;

procedure TUDFString.SetPChar(Value: PChar);
begin
  FLength := StrLen(Value);
  SetSize(FLength);
  StrCopy(FString, Value);
end;

function TUDFString.GetString: String;
begin
  result := String(FString);
end;

procedure TUDFString.SetString(Value: String);
begin
  if Self <> nil then begin
    FLength := Length(Value);
    SetSize(FLength);
    StrPCopy(FString, Value);
  end;
end;

procedure TUDFString.SetSize(Value: Integer);
begin
  if (Value > FSize) or
     (Value <= FSize - ShrinkLen) then begin
    ReallocMem(FString, Value + 1);
    FSize := Value;
  end;
end;
...

Ahora la declaración de la UDF

Código Delphi [-]
function T_AlgoToStr( var nFVToCheck: Integer ): PChar; cdecl; export;

La implemetación de dicha función. Se asume que la variable gResult se ha creado en Initialization section de la DLL.

Código Delphi [-]
function T_AlgoToStr( var nFVToCheck: Integer ): PChar; cdecl; export;
   function IsValueOk( nValue: Integer ): Boolean;
   begin
      .....
      Result := True;
   end;
   
   function GetAlgoAsStr( nValue: Integer ): String;
   begin
      case nValue of
         1 : Result := 'Cadena 1' ;
         ...
         else
            Result := 'Cadena else';   
      end;
begin
   Result           := '';
   if  not IsValueOk( nFVToCheck ) then
      Exit;
   
   gResult.AsString := GetAlgoAsStr( nFVToCheck ); 
   Result           := gResult.AsPChar; 
end;

NOTA: Esto funciona correctamente en Delphi 5 pero no en Delphi 2010 que en vez de devolver la cadena completa solo devuelte el primer elemento de la cadena.
Responder Con Cita
 



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
Hacer que Delphi 2010 luzca como Delphi 7 jorosmtz La Taberna 0 11-04-2010 22:45:36
Delphi 2010 tec Varios 1 19-01-2010 19:05:55
Problema Udfs cincosoft Firebird e Interbase 5 16-09-2008 23:06:48
UDFs Linux RESP 3.0 Firebird e Interbase 2 26-01-2006 16:10:44
Problemas com UDFs jwmoreira Firebird e Interbase 3 17-06-2004 19:53:01


La franja horaria es GMT +2. Ahora son las 07:59:31.


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