unidade updomEdit; A interface usa Windows, Sysutils, classes, controles, stdctrls, comctrls, mensagens; tipo tupdownedit = classe (tcustomControl) privado {Declarações privadas} Updown: TUPDOWN; Editar: Tedit; Fmin: número inteiro; Fmax: número inteiro; FONCHANGE: tnotifyEvent; Fposição: número inteiro; procedimento wmsize ( var msg: twmsize); mensagem wm_size; Procedimento setMax (Valor const : Inteiro); Procedimento setmin (Valor const : Inteiro); Procedimento Editchange (remetente: Tobject); Procedimento EditKeyPress (remetente: TOBJECT; VAR Tecla: CHAR); Procedimento UpdOwnClick (remetente: TOBJECT; Button: Tudbtntype); Procedimento setPosition (Valor const : Inteiro); protegido {Declarações protegidas} público {Declarações públicas} Construtor Create (Anowner: TComponent); substituir ; destruidor destruir; substituir ; publicado {Declarações publicadas} Propriedade Max: Inteiro Read Fmax Write Setmax; Propriedade min: inteiro leia fmin write setmin; Posição da propriedade : Inteiro Read Fposition Write setPosition; Propriedade OnChange: tnotifyEvent leia Foncange Write Fonchange; fim ; registro de procedimentos ; Registro de procedimentos de implementação ; iniciar o registroComponents ('Standard', [TupdownEdit]); fim ; {Tupdownedit} construtor tupdownedit.create (awner: tComponent); começar a criar Criar (Aowner); Setbounds (0, 0, 57, 21); Editar: = tedit.create (self); Edit.left: = 0; Edit.top: = 0; Edit.width: = 40; Edit.align: = alvento; Edit.parent: = self; Edit.Text: = '0'; // setWindowlong (edit.handle, gwl_style, getwindowlong (edit.handle, gwl_style) ou es_number); Updown: = tupdown.create (self); UpdOwn.Height: = altura; // 20; Updown.width: = 14; Updown.left: = edit.width + 1; Updown.parent: = self; Fmin: = 0; Fmax: = 100; Edit.onchange: = Editchange; Edit.onkeypress: = editKeypress; Updown.onclick: = updOwnClick; fim ; Destructor TupdownEdit.Destroy; Begin Edit.Free; Updown.free; herdado ; fim ; procedimento tupdownedit.editchange (remetente: tabjas); BEGN UPDOWN.POSIÇÃO: = STRTONTDEF (Edit.Text, 0); Fposition: = updOwn.Position; se atribuído (fonnchange) , então fonenchange (self); fim ; procedimento tupdownedit.editKeypress (remetente: tabject; var tecla var : char); var s: conjunto de char; I: Inteiro; Str, texto: string ; Comece S: = [#8, '0' .. '9']; Se key = #8 , então saia; se não (chave em s) , então inicie a tecla: = #0; Saída; fim ; //控制输入数字的大小Se TEDIT (remetente) .selngth> 0 então inicie o texto: = TEDIT (remetente) .Text; Str: = cópia (texto, 1, TEDIT (remetente) .SelStart - 1) + chave + cópia (texto, tedit (remetente) .Selstart + tedit (remetente) .selngth + 1, comprimento (texto)); i: = strtoint (str); Se i> fmax , então inicie a tecla: = #0; Saída; fim ; END mais se strtoint (TEDIT (remetente) .text + key)> fmax e então inicie a tecla: = #0; Saída; END mais se strtoint (TEDIT (remetente) .text + key) <fmin e então inicie a tecla: = #0; Saída; fim ; fim ; procedimento tupdownedit.setMax (Valor const : Inteiro); Comece Fmax: = Value; Updown.max: = fmax; Se strTointDef (edit.Text, 0)> fmax , então inicie UpdOwn.Position: = fmax; Edit.Text: = inttostr (fmax); Fposition: = updOwn.Position; fim ; fim ; procedimento tupdownedit.setmin ( const valor: inteiro); Comece fmin: = value; UpdOwn.min: = fmin; Se strTointDef (edit.Text, 0) <fmin então inicie UpdOwn.Position: = fmin; Edit.Text: = inttostr (fmin); Fposition: = updOwn.Position; se atribuído (fonnchange) , então fonenchange (self); fim ; fim ; procedimento tupdownedit.setPosition (Valor const : Inteiro); Comece se (valor> = fmin) ou (value <= fmax) , então inicie a fposition: = value; UPDOWN.POSIÇÃO: = fposition; Edit.Text: = inttostr (fposition); se atribuído (fonnchange) , então fonenchange (self); fim ; fim ; procedimento tupdownedit.updownClick (remetente: TObject; botão: tudbtntype); Comece se max = 0 então inicie o máximo: = 100; Updown.max: = max; fim ; Updown.min: = min; Edit.Text: = inttostr (updOwn.Position); Edit.setFocus; Edit.Selectall; se atribuído (fonnchange) , então fonenchange (self); Fposition: = updOwn.Position; fim ; procedimento tupdownedit.wmsize ( var msg: twmsize); Begin Edit.Width: = Width - 15; Updown.left: = edit.width + 1; UpdOwn.Height: = altura; herdado ; fim ; fim .