Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   problema crear dll con clase (https://www.clubdelphi.com/foros/showthread.php?t=50107)

rzf1983 08-11-2007 13:17:54

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

Lepe 08-11-2007 13:30:46

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

walito 08-11-2007 13:55:26

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.

ixMike 08-11-2007 13:56:19

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.

rzf1983 08-11-2007 14:03:30

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

ixMike 08-11-2007 14:27:36

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.

rzf1983 08-11-2007 14:32:18

Venga, que seguro q no es dificil pero aun asi me estoy matando y no soy capaz, luego será una chorrada seguro

rzf1983 08-11-2007 17:41:33

Por dios, una ayudita!!!

droguerman 08-11-2007 22:21:43

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;

rzf1983 08-11-2007 22:56:52

Si añado el pas ami programa, no necesito hacer la dll


La franja horaria es GMT +2. Ahora son las 14:29:20.

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