关于midas三层结构的问题,急用,高手请进!!!!!(100分)

  • 主题发起人 agang007
  • 开始时间
A

agang007

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TFrmMain.TmgetqqTimer(Sender: TObject);
var
QQinfoget:eek:levariant;
Contrinfo:variant;
last:variant;
rsult:variant;
NI,j:integer;
QQgetdid:integer;
sta:string;
begin
try
tmgetqq.Enabled :=false;
StatusBar1.Panels[1].Text:=FormatDateTime('"时间:"yyyy"年"m"月"dd"日 "hh:nn',Date+Time);
QQgetdid:=0;
if CancelQQget=1 then
begin
tmgetqq.Enabled :=false;
exit;
end;
inc(QQGetNum);
with dmdo
begin
NI:=0;//lzm
// for NI:=0 to 3do
while NI<=3do
begin
if CancelQQget=1 then
begin
tmgetqq.Enabled :=false;
exit;
end;
//Inc(NI);
QQinfoget:=null;
Contrinfo:=null;
last:=null;
rsult:=null;
QQgetdid:=dids[NI];
sta:=stationname1[NI];
application.ProcessMessages;
sckcon.AppServer.QQGet(QQgetdid,QQinfoget,rsult);
if rsult=1 then
begin
if VarIsArray(QQinfoget) then
begin
for j:=VarArrayLowBound(QQinfoget,1) to VarArrayHighBound(QQinfoget,1)do
begin
if QQinfoget[j]<>'' then
frmqq.memorec.Lines.Add(sta+':'+QQinfoget[j]);
end;
frmqq.Status.Panels[0].Text :='数据接收成功';
if frmqq.Visible <> true then
frmqq.Show ;
end;
end;

application.ProcessMessages;
sckcon.AppServer.ContrlStrGet(QQgetdid,Contrinfo,last);
if last=1 then
begin
if Contrinfo<>'' then
begin
if Contrinfo='notallow' then
application.MessageBox(pchar(sta+' 不同意修改参数'),'控制系统',mb_ok);
if Contrinfo='allow' then
application.MessageBox(pchar(sta+' 同意修改参数'),'控制系统',mb_ok);
end;
{if VarIsArray(Contrinfo) then
begin
for j:=VarArrayLowBound(Contrinfo,1) to VarArrayHighBound(Contrinfo,1)do
begin
if Contrinfo[j]<>'' then
begin
if Contrinfo[j]='notallow' then
application.MessageBox(pchar(sta+' 不同意修改参数'),'中心控制系统',mb_ok);
if Contrinfo[j]='allow' then
application.MessageBox(pchar(sta+' 同意修改参数'),'中心控制系统',mb_ok);
end;
end;
end;
}
end;
Inc(NI);
end;
tmgetqq.Enabled :=true;
end;
except
inc(QQGetNum);
tmgetqq.Enabled :=true;
exit;
end;
end;
上面是我在客户端调用服务器上的方法,timer隔2秒触发一次,
但是3-4个小时之后会跳出内存访问错误。不知道原因,出错在客户端
说明服务器端定义方法应该没有问题。
 
等你进行代码重构后,再看你的程序。
 
procedure Tstaserver.ContrlStrGet(SID: Integer;
out ContrInfo,
result: OleVariant);
begin
try
case sid of
51:begin
IF contrltxt51<>'' then
begin
ContrInfo:=contrltxt51;
contrltxt51:='';
result:=1;
end
else
begin
ContrInfo:='';
result:=0;
end;
end
else
begin
ContrInfo:='';
result:=0;
end;
end;
except
result:=0;
exit;
end;
end;
/////////以上为服务器端定义的过程。
var
Contrinfo:variant;
last:variant;
begin
sckcon.AppServer.ContrlStrGet(QQgetdid,Contrinfo,last);
end;
///////以上为客户端用timer 引用服务器定义的方法
大概执行到40000左右程序会出错,错误类型在‘error in model vcl50.bpl’
请高手指点!!!
 
长时间用TIMER比较容易出错,建议改用线程
如果不想改,有一点要注意:TIMER中绝对不能用application.ProcessMessages,
否则有可能导致出错,一般有可能是内存错误或资源不足错误,这是我的一个经验
 
您太喜欢用变体类型了。这样可能会造成内存错误.遇上这类问题。累人呀!
 
我与楼上同同感。我一般都不用Variant,除非逼不得已,而且你的调用也是用的Later Binding,
如果换用Dispatch Table,效果会更好(这是题外话)。
你要处理的是什么数据?二进制的吗?如果参数设为BSTR *类型,再用一个整形参数标识数
据长度,这样会更加可靠。
 
楼上的兄弟:
我传的是个长度不定的字符串列表!或者是单个一字符串!
但好象只有服务器端variant *才能支持数据的输入输出,这点我还不太清楚,请指教!
我会换成Dispatch Table的,谢谢你的提醒!
 
顶部