我正在尝试在RAD Studio XE2中创建新的VCL组件.我使用C++ Builder或Delphi得到了相同的结果:

如何获取VCL组件列表?我试过"修复设置",但没有成功.
我的新组件(TComponent)使用DsgnIntf,因为我使用自定义属性编辑器.问题是在自定义VCL应用程序中使用该组件时 - 找不到DSGNINTF.DCU!一种解决方案是将命令行开关添加到编译器(不记得它是什么),但我不喜欢这个解决方案.第二种解决方案是单位隔离.我找到了这个:
http://edn.embarcadero.com/article/27717
问题是 - 我不太了解这篇文章.我不知道在组件单元中我需要做什么才能将设计时与运行时代码分开.有人可以做出最简单的例子并解释一下吗?我只是想避免在人们使用我的组件时出现"dsgnintf.dcu not found"的问题.谢谢.
编辑:我看了一下这篇文章,我意识到第二个单元注册了第一个.为了避免dsgnintf.dcu问题我假设第二个单元必须在它自己的.pas文件中?
我正在使用此代码:
#include <iostream>
#include <memory>
#include <vector>
using namespace std;
void out(int* p){
cout << *p;
}
int main(){
vector<unique_ptr<int> > vInt;
for(int i = 0; i < 10; i++)
vInt.push_back(unique_ptr<int>(new int(i)));
out(vInt[0].get()); // 0
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用一些在线编译器,它编译好,但C++ Builder XE2和XE6报告错误:
[bcc32 Error] vector(1179): E2247 'unique_ptr<int,default_delete<int> >::unique_ptr(const unique_ptr<int,default_delete<int> > &)' is not accessible
[bcc32 Error] vector(1203): E2247 'unique_ptr<int,default_delete<int> >::unique_ptr(const unique_ptr<int,default_delete<int> > &)' is not accessible
[bcc32 Error] xutility(1682): E2247 'operator unique_ptr<int,default_delete<int> >::=(const unique_ptr<int,default_delete<int> > &)' is not accessible
[bcc32 Error] …Run Code Online (Sandbox Code Playgroud) 在捕获'[]'部分中编写lambda函数时,我需要仅指定自动持续时间变量,而在lambda函数中使用全局变量和静态变量而不需要捕获.这是为什么?为什么我们不能像全局变量和静态变量一样使用自动持续时间变量?
在以下示例中:
template <class T, int n>
class MyContainer{
public:
T myArray[size];
int size;
MyContainer() : size(n){}
};
// full or partial specialization?
template <int n>
class MyContainer <double, n>{
public:
double myArray[n];
int size;
MyContainer() : size(n){}
double sum();
double average();
};
Run Code Online (Sandbox Code Playgroud)
我刚刚开始学习完整和部分模板专业化,这让我有点困惑。一般来说,我会说这是一个完整的模板专业化,因为参数 T 被定义为 double 并且没有留下其他形式参数。但是,我不确定参数n在这里是否有任何区别?
我有两个表(表 1 - 主表,表 2 - 详细表)。如何仅选择(查看)主表中那些在详细表中没有记录的记录?我可以使用什么 SQL 语句来实现此目的?我正在使用 MS SQL Server 2012。
编辑:表定义
表 1 - ID (PK) 表 2 - ID (PK)、表 1ID (FK)
让我们假设我有tasks许多任务和threads运行它们的线程数。每个线程只能运行一次,所以我想通过现有线程平均分配这些任务。为了计算每个线程的任务数,我编写了这个简单的应用程序:
#include <iostream>
using namespace std;
int main(){
int tasks = 15;
int threads = 8;
if(tasks < threads)
threads = tasks;
int tasksPerThread = tasks / threads;
for (int i = 0, start = 1; i < threads; i++) {
start = tasksPerThread * i + 1;
int end = start + tasksPerThread - 1;
if (i == threads - 1 && end < tasks)
end = tasks;
if(start == end)
cout << "Thread " …Run Code Online (Sandbox Code Playgroud) 我有以下JSON:
{"test1":"1", "test2": {"test21":"21", "test22":"22"}}"
Run Code Online (Sandbox Code Playgroud)
但我解决它有麻烦.实际上,我在某种程度上试图阅读"test21",但不知道如何达到它.我尝试了这个,但它并不好:
UnicodeString myJSON = "{\"test1\" :\"1\",\"test2\":{\"test21\":\"21\",\"test22\":\"22\"}}";
TJSONObject *JSON = (TJSONObject*)TJSONObject::ParseJSONValue(myJSON);
TJSONValue *test2 = (TJSONValue*)JSON->Get("test2");
//TJSONString* test21 = (TJSONString*)test2->Get("test21");
Run Code Online (Sandbox Code Playgroud) 我知道auto_ptr搞砸了复制语义,因此在容器中使用是不安全的,因为将一个auto_ptr复制到另一个会使source = NULL指针(这不是像移动语义一样吗?).但话说再说一次,unique_ptr根本无法复制,只能转让所有权.那么,unique_ptr如何在需要使用复制操作来复制和重新排列元素的容器和算法中使用?
我正在使用可变参数模板,我坚持以下内容:
template <class T1, class T2>
auto sum(T1 a, T2 b) ->decltype(a + b){
return a + b;
}
template <class T1, class T2, class... T3>
auto sum(T1 a, T2 b, T3... tail) ->decltype(a + b){
return a + sum(b, tail...);
}
Run Code Online (Sandbox Code Playgroud)
函数调用:
cout << sum(1, 2, 3, 4) << endl; // 10 - OK
cout << sum(1.5, 2, 3, 4) << endl; // 10.5 - OK
cout << sum(1, 2, 3.5, 4) << endl; // 10 !! wrong result …Run Code Online (Sandbox Code Playgroud) 在 C++ Builder 10.3.3 中,我使用以下测试代码:
int count = 500;
_di_ITask* task = new _di_ITask[count];
ProgressBar1->Position = 0;
for(int i = 0; i < count; i++){
task[i] = TTask::Create([i, this](){
// do something...
Sleep(10);
});
task[i]->Start();
//ProgressBar1->Position = numberOfFinishedTasks;
//Application->ProcessMessages();
}
TTask::WaitForAll(task, count - 1);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,有 500 个测试任务,我希望我的 ProgressBar 组件显示当前已完成任务的数量。我不知道如何获得这些信息。谢谢!
我正在测试一个移动构造函数并执行以下操作:
#include <iostream>
#include <string>
using namespace std;
class X{
public:
int* p;
int size;
X(){}
X(int n) : size(n){
p = new int[n];
for(int i = 0; i < n; i++)
p[i] = i;
cout << "Constructor\n";
}
~X(){
delete[] p;
}
X(const X& r){
cout << "Copy\n";
}
X(X&& r){
p = r.p;
size = r.size;
r.p = NULL;
r.size = 0;
cout << "Move\n";
}
};
int main() {
X a(10); //constructor
X b(a); // copy
X …Run Code Online (Sandbox Code Playgroud) c++ ×8
c++11 ×5
c++builder ×4
delphi ×3
vcl ×2
algorithm ×1
class ×1
components ×1
constructor ×1
containers ×1
ide ×1
json ×1
lambda ×1
pointers ×1
sql ×1
sql-server ×1
templates ×1
vector ×1