zoukankan      html  css  js  c++  java
  • 问题-枚举类型为什么不支持点引用?

    问题现象:同事问我个问题,说同一个枚举类型名,在多个单元中出现,怎么指定?我说用点引用,比如说“Tmytype.My1”,可是在D2007报红。

    问题原因:可能是因为我用XE时间长了,把D7的老特性给忘了。

    问题处理:如果是老版本还是用老办法吧,新版本还是好用的。

    实例代码(枚举类型): 

     1 unit Unit2;
     2 
     3 
     4 interface
     5 
     6 type
     7   TMyType = (My1,My2,My3);
     8 
     9 implementation
    10 
    11 end.
    View Code

    实例代码(调用单元): 

     1 unit Unit1;
     2 
     3 interface
     4 
     5 uses
     6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
     7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
     8 
     9 type
    10   TForm1 = class(TForm)
    11     Button1: TButton;
    12     procedure Button1Click(Sender: TObject);
    13   private
    14     { Private declarations }
    15   public
    16     { Public declarations }
    17   end;
    18 
    19 var
    20   Form1: TForm1;
    21 
    22 implementation
    23 uses
    24   Unit2;//引用枚举类型所在单元
    25 {$R *.dfm}
    26 
    27 procedure TForm1.Button1Click(Sender: TObject);
    28 var
    29   tMy: TMyType;       //定义一个类型变量
    30 begin
    31   tMy := Unit2.My1;   //XE10.2 D7都支持
    32   tMy := Tmytype(0);  //XE10.2 D7都支持
    33   tMy := Tmytype.My1; //XE10.2支持 D2007 D7不支持
    34   tMy := Tmytype(My1);//XE10.2支持,但我感觉没有意义
    35 end;
    36 
    37 end.
    View Code
  • 相关阅读:
    Sobel边缘检测(2)-matlab
    Sobel边缘检测(1)
    FPGA-高斯滤波
    MySQL 常用30种SQL查询语句优化方法
    探索测试
    下拉菜单的选取
    163邮箱登录账号密码定位的问题
    python编码
    selenium python 如何控制网页内嵌div中滚动条的滚动
    Chrome正收到自动测试软件的控制 怎么去掉
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/7905038.html
Copyright © 2011-2022 走看看