Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-11-2007
rzf1983 rzf1983 is offline
Miembro
 
Registrado: oct 2007
Posts: 26
Poder: 0
rzf1983 Va por buen camino
problema crear dll con clase

Hola, tengo un programa en delphi que usa un .pas que yo mismo he realizado, el cual define una clase y sus métodos. Lo que quiero es crear una dll a partir de ese .pas para en mi programa llamar a esa dll. Gracias de antemano
Responder Con Cita
  #2  
Antiguo 08-11-2007
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 28
Lepe Va por buen camino
Empieza por crear un proyecto de tipo DLL: Delphi File -> new -> (busca por ahí ).

después ya podrás pegar el contenido en la dll, o hacer un uses de tu clase, dependiendo de las necesidades.

Saludos
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita
  #3  
Antiguo 08-11-2007
Avatar de walito
walito walito is offline
Miembro
 
Registrado: jun 2005
Posts: 121
Poder: 19
walito Va por buen camino
Luego que tengas la dll o bpl exportas las funciones o la clase completa!

En la libreria bpl la clase completa la exportas asi:

Código Delphi [-]
// I N I T I A L I Z A T I O N
//---------------------------------------
initialization
  // Registrar la clase del form
  RegisterClass(TForm1);
 
// F I N A L I Z A T I O N
//---------------------------------------
finalization
  // Eliminar el registro de la clase
  UnregisterClass(TForm1);

En mi caso yo tengo un Form en TForm1 vos pones el nombre de tu clase.
Responder Con Cita
  #4  
Antiguo 08-11-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
El fichero en cuestión sería:

Código Delphi [-]
//MiDLL.dpr
library MiDLL;

uses MiUnidad; //MiUnidad.pas

exports
  Funcion1, Funcion2, Funcion3; //Estas son funciones de MiUnidad.pas
end.

Una vez hecho y guardado, ve al menú Project|Build All, y te generará el archivo MiDLL.dll

NOTA: en MiUnidad.pas las funciones tienen que ir declaradas así:

Código Delphi [-]
function Funcion1(parametros: tipos): tipofuncion; stdcall;
begin
{...}
end;

procedure Funcion2(parametros: tipos); stdcall;
begin
{...}
end;


Saludos.
Responder Con Cita
  #5  
Antiguo 08-11-2007
rzf1983 rzf1983 is offline
Miembro
 
Registrado: oct 2007
Posts: 26
Poder: 0
rzf1983 Va por buen camino
Pero yo quiero que luego en cualquier programa yo pueda declara un objeto de esa clase y usar sus procedimientos. Mira yo tengo:
Código:
unit MICLASE;

interface

uses
  Classes, SysUtils;

const
  { Used with ChannelModeID property }
  VORBIS_CM_MONO = 1;                                    { Code for mono mode }
  VORBIS_CM_STEREO = 2;                                { Code for stereo mode }

 // Added for multi-channel OGG files
  VORBIS_CM_3Ch = 3;
  VORBIS_CM_4Ch = 4;
  VORBIS_CM_5Ch = 5;
  VORBIS_CM_5Dot1Ch = 6;
  { Channel mode names }
  VORBIS_MODE: array [0..5] of string = ('Unknown', 'Mono', 'Stereo', '3Ch', '4Ch', '5.1Ch');

type
  { Class TOggVorbis }
  TMICLASE = class(TObject)
    private
      { Private declarations }
      FFileSize: Integer;
      FChannelModeID: Byte;
      FSampleRate: Word;
      FBitRateNominal: Word;
      FSamples: Integer;
      FID3v2Size: Integer;
      FTitle: string;
      FArtist: string;
      FAlbum: string;
      FTrack: Word;
      FDate: string;
      FGenre: string;
      FComment: string;
      FVendor: string;

   // * Followings are added to show additional stream information  by Silhwan Hyun
      FStreamVersion : Byte;
      FSerialNo : integer;
      FExtraTag: string;

      procedure FResetData;
      function FGetChannelMode: string;
      function FGetDuration: Double;
      function FGetBitRate: Word;
      function FHasID3v2: Boolean;
      function FIsValid: Boolean;
    public
      { Public declarations }
      constructor Create;                                     { Create object }
      destructor Destroy; override;                          { Destroy object }
      function ReadFromFile(const FileName: string): Boolean;     { Load data }
      function SaveTag(const FileName: string): Boolean;      { Save tag data }
      function ClearTag(const FileName: string): Boolean;    { Clear tag data }
      property FileSize: Integer read FFileSize;          { File size (bytes) }
      property ChannelModeID: Byte read FChannelModeID;   { Channel mode code }
      property ChannelMode: string read FGetChannelMode;  { Channel mode name }
      property SampleRate: Word read FSampleRate;          { Sample rate (hz) }
      property BitRateNominal: Word read FBitRateNominal;  { Nominal bit rate }
      property Title: string read FTitle write FTitle;           { Song title }
      property Artist: string read FArtist write FArtist;       { Artist name }
      property Album: string read FAlbum write FAlbum;           { Album name }
      property Track: Word read FTrack write FTrack;           { Track number }
      property Date: string read FDate write FDate;                    { Year }
      property Genre: string read FGenre write FGenre;           { Genre name }
      property Comment: string read FComment write FComment;        { Comment }
      property Vendor: string read FVendor;                   { Vendor string }
      property Duration: Double read FGetDuration;       { Duration (seconds) }
      property BitRate: Word read FGetBitRate;             { Average bit rate }
      property ID3v2: Boolean read FHasID3v2;      { True if ID3v2 tag exists }
      property Valid: Boolean read FIsValid;             { True if file valid }

   // * Added properties   by Silhwan Hyun
      property StreamVersion: Byte read FStreamVersion;
      property SerialNumber: integer read FSerialNo;
      property ExtraTag: string read FExtraTag write FExtraTag;
  end;

implementation
...
Entonces yo quiero meter eso en una libreria para luego en cualquier programa poder declarar

objeto : MICLASE
Responder Con Cita
  #6  
Antiguo 08-11-2007
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 22
ixMike Va por buen camino
Bueno, en ese caso, para utilizarla tendrías que usar Project|Import Type Library...

pero, la verdad, no sé como crearla.

¿Alguien lo sabe? Es algo que me interesa saber a mí también.

Gracias.
Responder Con Cita
  #7  
Antiguo 08-11-2007
rzf1983 rzf1983 is offline
Miembro
 
Registrado: oct 2007
Posts: 26
Poder: 0
rzf1983 Va por buen camino
Venga, que seguro q no es dificil pero aun asi me estoy matando y no soy capaz, luego será una chorrada seguro
Responder Con Cita
  #8  
Antiguo 08-11-2007
rzf1983 rzf1983 is offline
Miembro
 
Registrado: oct 2007
Posts: 26
Poder: 0
rzf1983 Va por buen camino
Por dios, una ayudita!!!
Responder Con Cita
  #9  
Antiguo 08-11-2007
Avatar de droguerman
droguerman droguerman is offline
Miembro
 
Registrado: abr 2005
Ubicación: tierra
Posts: 999
Poder: 20
droguerman Va por buen camino
añades tu archivo pas tanto al programa como a la dll

en tu dll creas la siguiente funcion


function devolverMiClase : longint
begin
result longint(TMiClases.create);
end;

en tu programa vuelves a hacer el casting

function obtenerClase: TMiClase;
begin
result := TMiClase(devolverMiClase);
end;
__________________
self.free;
Responder Con Cita
  #10  
Antiguo 08-11-2007
rzf1983 rzf1983 is offline
Miembro
 
Registrado: oct 2007
Posts: 26
Poder: 0
rzf1983 Va por buen camino
Si añado el pas ami programa, no necesito hacer la dll
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
crear un evento en una clase? chelox OOP 4 06-06-2007 20:14:20
Crear eventos para una clase DarkByte OOP 10 07-12-2005 20:02:28
Crear clase. Basico de POO. DarkByte OOP 17 24-08-2005 17:37:21
Ayuda para crear una clase estebanx OOP 0 10-03-2005 16:36:49
Error al crear una instancia de clase jplj OOP 2 15-02-2005 11:52:07


La franja horaria es GMT +2. Ahora son las 20:08:04.


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