Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Programando componentes visuales (https://www.clubdelphi.com/foros/showthread.php?t=70798)

r1d2m3 11-11-2010 13:57:38

Programando componentes visuales
 
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
    { Private declarations }
        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
    { Protected declarations }
  public
    { Public declarations }

    constructor Create(AOwner: TComponent); override;

  published
    { Published declarations }
    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;

//aquí es donde pretendo asignar el valor del día y es donde se queda 
//colgada la aplicación generando el error que mencioné arriba.
  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.

droguerman 11-11-2010 15:52:06

Yo quitaría la condición de si es visible o enabled, porque no tiene nada que ver.

Además asignaría el texto con SendMessage(handle, WM_SETTEXT, .....)

Saludos.

r1d2m3 11-11-2010 16:40:14

ya probé quitando esas condiciones y el problema persiste. Respecto de tu sugerencia de hacerlo con SendMessage, ¿esto significa utilizar la API?, si tienes algún ejemplo, te lo agradecería.

Neftali [Germán.Estévez] 11-11-2010 17:02:53

Prueba a colocar esta línea al inicio de los eventos OnChangeClickD y OnChangeClicM.

Código Delphi [-]
    if (csLoading in Self.ComponentState) then begin
      Exit;
    end;
   ...

Neftali [Germán.Estévez] 11-11-2010 17:36:06

Por cierto, no he comentado, que para este caso, también puede ser adecuado sea un Frame, con lo componentes y el comportamiento que necesites.

r1d2m3 11-11-2010 19:10:20

Gracias Neftali, funcionó perfecto.

Saludos.


La franja horaria es GMT +2. Ahora son las 09:18:31.

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