大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> delphi一句话帮助

delphi一句话帮助

时间: 2021-07-31 作者:daque

 1.即使想你的步调不妨精确处置特殊情景的话,请援用sysutils.pas单位,要不纵然步调运用了try。。。except。。。也不许精确捕捉特殊。

2.设置恒量字符串的一种办法

resourcestring

    aa='aaaa';

raise exception.createres(@aa);

3.字符串恒量数组的初始化

const  constarray:array [0..2] of string=(‘first’,’second’,’third’);

4. 构造体初始化

type  tstructinit=record

   a1:integer;

   a2:array [0..2] of integer;

end;

const m_structinit:tstructinit=(a1:0;a2:(0,1,2));

5.多维数组的长度

var  array2:array of array of integer;

setlength(array2,2,2);

6.运用create和new开拓的空间都生存于堆中,不许机动开释,倡导运用freeandnil开释, 参数以及限制变量生存于栈中,机动开释。

7.sizeof不符合于东西,归来的老是4;对于恒定典型不妨精确归来.

8.create(nil)须要细工开释,creat(self)会跟着具有者的开释而开释.

9.动静变换已设置恒量的值

procedure changeconst(const const;var value;size:integer);

begin

  move((@value)^,(@constant)^,size);

end;

10.举行简略操纵的功夫轮回运用downto,会制止缺点.

11.中国字的ascii码>128,不妨用它来辨别能否为中国字

12.dll编写中,须要运用sharemem单位来援用borlandmm.dll外存处置.

13.postmessage只将动静放到动静部队中,须要列队等候处置。

sendmessage绕过动静部队径直发送给窗口进程,比及动静处置归来值才归来.

14.鼠标移入移出动静:cm_mouseenter,cm_mouseleave

15.关灯动静wm_queryendsession

16.不妨运用thintwindow和类的本领activatehint来创造浮动窗体.

17.调出文献属性对话框

uses shellapi;

function showfileproperties(filename: string; wnd: hwnd):boolean;

var

  sfi: tshellexecuteinfo;

begin

  with sfi do

  begin

    cbsize := sizeof(sfi);

    lpfile := pansichar(filename);

    wnd := wnd;

    fmask := see_mask_nocloseprocess or see_mask_invokeidlist or see_mask_flag_no_ui;

    lpverb := pansichar('properties');

    lpidlist := nil;

    lpdirectory := nil;

    nshow := 0;

    hinstapp := 0;

    lpparameters := nil;

    dwhotkey := 0;

    hicon := 0;

    hkeyclass := 0;

    hprocess := 0;

    lpclass := nil;

  end;

  result := shellexecuteex(@sfi);

end;

 

procedure tform1.button1click(sender: tobject);

begin

   showfileproperties('c:\aa.txt', handle);

end;

18.变动体例功夫

uses windows,dialogs,forms;

var mytime:tsystemtime;

begin

  fillchar(mytime,sizeof(mytime),#0);

  mytime.wyear:=2003;

  mytime.wmonth:=06;

  mytime.wday:=01;

  if not setsystem(mytime) then

showmessage(‘failure’);

   end;

19.复制文献夹xcopy

.   procedure xcopy(sourcedir,destinationdir:string);

    var

      search : tsearchrec;

     rec    : word;

begin

     sourcedir := sourcedir + '\';

      rec := findfirst(sourcedir + '*.*', faanyfile, search);

     while rec = 0 do

      begin

        if search.name[1] <> '.' then

        begin

          if (search.attr and fadirectory) = fadirectory then

          begin

            windows.createdirectory(pchar(destinationdir + '\' + search.name), nil);

            filesetattr(destinationdir + '\' + search.name, filegetattr(sourcedir + '\' + search.name));

            x_copy(sourcedir + '\' + search.name, destinationdir + '\' + search.name);

          end

          else

          begin

            copyfile(pchar(sourcedir + '\' + search.name),pchar(destinationdir + '\' + search.name), true);

            filesetattr(destinationdir + '\' + search.name, filegetattr(sourcedir + '\' + search.name));

            application.processmessages;

          end;

        end;

        rec := findnext(search);

      end;

      findclose(search);

end;

20.绘制通明位图

   procedure drawtrans(destcanvas: tcanvas; x,y: smallint; srcbitmap: tbitmap; acolor, backcolor: tcolor);

var  andbitmap, orbitmap: tbitmap;

         cm: tcopymode;

         src: trect;

begin

      andbitmap:= nil;

      orbitmap:=  nil;

      try

        andbitmap:= tbitmap.create;

        orbitmap:= tbitmap.create;

        src  := bounds(0,0, srcbitmap.width, srcbitmap.height);

        with orbitmap do begin

          width:= srcbitmap.width;

          height:= srcbitmap.height;

          canvas.brush.color := clblack;

          canvas.copymode := cmsrccopy;

          canvas.brushcopy(src, srcbitmap, src, acolor);

        end;

        with andbitmap do begin

          width:= srcbitmap.width;

          height:= srcbitmap.height;

         canvas.brush.color := backcolor;

         canvas.copymode := cmsrcinvert;

         canvas.brushcopy(src, srcbitmap, src, acolor);

       end;

       with destcanvas do begin

         cm := copymode;

         copymode := cmsrcand;

         draw(x,y, andbitmap);

         copymode := cmsrcpaint;

         draw(x,y, orbitmap);

         copymode := cm;

       end;

     finally

       andbitmap.free;

       orbitmap.free;

     end;

end;

 

procedure tform1.button4click(sender: tobject);

begin

    drawtrans(image1.canvas, 0,0, image2.picture.bitmap, clblack, clsilver);

end;

21.获得cpu速率

  function getcpuspeed: extended;

var

    t, mhi, mlo, nhi, nlo: dword;

    shr32 : comp;

begin

    shr32 := 65536;

    shr32 := shr32 * 65536;

    t := gettickcount;

    while t = gettickcount do ;

      asm

      db 0fh,031h // rdtsc

      mov mhi,edx

      mov mlo,eax

    end;

    while gettickcount < (t + 1000) do ;

      asm

      db 0fh,031h // rdtsc

      mov nhi,edx

      mov nlo,eax

    end;

    result := ((nhi * shr32 + nlo) - (mhi * shr32 + mlo)) / 1e6;

end;

 

procedure tform1.button4click(sender: tobject);

begin

    label1.caption := floattostr(getcpuspeed) + 'mhz';

end;

   

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.