[我可能错了] TIdTCPServer Server在Borland C++构建器中是多线程的.它在单独的线程上处理所有客户端.这是在Borland c ++的帮助下编写的.
现在是我的问题和疑问.例如,ShowMessage(String ..)应该在main(gui)线程上调用方法.但正如我上面所说,TCPServer是多线程的,并处理OnExecute不同线程上的事件.当我在OnExecute事件中使用ShowMessage方法(在与主线程不同的线程上处理)时,我得到了奇怪的结果.有时ShowMessage()按预期工作,有时它显示没有任何文字与不同的盒子大小(无限长,非常长,正常等).其他用户界面更改没有问题(更新TEdit,TMemo.ShowMessage()现在只有问题)
我认为这个问题是调用ShowMessage()方法不是在主(gui)线程上而是在TCPServer的线程上的结果,该线程是由TIdTCPServer在内部为客户端连接创建的.那么我该如何解决呢?
我boost::asio用来与同一台计算机上运行的node.js TCP服务器应用程序建立同步TCP套接字连接.我在Windows上使用Embarcadero RAD studio XE4构建64位应用程序,该应用程序使用Embarcadero集成升级版本1.50.
除了node.js TCP服务器关闭之外,工作正常.发生这种情况时,我从套接字读取时,我的C++客户端应用程序没有检测到断开连接.但是,当我写入套接字时,它确实检测到断开连接.
我目前的代码是在尝试了解增强文档和SO上的各种答案之后编写的.代码的读取部分如下(我省略了检查紧凑性的错误代码)
boost::system::error_code ec;
boost::asio::io_service io_service;
boost::asio::ip::tcp::socket s(io_service);
boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string("127.0.0.1"),m_port);
ec = s.connect(ep,ec);
std::size_t bytes_available = s.available(ec);
std::vector<unsigned char> data(bytes_available,0);
size_t read_len = boost::asio::read(s, boost::asio::buffer(data),boost::asio::transfer_at_least(bytes_available),ec);
if ((boost::asio::error::eof == ec) || (boost::asio::error::connection_reset == ec))
{
// disconnection
break;
}
Run Code Online (Sandbox Code Playgroud)
这不是一个很好的系统,因为它在循环内部运行自己的线程并不断轮询数据直到程序关闭.通常情况下,read()当没有数据时我不会在套接字上执行,但在这种情况下我会这样做,因为所有文档都让我相信只有在执行读取或写入套接字时才会检测到套接字断开连接.问题是上面的代码在node.js应用程序关闭时根本不会检测到断开连接.如果我正在编写,我会检测到它(代码的写入部分使用与读取相同的boost :: asio :: error`错误),但在读取时却没有.
显然,我无法执行大于可用字节数量的读取,或者我的线程将阻塞,我将无法在我的线程循环中执行写入.
我错过了另一个特定的增强错误代码来检测错误情况吗?或者这是一个特别是零长度读取的问题.如果是这样的话,我还有其他选择吗?
目前我正在让node.js服务器在关闭时关闭我检测到然后自己关闭客户端的时候写入特定的消息.但是,这有点像黑客,如果可能的话,我更愿意采用干净的方法来检测断开连接.
我知道这是一个愚蠢的问题,但是在更改视觉库时,我发现 FMX 存在“麻烦”...我的问题是:我需要做自己的边框,所以我将属性设置为边框样式:“无”,但是该应用程序全屏运行,也覆盖了 Windows 工具栏,所以我想要一种根据屏幕调整申请表大小的方法,例如:
mainForm->Height = Screen->Height - 10;
Run Code Online (Sandbox Code Playgroud)
可以使用 VCL,但是有没有办法使用 FMX 库来做到这一点?我用 FMX 征服的最大值是(我不知道它是如何返回值的,以及值的类型):
Screen->Size(); // TSize
Run Code Online (Sandbox Code Playgroud)
我现在也征服了它,但我有编译器错误:
TSize* Tamanho = new TSize;
Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho->Width;
frmPrincipal->Height = Tamanho->Height - 10;
Run Code Online (Sandbox Code Playgroud)
错误:“E2034 无法将 'TSize' 转换为 'TSize*'”
最后我试着把它放在 frmPrincipal.h 上,但同样的错误:
TSize *Tamanho;
Run Code Online (Sandbox Code Playgroud)
PS。:解决“主要问题”的其他可能的解决方案是可以接受的......
多谢!
我尝试从 dll 调用函数,但它似乎不能正常工作。这是代码:
HMODULE dllhandle;
#include "Unit1.h"
#include <windows.h>
#include <iostream.h>
#include <conio.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
dllhandle = LoadLibrary((wchar_t*)"PBusDrv.dll");
if(dllhandle)
{
typedef int (*PBUSCONNECTEX)(String aux1, String aux2, String ip);
PBUSCONNECTEX PBusConnectEx;
PBusConnectEx = (PBUSCONNECTEX)GetProcAddress(dllhandle, "PBusConnectEx");
PBusConnectEx(" "," ","192.168.30.252");
}
}
Run Code Online (Sandbox Code Playgroud)
dllhandle 不断返回空值。
I am attempting to add a low level mouse hook to a class. I am able to do so by placing this function in my CPP file:
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//my hook code here
return CallNextHookEx(0, nCode, wParam, lParam);
}
Run Code Online (Sandbox Code Playgroud)
Then, I set up the hook in the class constructor like so:
HHOOK mousehook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
Run Code Online (Sandbox Code Playgroud)
This works fine for intercepting mouse events, however since the callback function is not defined …
是否有可能来画TProgressBar上一个TSpeedButton,后面的文字和图标?
我不知道如何开始这个(假设它是可能的).我该怎么办呢?
在这种特殊情况下,我使用按钮来启动和停止进程,并且在该按钮中显示进程也是很好的.
我有一个包含多个表单的应用程序。其中两个非常相似,它们具有共同的 VCL 对象(标签、图像等)形式的特征,我将其命名为相同的。我想在特定类中有一个函数,它可以接受这两个 Form 之一作为参数,以便修改它们共有的参数。我遇到的解决方案似乎不起作用。
由于我的应用程序非常大且复杂,我使用一个小示例复制了该问题。首先,下面是我的 MainForm 的一个例子:
以及一个子表单的示例(它们都以类似的方式排列)
我有一个额外的类,用于填写子表单上的编辑。这个类的代码如下:
#pragma hdrstop
#include "master_class.h"
#include "sub_Form2.h"
#include "sub_Form3.h"
#include "sub_Form4.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
Master::Master(void)
{
}
Master::~Master(void)
{
}
void Master::WriteToForm(TForm* Form)
{
TForm2* curForm = static_cast<TForm2*>(Form);
TForm3* self = dynamic_cast<TForm3*>(Form);
TForm2* self2 = dynamic_cast<TForm2*>(Form);
if (self != NULL && self2 == NULL) {
TForm3* curForm = static_cast<TForm3*>(Form);
}
else if (self == NULL && self2 != NULL) {
TForm2* curForm = static_cast<TForm2*>(Form);
}
curForm -> Edit1 -> Text = …Run Code Online (Sandbox Code Playgroud) 我有一个用 Embarcadero C++Builder 编写的 C++ Windows 应用程序,我想将命令提示符中给出的参数传递给应用程序。
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR argv, int argc)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TFormMain), &FormMain);
if (argc > 1)
{
// pass argv to app.
}
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我如何从这里开始?
我正在使用C++ Builder XE4.我正在尝试将一些C代码编译到控制台应用程序中.C文件很大,所以我试着关注这个问题.代码设置了两个结构,然后尝试调用失败的值.
struct ephloc
{
long first_item_ordinal;
long last_item_ordinal;
int days_per_record;
int items_per_record;
int total_records;
};
struct ephloc objs[15] = {
{ 641, 2210500, 8, 44, 50224},
{2210501, 3014088, 16, 32, 25112},
{3014089, 4043684, 16, 41, 25112},
{4043685, 4483148, 32, 35, 12556},
{4483149, 4809608, 32, 26, 12556},
{4809609, 5098400, 32, 23, 12556},
{5098401, 5349524, 32, 20, 12556},
{5349525, 5600648, 32, 20, 12556},
{5600649, 5851772, 32, 20, 12556},
{5851773, 6730696, 16, 35, 25112},
{6730697, 10849068, 4, 41, 100448},
{10849069,14967440, 4, …Run Code Online (Sandbox Code Playgroud) 我有这个代码的问题.
我在代码中寻找的是随机获得"first"和"second"的结果并将结果放入文件中.
它的伟大工程,如果我不使用该文件运行它,我得到的所有正确的结果,但是当我尝试将结果保存在文件中,我只得到其中包含的第一个节点(第一,secnd).
这是代码:
#include<iostream>
#include <fstream>
#include<cmath>
using namespace std;
void main()
{
int first[100],secnd[100];
for (int i=0; i<100 ;i++)
{
first[i]=rand()%500; //random number from to 499
secnd[i]=rand()%500; //random number from to 499
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile <<first[i]<<" "<<secnd[i];
myfile.close();
}
}
Run Code Online (Sandbox Code Playgroud) c++builder ×10
c++ ×9
winapi ×3
boost-asio ×1
borland-c++ ×1
c ×1
delphi ×1
hook ×1
indy ×1
rad-studio ×1
sockets ×1
vcl ×1
visual-c++ ×1
windows ×1