ITPub博客

首页 > Linux操作系统 > Linux操作系统 > delphi一句话帮助终 (转)

delphi一句话帮助终 (转)

原创 Linux操作系统 作者:amyz 时间:2007-08-15 14:50:52 0 删除 编辑
delphi一句话帮助终 (转)[@more@]

1.  产生随机密码(应该比较有用)XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />

  function CreatePass:String;

const

   MAX_LEN=10;

var

   i: integer;

   s: string;

begin

   Randomize;

   s:='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+'abcdefghijklmnopqrstuvwxyz'+ '0123456789';

   Result := '';

   for i := 0 to MAX_LEN-1 do

   begin

   Result := Result + s[Random(Length(s)-1)+1];

   end;

end;

2.  十进制数字转换成罗马数字

  function DecToRoman(idecimal: longint): string;

const

   aRomans: array[1..13] of string = ('I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC',

   'C', 'CD', 'D', 'CM', 'M');

   aArabics: array[1..13] of integer = (1, 4, 5, 9, 10, 40, 50, 90, 100, 400,

   500, 900, 1000);

var

   i: integer;

begin

   result := '';

   for i := 13 downto 1 do

   while (iDecimal >= aArabics[i]) do

   begin

   iDecimal := iDecimal - aArabics[i];

   result := result + aRomans[i];

   end;

end;

 

procedure TForm1.Button1Click(Sender: Tobject);

begin

   showmessage(DecToRoman(5));

end;

3.  格式化整数显示

使用FormatFloat函数可以解决你很多问题。例如把1200000格式化为1,200,000输出

procedure TForm1.Button1Click(Sender: TObject);

var

  i:integer;

  s:string;

begin

  i := 1200000;

  s := FormatFloat('#,0', i);

  showmessage(s);

end;

4.  判断串口是否收到了数据可以使用ClearCommError函数,TcomStat结构体中cbInQue,cbOutQue可以帮助实现判断。

5.  RGB颜色转换为TColor类

  function RGBToColor(R,G,B:Byte): TColor;

begin

   Result:=B Shl 16 Or

   G Shl 8 Or

   R;

end;

6.  把TColor转换为RGB值

  procedure TForm1.Button1Click(Sender: TObject);

var

   Color: TColor;

   R, G, B: Integer;

begin

   Color := clBlack;

   R := Color and $FF;

   G := (Color and $FF00) shr 8;

   B := (Color and $FF0000) shr 16;

   showmessage(inttostr(R));

   showmessage(inttostr(G));

   showmessage(inttostr(B));

end;

7.  浏览计算机对话框

uses ShlObj;

function BrowseForComputer(const winhandle : THANDLE; const title : string) : string;

var

  BrowseInfo: TBrowseInfo;

  IDroot: PItemIDList;

  Path: array[0..MAX_PATH] of Char;

begin

  SHGetSpecialFolderLocation(winHandle, CSIDL.NETWORK, IDRoot);

  ZeroMemory(@BrowseInfo, SizeOf(TBrowseInfo));

  ZeroMemory(@path, MAX_PATH);

  BrowseInfo.hwndOwner := winhandle;

  BrowseInfo.pidlRoot := IDRoot;

  BrowseInfo.lpszTitle := PChar(title);

  BrowseInfo.pszDisplayName := @path;

  BrowseInfo.ulFlags:=BIF_BROWSEFORCOMPUTER;

  SHBrowseForFolder(BrowseInfo);

end;

 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-958275/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3982
  • 访问量
    7895765