Ver Mensaje Individual
  #1  
Antiguo 07-07-2015
viveba viveba is offline
Miembro
 
Registrado: nov 2006
Posts: 24
Reputación: 0
viveba Va por buen camino
Crear ActiveX en delphi XE 4

Hola gente.

Estoy tratando de crear un ActiveX desde delphi, a modo de prueba y aprendizaje.

Creo un nuevo componente, un sencillo PanelReloj, el siguiente:

Código Delphi [-]
unit PanelReloj;
 
interface
 
uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.ExtCtrls, Vcl.Dialogs, Winapi.Windows;
 
type
  TModoPanel = (Reloj, Texto);
 
  TPanelReloj = class(TPanel)
 
  private
    { Private declarations }
    FModo       : TModoPanel;
    FHoraActual : TTime;
    FTimerAlarma: TTimer;
    FAlarma     : String;
    FOnAlarma   : TNotifyEvent;
 
    procedure ObtenerHora(Sender: TObject);
    procedure ValidarAlarma(Alarma: String);
  protected
    { Protected declarations }
    procedure Paint; override;
  public
    { Public declarations }
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;
    function CambiarHora(Hora: TTime): Integer;
    function CambiarFecha(Fecha: TDate): Integer;
  published
    { Published declarations }
    property Modo    : TModoPanel   read FModo     Write FModo;
    property Alarma  : String       read FAlarma   write ValidarAlarma;
    Property OnAlarma: TNotifyEvent read FOnAlarma write FOnAlarma;
  end;
 
procedure Register;
 
implementation
 
function TPanelReloj.CambiarFecha(Fecha: TDate): Integer;
var FechaHora: TSYSTEMTIME;
    HAno, HMes, HDia: word;
begin
  try
    DecodeDate(Fecha, HAno, HMes, HDia);
    GetLocalTime(FechaHora);
 
    with FechaHora do
    begin
      wYear  := HAno;
      wMonth := HMes;
      wDay   := HDia
    end;
    SetLocalTime(FechaHora);
 
    Result := 0
  except
    Result := 1
  end
end;
 
function TPanelReloj.CambiarHora(Hora: TTime): Integer;
var FechaHora: TSYSTEMTIME;
    HHor, HMin, HSeg, HMil: word;
begin
  try
    DecodeTime(Hora, HHor, HMin, HSeg, HMil);
    GetLocalTime(FechaHora);
 
    with FechaHora do
    begin
      wHour   := HHor;
      wMinute := HMin;
      wSecond := HSeg
    end;
    SetLocalTime(FechaHora);
 
    Result := 0
  except
    Result := 1
  end
end;
 
Constructor TPanelReloj.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  Height     := 25;
  Width      := 120;
  BevelInner := bvLowered;
  BevelOuter := bvLowered;
  FModo      := Reloj;
  FHoraActual:= Time;
  Refresh;
 
  FTimerAlarma          := TTimer.Create(self);
  FTimerAlarma.Interval := 1000;
  FTimerAlarma.OnTimer  := ObtenerHora;
end;
 
Destructor TPanelReloj.Destroy;
begin
  FTimerAlarma.Free;
  Inherited Destroy
end;
 
procedure TPanelReloj.ObtenerHora(Sender: TObject);
var
  LaHoraActual: string;
 
begin
  FHoraActual := Time;
  LaHoraActual:= TimeToStr(FHoraActual);
  Refresh;
  if Enabled and (Alarma = LaHoraActual) and (Assigned(FOnAlarma)) then
    FOnAlarma(self)
end;
 
procedure TPanelReloj.Paint;
begin
  Inherited Paint;
  if Modo = Reloj then Caption := TimeToStr(FHoraActual)
end;
 
procedure TPanelReloj.ValidarAlarma(Alarma: String);
var
  HoraCorrecta: TTime;
 
begin
  Try
    HoraCorrecta := StrToTime(Alarma);
    FAlarma      := TimeToStr(HoraCorrecta)
  except
    ShowMessage('Hora incorrecta')
  end
end;
 
procedure Register;
begin
  RegisterComponents('Mis tonterias', [TPanelReloj])
end;
 
end.

Y ahora???? cómo lo convierto en un ActiveX???

Desde ya, muchas gracias por vuestras respuestas.
Responder Con Cita