delphi-如何在DataSnap projectgroup中使用全局变量进行服务器和客户端的通信
发布时间:2022-04-15 11:49:04 328
相关标签: # 服务器# 数据# 服务器
我在datasnap projectgroup中使用全局变量。每天我都要从客户端主机上传新的数据到远程服务器上。所以,我应该知道上次上传记录的id,只选择客户端数据集中的新记录,然后使用CliendDataset组件上传到远程服务器上。
在ServerMethodUnit中,我使用fdQuery组件:
select max country_id as maxcountry_id from country.
然后我赋值:
G_maxcountry_id:= fdquery1maxcountry_id.AsInteger;
断点显示此时全局变量得到了正确的值。
然后在ClientModuleUnit中,我使用其他fdQuery从本地firebird db中选择新记录:
select * from country where country_id>:country_id
Clientmodule1.qCountry.close;
Clientmodule1.qCountry.Params[0].AsInteger:= G_MAXCOUNTRY_ID;
Clientmodule1.qCountry.close;
but in this moment breakpoint shows that variable is 0.
要使用此全局变量单位:
1)我为全局变量创建单位:
unit uGlob;
interface
var G_MAXCOUNTRY_ID:integer;
implementation
uses ServerMethodsUnit1, ClientModuleUnit1, ClienUnit;
2)我在服务器和客户端项目中添加了这个单元;项目->;“添加到项目中”;。
3)我在这些单元的实现部分——ServerMethodsUnit1、ClientModuleUnit1和ClieUnit中添加了这个单元:
a)
unit ClientModuleUnit1;
implementation
uses ServerMethodsUnit1, uGlob;
{$R *.dfm}
b)
unit ServerMethodsUnit1;
implementation
{$R *.dfm}
uses System.StrUtils, uGlob;
c)
unit ClienUnit;
implementation
{$R *.dfm}
uses ClientModuleUnit1, uGlob;
我的问题是:
- 怎么了?在我的例子中,如何以及在何处声明和使用全局变量?
- 我可以避免在我的例子中使用全局变量吗?
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报