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. ...
随机推荐
- Struts2重新学习2之struts2和struts1的区别
1) 在Action实现类方面的对比:Struts 1要求Action类继承一个抽象基类:Struts 1的一个具体问题是使用抽象类编程而不是接口.Struts 2 Action类可以实现一个Acti ...
- 自制数据结构(容器)-java开发用的最多的ArrayList和HashMap
public class MyArrayList<E> { private int capacity = 10; private int size = 0; private E[] val ...
- MySQL Disk--SSD 特性
======================================================================= SSD 特性 .随机读能力非常好,连续读性能一般,但比普 ...
- vsto excel 任务窗体操作
1. 开发环境visual studio 2010 2. office 2007 代码: 1.任务窗体 代码: partial class ActionsPaneControl1 : UserCont ...
- vs2013下OpenGL环境的配置
1.下载glut库:https://files.cnblogs.com/files/laoxia/glutdlls37beta.zip 2.解压后,将glut.lib和glut32.lib两个文件拷贝 ...
- Oracle 基于用户管理恢复的处理
================================ -- Oracle 基于用户管理恢复的处理 --================================ Oracle支持多种 ...
- CommonsChunkPlugin知识点
CommonsChunkPlugin 的作用就是提取代码中的公共模块,然后将公共模块打包到一个独立的文件中去,以便在其它的入口和模块中使用. 多个 html共用一个js文件(chunk),可用Comm ...
- SQLServer2008开启远程连接
1.查看sqlserver brower协议是否启动 2.对象资源管理器 右键属性->选择-> 方面->服务器配置->Remoteaccess ->True 3.对象资源 ...
- 深入理解ASP.NET MVC(4)
系列目录 DataTokens和Areas机制 到目前为止Route对象只剩下DataTokens属性没有涉及,事实上这个Areas机制的核心. DataTokens实际上也是一个RouteValue ...
- PHP接口开发加密技术实例原理与例子
下面例子简单讲解PHP接口开发加密技术:如app要请求用户列表,api是“index.php?module=user&action=list”app生成token = md5sum (‘use ...