请教DataSnap客户端如何调用服务器端定义的方法
展开全部
服务端的方法定义在 ServerMethodsUnit1.cpp中。
调用两个方法的例子
Samples\CPP\DataSnap\SimpleDataSnapDemo\CppDataSnapClient\DataSnapClientClasses.cpp
System::UnicodeString __fastcall TServerMethods1Client::EchoString(System::UnicodeString value)
{
if (FEchoStringCommand == NULL)
{
FEchoStringCommand = FDBXConnection->CreateCommand();
FEchoStringCommand->CommandType = TDBXCommandTypes_DSServerMethod;
FEchoStringCommand->Text = "TServerMethods1.EchoString";
FEchoStringCommand->Prepare();
}
FEchoStringCommand->Parameters->Parameter[0]->Value->SetWideString(value);
FEchoStringCommand->ExecuteUpdate();
System::UnicodeString result = FEchoStringCommand->Parameters->Parameter[1]->Value->GetWideString();
return result;
}
System::UnicodeString __fastcall TServerMethods1Client::ReverseString(System::UnicodeString value)
{
if (FReverseStringCommand == NULL)
{
FReverseStringCommand = FDBXConnection->CreateCommand();
FReverseStringCommand->CommandType = TDBXCommandTypes_DSServerMethod;
FReverseStringCommand->Text = "TServerMethods1.ReverseString";
FReverseStringCommand->Prepare();
}
FReverseStringCommand->Parameters->Parameter[0]->Value->SetWideString(value);
FReverseStringCommand->ExecuteUpdate();
System::UnicodeString result = FReverseStringCommand->Parameters->Parameter[1]->Value->GetWideString();
return result;
}
调用两个方法的例子
Samples\CPP\DataSnap\SimpleDataSnapDemo\CppDataSnapClient\DataSnapClientClasses.cpp
System::UnicodeString __fastcall TServerMethods1Client::EchoString(System::UnicodeString value)
{
if (FEchoStringCommand == NULL)
{
FEchoStringCommand = FDBXConnection->CreateCommand();
FEchoStringCommand->CommandType = TDBXCommandTypes_DSServerMethod;
FEchoStringCommand->Text = "TServerMethods1.EchoString";
FEchoStringCommand->Prepare();
}
FEchoStringCommand->Parameters->Parameter[0]->Value->SetWideString(value);
FEchoStringCommand->ExecuteUpdate();
System::UnicodeString result = FEchoStringCommand->Parameters->Parameter[1]->Value->GetWideString();
return result;
}
System::UnicodeString __fastcall TServerMethods1Client::ReverseString(System::UnicodeString value)
{
if (FReverseStringCommand == NULL)
{
FReverseStringCommand = FDBXConnection->CreateCommand();
FReverseStringCommand->CommandType = TDBXCommandTypes_DSServerMethod;
FReverseStringCommand->Text = "TServerMethods1.ReverseString";
FReverseStringCommand->Prepare();
}
FReverseStringCommand->Parameters->Parameter[0]->Value->SetWideString(value);
FReverseStringCommand->ExecuteUpdate();
System::UnicodeString result = FReverseStringCommand->Parameters->Parameter[1]->Value->GetWideString();
return result;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询