zoukankan      html  css  js  c++  java
  • Delphi 你不知道的函数

    技术交流,DH讲解.

    在Sysutils.pas有几个函数,以前我也没有看见过,今天看源码的时候无意间发现了.

    function GDAL: LongWord;
    type
      TDVCLAL = array[0..3] of LongWord;
      PDVCLAL = ^TDVCLAL;
    var
      P: Pointer;
      A1, A2: LongWord;
      PAL1s, PAL2s: PDVCLAL;
      ALOK: Boolean;
    begin
      P := ALR;//从资源文件获得
      if P <> nil then
      begin
        A1 := AL1(P^);
        A2 := AL2(P^);
        Result := A1;
        PAL1s := @AL1s;
        PAL2s := @AL2s;
        ALOK := ((A1 = PAL1s[0]) and (A2 = PAL2s[0])) or
                ((A1 = PAL1s[1]) and (A2 = PAL2s[1])) or
                ((A1 = PAL1s[2]) and (A2 = PAL2s[2]));
        FreeResource(Integer(P));
        if not ALOK then ALV;//抛出异常,说Application is not licensed to use this feature
      end
      else Result := AL1s[3];
    end;

    这个函数全称Get Delphi Access Licences,这个函数去读取资源里面的访问许可,如果不合法就抛出异常,如果合法就返回解密后的AL1。里面用到的两个函数:

    const
      AL1s: array[0..3] of LongWord = ($FFFFFFF0, $FFFFEBF0, 0, $FFFFFFFF);
      AL2s: array[0..3] of LongWord = ($42C3ECEF, $20F7AEB6, $D1C2F74E, $3F6574DE);
    
    procedure ALV;
    begin
      raise Exception.CreateRes(@SNL);
    end;
    
    function ALR: Pointer;
    var
      LibModule: PLibModule;
    begin
      if MainInstance <> 0 then
        Result := Pointer(LoadResource(MainInstance, FindResource(MainInstance, 'DVCLAL',
          RT_RCDATA)))
      else
      begin
        Result := nil;
        LibModule := LibModuleList;//这里是一个链表,其实想学习链表的朋友可以来看看
        while LibModule <> nil do//遍历链表
        begin
          with LibModule^ do
          begin
            Result := Pointer(LoadResource(Instance, FindResource(Instance, 'DVCLAL',
              RT_RCDATA)));
            if Result <> nil then Break;
          end;
          LibModule := LibModule.Next;
        end;
      end;
    end;

    紧接着下面有个函数用到GDAL了,也就是GDAL没有直接被用到:

    procedure RCS;
    var
      P: Pointer;
      ALOK: Boolean;
    begin
      P := ALR;
      if P <> nil then
      begin
        ALOK := (AL1(P^) = AL1s[2]) and (AL2(P^) = AL2s[2]);
        FreeResource(Integer(P));
      end
      else
        ALOK := False;
      if not ALOK then
        ALV;
    end;
    
    procedure RPR;
    var
      AL: LongWord;
    begin
      AL := GDAL;
      if (AL <> AL1s[1]) and (AL <> AL1s[2]) then
        ALV;
    end;

    函数RCS:检查是否有合法的Delphi Client Server许可,不合法就异常.
    函数RPR:检查是否有合法的Delphi Pro 许可,不合法就异常.

    从上面看,这两个函数我们平时基本用不着了,也是,这两个函数在自带的VCL里面有.有兴趣的朋友可以自己看一下.

    OK

  • 相关阅读:
    部署 AppGlobalResources 到 SharePoint 2010
    还原一个已删除的网站集
    使用仪表板设计器配置级联筛选器 (SharePoint Server 2010 SP1)
    File or arguments not valid for site template
    Pex and Moles Documentation
    Content Query Webpart匿名访问
    Running Moles using NUnit Console from Visual Studio
    Calling a WCF Service using jQuery in SharePoint the correct way
    Updating Content Types and Site Columns That Were Deployed as a Feature
    asp.net中判断传过来的字符串不为空的代码
  • 原文地址:https://www.cnblogs.com/huangjacky/p/1702884.html
Copyright © 2011-2022 走看看