Unité UpdownEDIT; L'interface utilise Windows, Sysutils, Classes, Controls, Stdctrls, ComCtrls, Messages; Type TupdowneDit = classe (tCustomControl) privé {Déclarations privées} Updown: Tupdown; Edit: Tedit; Fmin: entier; Fmax: entier; FonChange: tnotifyEvent; FPOSITION: entier; Procédure WMSIZE ( VAR MSG: TWMSIZE); message wm_size; Procédure setMax ( const Value: Integer); procédure setmin ( const de valeur: entier); procédure editchange (expéditeur: tobject); Procédure EditKeyPress (expéditeur: tobject; clé VAR : char); Procédure UpdownClick (expéditeur: tobject; bouton: TudBtntype); procédure setPosition (constamment de const : entier); protégé {Déclarations protégées} publique {Déclarations publiques} Constructor Create (Aowner: TComponent); remplacer ; destructeur détruire; remplacer ; publié {Déclarations publiées} Property Max: Integer Read Fmax Write SetMax; propriété min: entier read fmin write setmin; Position de la propriété : entier lue fpositive write setPosition; Propriété OnChange: TnotifyEvent Read FonChange Write FonChange; fin ; Registre de procédure ; Registre des procédures de mise en œuvre ; commencer RegisterComponents («Standard», [TupdownEdit]); fin ; {TupdowneDit} Constructor TupdownEdit.Create (Aowner: TComponent); commencer hérité de créer (aowner); SetBounds (0, 0, 57, 21); Edit: = tedit.create (self); Edit.left: = 0; Edit.top: = 0; Edit.width: = 40; Edit.align: = prest; 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: = hauteur; // 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; fin ; destructor Tupdownedit.destroy; commencer edit.free; Updown.free; hérité ; fin ; Procédure TupdownEdit.editchange (expéditeur: tobject); begin updown.position: = strTointDef (edit.Text, 0); FPosition: = updown.position; si elle est attribuée (FonChange) alors FonChange (self); fin ; Procédure TupdownEdit.EditKeyPress (expéditeur: tobject; clé var : char); var s: ensemble de char; I: entier; Str, texte: chaîne ; commence s: = [# 8, '0' .. '9']; Si key = # 8 alors sortez; Sinon (clé en s) , commencez la touche: = # 0; Sortie; fin ; //控制输入数字的大小Si Tedit (expéditeur) .Sellngth> 0 alors commencez le texte: = TeDit (expéditeur) .Text; Str: = copy (text, 1, Tedit (expéditeur) .selStart - 1) + key + copy (text, Tedit (expéditeur) .SeLStart + Tedit (expéditeur) .Sellngth + 1, longueur (texte)); i: = strToint (str); Si i> fmax , commencez la clé: = # 0; Sortie; fin ; fin d'autre si strToint (Tedit (expéditeur) .Text + clé)> fmax puis commencez la touche: = # 0; Sortie; fin d'autre si strToint (Tedit (expéditeur) .Text + key) <fmin alors commencez la touche: = # 0; Sortie; fin ; fin ; Procédure TupdownEdit.SetMax ( const Value: Integer); commencer fmax: = valeur; Updown.max: = fmax; Si strTointDef (edit.Text, 0)> fmax , commencez à mettre à jour.position: = fmax; Edit.text: = intToStr (fmax); FPosition: = updown.position; fin ; fin ; Procédure TupdownEdit.setMin ( const Value: Integer); commencer fmin: = valeur; Updown.min: = fmin; Si strTointDef (édition.Text, 0) <fmin , commencez à updown.position: = fmin; Edit.text: = intToStr (fmin); FPosition: = updown.position; si elle est attribuée (FonChange) alors FonChange (self); fin ; fin ; Procédure TupDowneDit.SetPosition ( const Value: Integer); commencer if (valeur> = fmin) ou (valeur <= fmax) puis commencer fPosition: = valeur; Updown.position: = fPosition; Edit.text: = intToStr (fPosition); si elle est attribuée (FonChange) alors FonChange (self); fin ; fin ; Procédure TupdownedIdit.updownClick (expéditeur: tobject; bouton: TudBtntype); commencer si max = 0 alors commencez max: = 100; Updown.max: = max; fin ; Updown.min: = min; Edit.text: = intToStr (updown.position); Edit.setfocus; Edit.selectall; si elle est attribuée (FonChange) alors FonChange (self); FPosition: = updown.position; fin ; Procédure TupDowneDit.wmSize ( var msg: twmSize); commencer edit.width: = largeur - 15; Updown.left: = edit.width + 1; Updown.height: = hauteur; hérité ; fin ; fin .