H!
Buscando en la red, encontré un código de A. Johnson para lo redimensionar el componente TEdit. Lo adapté y si funcionó:
Código:
procedure TEditor.AjustarWidth;
var
DC: HDC;
SaveFont: HFont;
Size: TSize;
sText: String;
begin
if (AutoSize) and (MaxLength > 0) then
begin
if not HandleAllocated then exit;
DC := GetDC(handle);
try
SaveFont := SelectObject(DC, Font.Handle);
sText:= DupeString('X', MaxLength);
if GetTextExtentPoint32(DC, pchar(sText), length(sText), Size) then
ClientWidth:= Size.cx;
SelectObject(DC, SaveFont);
finally
ReleaseDC(handle, DC);
end;
end;//if
end;
La llamada a este procedimiento la hago desde CreateWnd, SetAutoSize y DoSetMaxLength:
Código:
procedure TEditor.CreateWnd;
begin
inherited CreateWnd;
AjustarWidth;
end;
procedure TEditor.SetAutoSize(Value: Boolean);
begin
inherited;
AjustarWidth;
end;
procedure TEditStr.DoSetMaxLength(Value: Integer);
begin
AjustarWidth;
inherited;
end;
Sin embargo, funciona a medias. En tiempo de diseño, cuando modificó SetAutoSize y luego MaxLength, no cambia el ancho del componente visual TEditor, pero si lo hago al revés, si lo cambia. También lo cambia, cuando cambio SetAutoSize, MaxLength y vuelvo a poner la propiedad SetAutoSize.
¿Qué me estará faltando?
¿No habrá otra manera de llamar el procedimiento AjustarWidth cuando se cambie el valor de MaxLength?
Espero puedan ayudarme. Gracias de antemano.