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. ...
随机推荐
- alpha和color key
一.alpha 1.透明度,一般取值0-255 2.Alpha 通道: Alpha 通道是为保存选择区域而专门设计的通道.在生成一个图像文件时,并不必须产生 Alpha 通道.通常它是由人们在图 ...
- let、var、const区别(表格比较)
let.var.const区别(表格比较): 区别项 let var const 作用域 块级作用域 全局作用域或函数作用域 块级作用域 是否有变量提升 无 有 无 是否可重复声明 不可 可以 不可 ...
- Spring 集成开发工具(STS)安装及配置
安装 spring 集成开发工具,下载地址:https://spring.io/tools 下载后,解压,双击 STS ,运行. 如果提示: 去oracle的网站上下载了1.8版本的jdk,下载地址如 ...
- MapReduce – 基本思路之推荐引擎
理解MapReduce关键两个步骤: 首先是构想出结构的数据结构,这种数据结构可以支撑你的业务分析使用:是要理解这种模式的处理元素. 第二步,分析原始数据的结构是怎样的: 第三步,基于原始数据结构以及 ...
- bzoj 2616 SPOJ PERIODNI——笛卡尔树+树形DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2616 把相同高度的连续一段合成一个位置(可能不需要?),用前缀和维护宽度. 然后每次找区间里 ...
- phper必知必会(一)
1.http返回状态 200:成功,服务器已经成功处理了请求,并正常返回了提供请求的网页 301:永久移动,服务器会将请求转移到新的服务器地址 302:临时移动 401:未授权请求,请求需要身份移动 ...
- SSH pts 虚拟终端
昨天晚上小试了一下SSH,学到了一些乱七八糟的命令,知道了一种古老装逼的聊天方式:write.期间下定决心终于弄明白了pts/0之类的东西到底是什么东西. 先说pts/0吧,man里面是这样说的:pt ...
- 如何制作Jar包并在android中调用jar包
android制作jar包: 新建android工程,然后右击,点击导出,选择导出类型为Java下的JAR file,在java file specification 中不要选择androidmani ...
- jquery ztree异步搜索
一.初始异步加载树 初始化默认给出一个根结点,再结合异步加载的方式手动触发默认加载第一层,如图: 代码如下: var treeSetting = { async: { enable: true, ur ...
- Java-Runoob-高级教程-实例-数组:08. Java 实例 – 数组填充
ylbtech-Java-Runoob-高级教程-实例-数组:08. Java 实例 – 数组填充 1.返回顶部 1. Java 实例 - 数组填充 Java 实例 以下实例我们通过 Java Ut ...