Hola colegas, estoy realizando unas pruebas acerca del desarrollo de componentes visuales y estoy teniendo inconvenientes para avanzar, les cuento que pretendo hacer: por ahora es algo muy sencillo (al menos en apariencia), quiero crear un componente que tenga tres tedit para recibir una fecha (dia, mes y año), y cuando quiero implementarle propiedades para que reciba los valores del día, mes y año, me tira el siguiente error: raised exception class EInvalidOperation with message 'Cannot focus a disabled or invisible windows', entiendo que este mensaje es porque pretendo asignar el contenido a un campo que no puede recibir el foco porque la ventana es aún invisible, a continuación les pego el código que estoy usando para ver si me pueden ayudar.
Código Delphi
[-]
unit MisFechas;
interface
uses
Controls, StdCtrls, Classes;
type
TFechas = class(TCustomControl)
private
FCampoD: TEdit;
FCampoM: TEdit;
FCampoA: TEdit;
vDia:Byte;
vMes:Byte;
vAni:Integer;
procedure OnChangeClicD(Sender: TObject);
procedure OnChangeClicM(Sender: TObject);
function GetDia:Byte;
procedure SetDia(Value:Byte);
protected
public
constructor Create(AOwner: TComponent); override;
published
property Dia:Byte read GetDia write SetDia;
end;
procedure Register;
implementation
uses Dialogs, SysUtils;
procedure Register;
begin
RegisterComponents('MisComponentes', [TFechas]);
end;
function TFechas.GetDia:Byte;
begin
Result:=vDia;
end;
procedure TFechas.SetDia(Value: Byte);
begin
vDia:=Value;
if (FCampoD.Visible) and (FCampoD.Enabled) then
FCampoD.Text:=IntToStr(vDia);
end;
constructor TFechas.Create(AOwner: TComponent);
begin
inherited;
Width := 85;
Height := 21;
FCampoD := TEdit.Create(Self);
with FCampoD do
begin
SetBounds(0, 0, 22, 21);
Visible := true;
MaxLength:=2;
OnChange := OnChangeClicD;
Parent := Self;
end;
FCampoM := TEdit.Create(Self);
with FCampoM do
begin
SetBounds(22, 0, 22, 21);
Visible := true;
MaxLength:=2;
OnChange := OnChangeClicM;
Parent := Self;
end;
FCampoA := TEdit.Create(Self);
with FCampoA do
begin
SetBounds(44, 0, 40, 21);
Visible := true;
MaxLength:=4;
Parent := Self;
end;
end;
procedure TFechas.OnChangeClicD(Sender: TObject);
begin
if Length(FCampoD.Text)=FCampoD.MaxLength then
try
FCampoM.SetFocus;
except
end;
end;
procedure TFechas.OnChangeClicM(Sender: TObject);
begin
if Length(FCampoM.Text)=FCampoM.MaxLength then
try
FCampoA.SetFocus;
except
end;
end;
end.
Espero me puedan ayudar, les mando saludos.