泛型问题
泛型定义:
unit uGlobal;interfacetype Tiif<T> = class public class function iif<T>(bFlag: Boolean; aValue: T; bValue: T): T; end;implementation{ Tiif<T> }class function Tiif<T>.iif<T>(bFlag: Boolean; aValue, bValue: T): T;begin if bFlag then Result := aValue else Result := bValue; end;end.//如果只是过程需要泛型, 可以这么写Tiif = class public class function iif<T>(bFlag: Boolean; aValue: T; bValue: T): T; end;{ Tiif<T> }class function Tiif.iif<T>(bFlag: Boolean; aValue, bValue: T): T;begin if bFlag then Result := aValue else Result := bValue;end;var index : Integer;begin index := StrToInt(edt1.Text); Index := Tiif.iif<Integer>(Index < 7, index, 0); Caption := IntToStr(index);