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:

  1. Right-click your CppApplication project on the Project Manager and select Add.
  2. 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用起来太吃力。的更多相关文章

  1. delphi 泛型 c++builder 泛型

    delphi 泛型 System.Generics.Collections.pas TList<T> http://docwiki.embarcadero.com/Libraries/Be ...

  2. delphi 连接 c++ builder 生成obj文件

    delphi 连接 c++ builder 生成obj文件 delphi 可以连接c++ builder 生成OMF格式的obj文件,会报一个错.[DCC Error] E2065 Unsatisfi ...

  3. RAD Studio/Delphi 2010 3615下载+破解

    RAD Studio/Delphi 2010 3615下载+破解 官方下载地址: http://altd.embarcadero.com/download/RADStudio2010/delphicb ...

  4. Delphi中DLL的创建和使用

    参考:http://blog.csdn.net/ninetowns2008/article/details/6311663 结合这篇博客:http://www.cnblogs.com/xumenger ...

  5. 第三章 传奇的开始--Delphi(附读书笔记)

    第三章 传奇的开始--Delphi "是惊世之作的Delphi让Borland重新站了起来,没有当初的Delphi,就没有今日的Borland!" "是Turbo Pas ...

  6. 通过预编译头文件来提高C++ Builder的编译速度

    C++ Builder是最快的C++编译器之一,从编译速度来说也可以说是最快的win32C++编译器了.除了速度之外,C++builder的性能也在其它C++编译器的之上,但许多Delphi程序员仍受 ...

  7. Delphi 2010下载+完美破解

    点击链接进入http://altd.embarcadero.com/download/RADStudio2010/delphicbuilder_2010_3615_win.isoRAD Studio/ ...

  8. Delphi资源大全

    A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. Inspired by awe ...

  9. Awesome Delphi

    Awesome Delphi  A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. ...

随机推荐

  1. Mysql_connect报告”No such file or directory”错误的解决方法

    写了个php脚本单独执行mysql_connect(),发现错误信息居然是“No such file or directory"! 首先确定是mysql_connect()和mysql_pc ...

  2. wpf 客户端【JDAgent桌面助手】开发详解(三) 瀑布流效果实现与UI虚拟化优化大数据显示

    目录区域: 业余开发的wpf 客户端终于完工了..晒晒截图 wpf 客户端[JDAgent桌面助手]开发详解-开篇 wpf 客户端[JDAgent桌面助手]详解(一)主窗口 圆形菜单... wpf 客 ...

  3. metabase docker-compose 运行说明

    metabase 是一款比较产品化的一个数据分析工具,支持的数据源也比较多 以下为简单的docker-compose 运行文件,同时集成了mongo 以及graphql 引擎,方便数据 的api查询 ...

  4. sql server 循环操作

    使用的sql 语句如下: declare @userid int ;set @userid=0while(@userid<20)begin print 'the result is :'+STR ...

  5. Aria2+yaaw+Chrome插件BaiduExporter实现百度网盘下载

    Aria2+yaaw+Chrome插件BaiduExporter实现百度网盘下载 这篇博客主要为了解决百度网盘下载限速以及linux等操作系统无百度客户端的问题.主要包括两个方面第一个是aria2的安 ...

  6. 使用VBS控制声音

    Set Ws = CreateObject("Wscript.Shell") Ws.Sendkeys "…" '静音 'Ws.Sendkeys "爱爱 ...

  7. jquery选择器之属性过滤选择器详解

    代码如下: <style type="text/css">  /*高亮显示*/  .highlight{       } </style> 复制代码代码如下 ...

  8. java面试笔试题收集

    转载过来看看.... J2SE基础 1. 九种基本数据类型的大小,以及他们的封装类. 2. Switch能否用string做参数? 可以 3. equals与==的区别. 4. Object有哪些公用 ...

  9. FastAdmin CMS 插件下载

    FastAdmin CMS 插件下载 CMS内容管理系统插件(含小程序) 自定义内容模型.自定义单页.自定义表单.自定义会员发布.付费阅读.小程序等 提供全部前后端源代码和小程序源代码 功能特性 基于 ...

  10. Python 中的变量

    Python采用基于值得内存管理模式,赋值语句的执行过程是:首先把等号右侧标识的表达式计算出来,然后在内存中找一个位置把值存放进去,最后创建变量并指向这个内存地址.Python中的变量并不直接存储值, ...