In questo componente ereditato da Tedit volevo che oltre a ricevere solo caratteri numerici virgola compresa, la proprieta' Text fosse inizialmente vuota, come impostato nel costruttore, invece tale proprieta' vale sempre il valore presente in Object Ispector anche all'avvio della form. Dove sbaglio?
unit EditNum;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;
type
TEditNum = class(TEdit)
private
{ Private declarations }
protected
{ Protected declarations }
procedure KeyPress(var Key: Char); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TEditNum]);
end;
constructor TEditNum.Create(AOwner: TComponent);
begin
// 1. Chiama sempre il costruttore del genitore
inherited Create(AOwner);
Text:='';
end;
procedure TEditNum.KeyPress(var Key: Char);
begin
if not (Key in ['0'..'9', '.', ',' ,#8]) then // #8 -> Backspace
begin
Key:=#0;
exit;
end;
if Key='.' then
Key:=',';
if (Key=',') And (Pos(',',Self.Text)>0) then // ',' multiple
Key:=#0;
inherited KeyPress(Key);
end;
end.