TDictionary 是delphi用的,c++builder用起来太吃力。
TDictionary 是delphi用的,c++builder用起来太吃力。
c++还是用std::map代替。
c++d map很好用啊。
https://blog.csdn.net/ddkxddkx/article/details/6555754
#include <map> void __fastcall TForm2::FormCreate(TObject *Sender)
{
std::map<String, String> *Dir = new std::map<String, String>;
delete Dir;
} Or: #include <map> void __fastcall TForm2::FormCreate(TObject *Sender)
{
std::map<String, String> Dir;
}
Copy the following code in your DelphiUnit.pas file:
unit DelphiUnit; interface uses
System.Generics.Collections; type
TCity = class
Country: String;
Latitude: Double;
Longitude: Double;
end; // You cannot use TDictionary<String, TCity> in C++ unless you first
// instantiate it in Delphi as follows:
CityDictionary = class(TDictionary<String, TCity>)
end; implementation end.
Then right-click your DelphiPackage project on the Project Manager and select Build.
Add the generated Delphi package library file to your C++ console application:
- Right-click your CppApplication project on the Project Manager and select Add.
- On the dialog box that opens, select the DelphiPackage.lib file that you previously built and click OK. You may find this file inside "C:\Users\Public\Documents\Studio\14.0\Dcp".
- Note: If you cannot see the expected file, ensure that the file filter in the dialog box is "Any file (*.*)".
Copy the following code in your main.cpp file:
#pragma hdrstop
#pragma argsused #ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif #include <iostream>
#include <DelphiUnit.hpp> const double EPSILON = 0.0000001; int _tmain(int argc, _TCHAR* argv[])
{
// Create the dictionary.
TDictionary__2<UnicodeString, TCity*>* dictionary = new TDictionary__2<UnicodeString, TCity*>();
TCity* city; // Add some key-value pairs to the dictionary. city = new TCity;
city->Country = "Romania";
city->Latitude = 47.16;
city->Longitude = 27.58;
dictionary->Add("Iasi", city); city = new TCity;
city->Country = "United Kingdom";
city->Latitude = 51.5;
city->Longitude = -0.17;
dictionary->Add("London", city); city = new TCity;
city->Country = "Argentina";
city->Latitude = ; // Wrong coordinates
city->Longitude = ; // on purpose.
dictionary->Add("Buenos Aires", city); // Display the current number of key-value entries.
std::wcout << "Number of pairs in the dictionary: " << dictionary->Count << "." << std::endl; // Try looking up "Iasi".
if (dictionary->TryGetValue("Iasi", city))
std::wcout << "Iasi is located in " << city->Country
<< " with latitude = " << city->Latitude
<< " and longitude = " << city->Longitude
<< "." << std::endl;
else
std::wcout << "Could not find Iasi in the dictionary." << std::endl; // Remove the "Iasi" key from the dictionary.
dictionary->Remove("Iasi"); // Make sure that the capacity of the dictionary is set to the number of entries.
dictionary->TrimExcess(); // Test if "Iasi" is a key in the dictionary.
if (dictionary->ContainsKey("Iasi"))
std::wcout << "The key \"Iasi\" is in the dictionary." << std::endl;
else
std::wcout << "The key \"Iasi\" is not in the dictionary." << std::endl; if (dictionary->ContainsKey("London")) { // Test how (United Kingdom, 51.5, -0.17) is a value in the dictionary...
dictionary->TryGetValue("London", city);
if (city->Country == "United Kingdom" && (city->Latitude - 51.5) < EPSILON && (city->Longitude - -0.17) < EPSILON)
std::wcout << "The value (United Kingdom, 51.5, -0.17) is in the dictionary." << std::endl;
else
std::wcout << "Error: The value (United Kingdom, 51.5, -0.17) is not in the dictionary." << std::endl; // ...but ContainsValue returns False if passed a different instance of
// TCity with the same data, as different instances have different references.
city = new TCity;
city->Country = "United Kingdom";
city->Latitude = 51.5;
city->Longitude = -0.17;
if (dictionary->ContainsValue(city))
std::wcout << "Error: A new instance of TCity with values (United Kingdom, 51.5, -0.17) matches an existing instance in the dictionary." << std::endl;
else
std::wcout << "A new instance of TCity with values (United Kingdom, 51.5, -0.17) does not match any existing instance in the dictionary." << std::endl; delete city;
}
else {
std::wcout << "Error: The key \"London\" is not in the dictionary." << std::endl;
} // Update the coordinates to the correct ones.
city = new TCity;
city->Country = "Argentina";
city->Latitude = -34.6;
city->Longitude = -58.45;
dictionary->AddOrSetValue("Buenos Aires", city); // Generate the exception "Duplicates not allowed".
try {
dictionary->Add("Buenos Aires", city);
} catch (Exception &e) {
std::wcout << "Could not add entry. Duplicates are not allowed." << std::endl;
} // Display all countries.
std::wcout << "All countries:" << std::endl;
DynamicArray<TCity*> cityValues = dictionary->Values->ToArray();
const int cityCount = cityValues.get_length();
for (int i = ; i < cityCount; i++) {
std::wcout << cityValues[i]->Country << std::endl;
} // Iterate through all keys in the dictionary and display their coordinates.
std::wcout << "All cities and their coordinates:" << std::endl;
DynamicArray<UnicodeString> cityKeys = dictionary->Keys->ToArray();
for (int i = ; i < cityCount; i++) {
dictionary->TryGetValue(cityKeys[i], city);
std::wcout << cityKeys[i] << ": " << city->Latitude << ", " << city->Longitude << std::endl;
} // Clear all entries in the dictionary.
dictionary->Clear(); // There should be no entries at this point.
std::wcout << "Number of key-value pairs in the dictionary after cleaning: " << dictionary->Count << std::endl; std::cin.get();
return ;
}
http://docwiki.embarcadero.com/CodeExamples/XE6/en/Generics_Collections_TDictionary_%28C%2B%2B%29
TDictionary 是delphi用的,c++builder用起来太吃力。的更多相关文章
- delphi 泛型 c++builder 泛型
delphi 泛型 System.Generics.Collections.pas TList<T> http://docwiki.embarcadero.com/Libraries/Be ...
- delphi 连接 c++ builder 生成obj文件
delphi 连接 c++ builder 生成obj文件 delphi 可以连接c++ builder 生成OMF格式的obj文件,会报一个错.[DCC Error] E2065 Unsatisfi ...
- RAD Studio/Delphi 2010 3615下载+破解
RAD Studio/Delphi 2010 3615下载+破解 官方下载地址: http://altd.embarcadero.com/download/RADStudio2010/delphicb ...
- Delphi中DLL的创建和使用
参考:http://blog.csdn.net/ninetowns2008/article/details/6311663 结合这篇博客:http://www.cnblogs.com/xumenger ...
- 第三章 传奇的开始--Delphi(附读书笔记)
第三章 传奇的开始--Delphi "是惊世之作的Delphi让Borland重新站了起来,没有当初的Delphi,就没有今日的Borland!" "是Turbo Pas ...
- 通过预编译头文件来提高C++ Builder的编译速度
C++ Builder是最快的C++编译器之一,从编译速度来说也可以说是最快的win32C++编译器了.除了速度之外,C++builder的性能也在其它C++编译器的之上,但许多Delphi程序员仍受 ...
- Delphi 2010下载+完美破解
点击链接进入http://altd.embarcadero.com/download/RADStudio2010/delphicbuilder_2010_3615_win.isoRAD Studio/ ...
- Delphi资源大全
A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. Inspired by awe ...
- Awesome Delphi
Awesome Delphi A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. ...
随机推荐
- juc包下的集合类
import java.util.Iterator;import java.util.concurrent.CopyOnWriteArrayList; /** * 集合在多线程中同步的方式: * 1. ...
- 前端基础之CSS快速入门
前一篇写了我们的Html的常用组件,当然那些组件在我们不去写样式的时候都是使用的浏览器的默认样式,可以说是非常之丑到爆炸了,我们肯定是不能让用户去看这样丑到爆炸的样式,所以我们在这里需要使用css样式 ...
- Jenkins进阶-发布后自动创建git tag(5)
为了便于项目中对发布的版本进行回滚,所以我们每次发布完成以后自动创建git tag. 1,创建一个Jenkins任务,命名成为push_tag_demo: 2,配置<源码管理>,这里配置比 ...
- 既做无线客户端又做无线ap、又可只存在一种模式
1. 1.1 打开 /barrier_breaker/package/base-files/files/etc/init.d 加入 disable_sta_mode_wifi_interfaces # ...
- Mybatis常见面试题 二
1.mybatis是什么? (1)mybatis是一个优秀的基于java的持久层框架,它内部封装了jdbc,使开发者只需要关注sql语句本身,而不需要花费精力去处理加载驱动.创建连接.创建state ...
- TraceView 使用详解 android eclipse
先看命令 (配置好环境变量的情况下,直接traceview+空格+ trace文件路径即可): TraceView是什么 Traceview是android平台配备一个很好的性能分析的工具.它可以通过 ...
- poj 3069 Saruman's Army(贪心)
Saruman's Army Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tot ...
- 接口测试3-4使用csv进行接口测试
参照前面的例子 向URL发送corpid和corsecret2个参数,可以获取正确的tokenid https://qyapi.weixin.qq.com/cgi-bin/gettoken 数据 场景 ...
- [UE4]添加机器人
跟玩家角色一样,机器人也是继承自“Character”,动画蓝图也是跟角色玩家的一样,区别是机器人要使用“AIController”来控制
- [UE4]关闭自动曝光
向光移动,屏幕会慢慢变亮:背光移动,屏幕会慢慢变暗. 关闭自动曝光: 编辑->项目设置->搜索Auto exposure