BCB运行期取得Enum(枚举)类型信息

BCB版串口枚举 一个老外的串口枚举程序,bcb6.0版,测试正常,可以设置FIFO,win7及以上程序需以管理员身份启动。 立即下载

由于Pascal和C++的本质区别,在Delphi里面强大的RTTI功能,BCB中就被相对弱化了很多。
不过即便如此,BCB仍然可以享受TObject带来的好处,
虽然我们不能够直接使用在delphi下十分方便的GetEnumName。

 

我们还是不需要为每个枚举类型实现一个静态的String列表。

考虑一下如下的宏实现,为了享受TObject的好处,我们需要从它继承一个VCL子类,

并且为这个类声明一个属性,使得我们可以使用GetPropInfo来取得ENUM类型信息。

 

#include <TYPINFO.HPP>

 

#define Marco_PrepareEnumerateName(ENUM)  /

class ___TEnumObject___ : TObject         /

{                                         /

  ENUM _se;                               /

__published:                              /

  __property ENUM Prop ={read=_se};       /

};                                        /

AnsiString GetEnumName(const ENUM& value) /

{                                         /

                                          /

  PPropInfo aPropInfo = GetPropInfo(__typeinfo(___TEnumObject___), "Prop"); /

  if (aPropInfo)                                                            /

  {                                                                         /

    return GetEnumName(*(aPropInfo->PropType), int(value));                 /

  }                                                                         /

  return "";                                                                /

}

 

 

有了这个宏的实现,使得将来取得enum类型的时候,事情变得更加容易。

本来计划使用template技术来实现的,但是__property声明后不允许使用模板参数。所以作罢。

//以下为测试代码 

typedef enum {xxx,yyy,zzz,eee,ffff} TSampleEnum;

Marco_PrepareEnumerateName(TSampleEnum)

 

void __fastcall TForm1::Button1Click(TObject *Sender)

{

  Caption = GetEnumName(xxx);

}

BCB6.0四种方法枚举电脑串口 BCB6.0用四种方法枚举电脑串口,第四种有个小bug,暂时没时间详查 立即下载

相关推荐

海康视觉平台VisionMaster实战入门:从通讯配置到工具应用

本文为海康VisionMaster视觉平台实战入门指南,详细介绍了从软件安装准备、与PLC等外部设备的通讯配置,到匹配定位、测量、畸变矫正等核心工具的应用方法。通过实战案例拆解,帮助工程师快速掌握如何搭建完整的机器视觉检测与引导定位系统,实现工业自动化项目落地。

weixin_29224309的博客 1035

BCB的属性编辑器

Delphi Open Tools API 浅探 - 属性编辑器savetime2k@yahoo.com  2004.1.26http://savetime.delphibbs.com昨天开始学习 Delphi Open Tools API,第一站是 TPropertyEditor。在阅读 VCL 源码时发现了不熟悉的 interface 操作,只好临时学习了 interface。花了二天时间大概

冷剑魂的专栏——垃圾场 1848

史上最强量化工具库 Ta-Lib 从入门到精通,一篇文章就够了!

Ta-Lib 提供的 13 个关键指标,并配上详细的代码示例,确保你看完就能直接上手!🔥。

奔跑的蜗牛 9962

用RTTI处理程序配置信息

一般来说,程序多少都会有一些自己的配置信息要保存,不论是通常用的保存到INI还是注册表,或者是XML甚至YAML,总归是要写不少代码处理的。问题的麻烦在于,程序中实现操作配置信息通常并不需要关注它是保存在什么地方,以什么格式保存,但是传统的方法不论是调用TIniFile还是TRegistry或者是DOM,都是需要开发者花一些时间精力浪费在这上面。我前一阵写个小程序,不高兴弄配置这些麻烦事,

猛禽的编程艺术 3527

全国30米分辨率逐年植被覆盖度(FVC)数据集

植被覆盖度是描述地表植被的重要参数与生态环境的基本指标,在大气圈、土壤圈、水圈和生物圈中都占据着重要的地位,区域及全球范围的植被覆盖度估算对植被及相关领域的研究具有重要意义。分别对LANDSAT 5/7/8系列数据计算FVC,其中Landsat5 和Landsat 7NDVI计算利用 B4和B3波段,Landsat8 和Landsat9 NDVI计算利用 B5和B4波段。算法从当年所有观测数据中,以低云、低探测角度和最高NDVI值为标准,选择最佳的可用像元值,并进行换算。(3) FVC的计算。

地球资源数据云的官方博客 1818

STM32F103C8T6最小系统板GPIO配置避坑指南:从原理图到流水灯一次成功

本文详细介绍了STM32F103C8T6最小系统板GPIO配置的实战指南,从硬件准备到流水灯实现,涵盖了九大关键步骤。特别针对新手常见问题,如GPIO配置、开发环境搭建和程序下载调试,提供了详细的解决方案和避坑技巧,帮助开发者快速掌握STM32开发基础。

weixin_33756596的博客 347

BCB版的串口枚举

做自控近20年,脱离不了串口通信。原来需要获取电脑的串口时,采用的是读取注册表法,一直以来也使用正常。除非电脑系统问题造成多余的虚拟串口或usb串口号,清理下注册表即可:  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control \COM Name Arbiter,  删除数值项ComDB即可。 但是随着业务的扩展,面对

gongzhu110的专栏 1058

BERT之提取特征向量 及 bert-as-server的使用

本文内容列表提取句向量1、句向量简介1-1传统句向量1-2、BERT句向量2、 extract_features.py源码分析2-1 main函数 前一篇文章 BERT介绍及中文文本相似度任务实践 简单介绍了使用BERT进行中文文本相似度计算的方法,这篇文章着重对特征提取方法进行讲述。 提取句向量 1、句向量简介 1-1传统句向量 更多采用word embedding的方式取加权平均,该方法的一大...

ling620的专栏 1万+

【转】C++中enum枚举类型成员重名问题的解决方法 - Enum枚举类型的类封装

//C#就没有这个问题,有兴趣可以去看看,抛砖引玉一下。C++毕竟还是有些进化不完整。 C++语言中,对于一个枚举类型(enum),其成员值在所属枚举类型的声明作用域内是不可重复的。这个继承自C语言的特性,使我在写程序时碰到有相同名称的枚举成员时,苦于寻找且方便易读的替代枚举名称。 这在C++程序开发方面带来了许多的不方便,在涉及枚举类型时必须时刻关注与现有的枚举变量是否有重名,在一定程度

ACM 【程式=演算法+資料結構】@蜡笔小轩V 1554

【STM32Cube HAL】输入捕获(六)——脉宽测量

1

HAHAHA 4913

msf后渗透之获取登入password、远程控制、调用摄像头

在terminal输入load kili creds_all直接获取密码(不一定成功) 使用kiwi_cmd sekurlsa::logonpasswords获取密码

m0_61506558的博客 2964

取得枚举类型enum中的元素名称

此例应用了VCL的RTTI机制...#include enum number {One,Two,Three,Four,Five,Six};class TForm1 : public TForm{...private: number FNum;__published: __property number Num = { read = FNum };};.CPP文件

Compile failed 4791

PyCharm 怎么不升级直接使用Jupyter Notebook

在PyCharm 中需要升级到 PyCharm Professional 版本,才能直接使用 Jupyter Notebook。从截图来看,Jupyter Notebook 已经成功启动,并且正在运行。这将在默认网络浏览器中打开一个新的标签页,显示文件浏览器界面。可以在这里创建和编辑。文件添加到 PyCharm 项目中,并使用纯文本编辑功能进行修改。支持与外部工具集成,可以配置它以调用命令行工具或脚本来启动。,参数可以根据需要设置,工作目录设置为项目根目录。,你仍然可以在本地环境中安装和运行。

Davina_yu的博客 1005

C++枚举使用

关于enum class与enum struct以及普通枚举的实例

走在成长的路上 1万+

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

C++中enum的大小

关于枚举类型所占内存的大小,书里对枚举大小的定义是:sizeof枚举是sizeof某类可以包含枚举range的整型,并且不会大于sizeof(int)。也就是说枚举大小不一定等于sizeof(int)。  比如在一个sizeof(int)等于4的机器上,sizeof枚举有可能是1或者4,但不会是8 。 要想强制enum等于一个固定长度,就要定义一个最大的长度放入enum定义中。 比如

y020142014的专栏 3432

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

15 如何从枚举中获得枚举项名称值

(1) 使用Enum.GetName() (2) 使用ToString()方法 public enum AuthMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } stat

乌英达姆的博客 3447

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

C++builder enum类型

C/C++ code #pragma option push -b- enum TThreadPriority { tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest, tpTimeCritical }; //这是字节型的.理论上说这是可能的最小整形.可以是1Byte, 2Bytes, 4Bytes... #pragma op

芒果儿 1204

enum,struct,union类型使用和长度

VC,C++ Builder和lcc三个编译器 间枚举类型enum长度的情况. 各种C编译器默认的字节对齐数不一致,要写通用的代码,经常就是使用 #pragma pack(1) ... #pragma pack() 来使编译器以单字节对齐. 今天在bcb5中调用vc6的dll时出现错误,但在VC中调用dll却很正常,说明很有可能是编译器之间的差异造成.仔细debug后发现b...

weixin_33871366的博客 208

usb的旅途之枚举

前面列出了usb枚举过程的大体流程,现在来看一下usb枚举过程的详细分析  USB命令与设备描述符之开发详解 首先列出枚举过程中抓的数据包     /***************************************************************************/ Bus Hound 5.00 capture. Complements of w

射频匠人 909

给枚举常量编写方法

import java.util.*;import java.text.*;public enum ChangLiangFangFa{      ONE{           String getInfo(){return "文萧骋";}},      TWO{           String getInfo(){return "刘梓毅";}},      THR

刘利新 421

Windows 笔记本内屏变暗、亮度调不上去:一次显示器驱动枚举异常的排查修复

本文记录了Windows笔记本内屏变暗且亮度调节失效问题的排查修复过程。作者通过检查电源计划、WMI亮度接口和屏幕设备状态,发现内屏被错误识别为"Generic Monitor"且未正确绑定系统监视器驱动。最终通过移除错误设备实例并重新扫描硬件,使系统重新识别为"通用即插即用监视器"并绑定monitor.inf驱动,成功恢复了亮度调节功能。文章提供了完整的排查步骤和PowerShell命令,指出类似问题可能是由设备枚举异常而非硬件或电源设置问题导致。

小时候超帅的博客 321

HarmonyOS6 PC 动画开发实战:五种 Curve 曲线类型,到底该选哪个?

做 HarmonyOS6 PC 端开发的时候,动画这个东西真的是"一看就会,一做就废"。很多开发者(包括我自己)写动画的时候最常干的事情就是:duration 给个 300,curve 用个默认的,然后就不管了。直到有一天产品经理过来说"这个动画怎么这么生硬",才意识到——。今天咱们就把 HarmonyOS ArkUI 里的 Curve 枚举彻底搞明白。不搞虚的,直接上对比,让你看完就知道什么场景用什么曲线。

qq_37048082的博客 1920

mysql bcmod_mysql基础学习笔记

1、登录数据库。mysql -uroot -pxxxx -h127.0.0.1 -P3306 --prompt xxxprompt xxx可更改提示符 \D表示完整的日期; \d表示当前数据库;\h服务器名称;\u当前用户。2、显示select version(); 显示版本select now();显示时间select user();显示用户3、创建数据库create database xx...

weixin_31616803的博客 215
上一篇: ADOQuery的Parameter问题
下一篇: 用代码控制新建Console的位置大小
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址