我对DELPHI写的几个基类型[7]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 qiubolecn 的 blog

  result := ainteger;
end;

class function tinteger.inttostr(ainteger: int64): string;
begin
  result := sysutils.inttostr(ainteger);
end;

class function tinteger.isvalidint(astring: string): boolean;
begin
  result := true;
  try
    strtoint(astring);
  except
    result := false;
  end;
end;

class function tinteger.isvalidint64(astring: string): boolean;
begin
  result := true;
  try
    strtoint(astring);
  except
    result := false;
  end;
end;

class function tinteger.maxint: integer;
begin
  result := system.maxint;
end;

class function tinteger.maxlongint: integer;
begin
  result := system.maxlongint;
end;

class function tinteger.inttobin(ainteger: cardinal): string;
var
  i: integer;
begin
  setlength(result, 32);
  for i := 1 to 32 do
  begin
    if ((ainteger shl (i-1)) shr 31) = 0 then
      result[i] := '0'
    else
      result[i] := '1';
  end;

end;

class function tinteger.inttohex(ainteger: integer): string;
begin
  result := sysutils.inttohex(ainteger, 0);
end;

class function tinteger.hextoint(astring: string): integer;
begin
  if tstring.left(astring, 1) = '$' then
    result := strtoint(astring)
  else
    result := strtoint('$' + astring);   
end;

class function tinteger.makeserialno(ainteger, adigit: integer): string;
var
  tmpstr: string;
  i: integer;
begin
  tmpstr := '';
  for i := 0 to adigit - 1 do    // iterate
  begin
    tmpstr := tmpstr + '0';
  end;    // for

  result := formatfloat(tmpstr, ainteger);

end;

{ tfloat }

class function tfloat.floattomoney(const value: double; round: boolean): string;
begin
  //金额默认采用四舍五入
 
end;

class function tfloat.isvalidfloat(astring: string): boolean;
begin
  result := true;
  try
    strtofloat(astring);
  except
    result := false;
  end;
end;

class function tfloat.maxdouble: double;
begin
  result := 1.7e+308;
end;

class function tfloat.maxextended: extended;
begin
  result := 1.1e+4932;
end;

class function tfloat.mindouble: double;
begin
  result := 5.0e-324;
end;

class function tfloat.minextended: extended;
begin
  result := 3.4e-4932;
end;

class function tfloat.samevalue(const a, b: single;
  epsilon: single): boolean;
begin
  result := math.samevalue(a, b, epsilon);
end;

class function tfloat.samevalue(const a, b: double;
  epsilon: double): boolean;
begin
  result := math.samevalue(a, b, epsilon);
end;

class function tfloat.samevalue(const a, b: extended;
  epsilon: extended): boolean;
begin
  result := math.samevalue(a, b, epsilon);
end;

{ tboolean }

class function tboolean.booltostr(aboolean: boolean): string;
begin
  if aboolean then
    result := 'true'
  else
    result := 'false';         
end;

class function tboolean.strtobool(astring: string): boolean;
begin
  if uppercase(astring) = 'true' then
    result := true
  else
    result := false;
   
end;

end.

本文关键:我对DELPHI写的几个基类型
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top