测试1
//校验文本框 function fCheckEdit(aForm:TForm) : Boolean; var I : Integer; mmName,mmFLag,mmTxt : string; mmCurr : Currency; begin Result := False; try for i := 0 to aForm.ControlCount-1 do begin //aForm.Controls[i].ClassName if not (aForm.Controls[i] is TEdit) then Continue; (aForm.Controls[i] as TEdit).Text := Trim((aForm.Controls[i] as TEdit).Text); mmName := aForm.Controls[i].Name; mmFlag := Copy(mmName,1,1); //校验标志 mmTxt := (aForm.Controls[i] as TEdit).Text; if (mmFlag='c') and (mmTxt='') then begin f_ShowTS(YY('不允许为空值!')); (aForm.Controls[i] as TEdit).SetFocus; Exit; end; if (mmFlag='n') and (not TryStrToCurr(mmTxt,mmCurr)) then begin f_ShowTS(YY('必须为数值!')); (aForm.Controls[i] as TEdit).SetFocus; Exit; end; end; Result := True; except end; end;
测试2
1 //校验文本框 2 function fCheckEdit(aForm:TForm) : Boolean; 3 var 4 I : Integer; 5 mmName,mmFLag,mmTxt : string; 6 mmCurr : Currency; 7 begin 8 Result := False; 9 try 10 for i := 0 to aForm.ControlCount-1 do begin //aForm.Controls[i].ClassName 11 if not (aForm.Controls[i] is TEdit) then Continue; 12 (aForm.Controls[i] as TEdit).Text := Trim((aForm.Controls[i] as TEdit).Text); 13 14 mmName := aForm.Controls[i].Name; 15 mmFlag := Copy(mmName,1,1); //校验标志 16 mmTxt := (aForm.Controls[i] as TEdit).Text; 17 if (mmFlag='c') and (mmTxt='') then begin 18 f_ShowTS(YY('不允许为空值!')); 19 (aForm.Controls[i] as TEdit).SetFocus; 20 Exit; 21 end; 22 23 if (mmFlag='n') and (not TryStrToCurr(mmTxt,mmCurr)) then begin 24 f_ShowTS(YY('必须为数值!')); 25 (aForm.Controls[i] as TEdit).SetFocus; 26 Exit; 27 end; 28 end; 29 Result := True; 30 except 31 end; 32 end;View Code