三层应用客户端用多线程调用 运行期 bpl(Tdatamodule)‘灾难性错误’?在线急等... (200分)

T

TMXYB

Unregistered / Unconfirmed
GUEST, unregistred user!
[red]//如果客户端不用多线程调用则一切正常。[/red] .只是主窗口出现太慢。
经调试的发现和一些说明:
1。多线程导出的全局变量(TTDataModule,Tsocketconnection,TSimpleObjectBroker)不为nil;主窗口中调用它们的方法正常。
2。无法在主窗口中引用Tsocketconnection.appserver.add_client_inf('','','','');
[red]//即无法引用服务器定义的方法,消息提示:project xxx.exe raise expception class message ''. process stopped...[/red]
[red]//接着出现一些错误。[/red] .
3. 单线程一切正常。
4。对于 clientdataset 不能close;
否则也出现上面的错误信息,且说‘灾难性错误’。
相关例子引出:李维的《如 何 使 用 Delphi 開 發 大 型 主 從 架 構 系 統 - Package 的 秘 密 和 威 力 (續)》
http://www2.borland.com.tw/tw/reference9-4.html
 
老大们,给个说法啊。我可等不急了。
 
socketconnection is not register properly......
 
to :dragonlee007
如何让 socketconnection 在多线程中完全注册? 为何在单线程中又没有问题呢?
我的多线程代码为:
type
get_sever_data = class(TThread)
private
the_dm_handle:integer;
the_dm_Class:Tclass;
temp_DataModule: TDataModule;
temp_ds:TFTClientDataset;
temp_socket: Tsocketconnection;
temp_SimpleObject:TSimpleObjectBroker;
{ Private declarations }
protected
procedure Execute;
override;
procedure export_dataset;
end;

implementation
uses myfunction;
{ get_sever_data }
procedure get_sever_data.Execute;
var loop: integer;
begin

{ for loop := 0 to Screen.DataModuleCount - 1 do

begin
if (not terminated) and (UpperCase(Screen.DataModules[loop].ClassName) = 'TDATA_MODULE') then
the_DataModule:= Screen.DataModules[loop];
end;
}
freeonterminate:=true;
if temp_DataModule = nil then
begin
if the_dm_handle = 0 then
the_dm_handle:= LoadPackage('Pack_datamodule.bpl');
the_dm_Class:= GetClass('TData_Module');
if the_dm_Class <> nil then
begin
temp_ds:=nil;
temp_socket:=nil;
temp_SimpleObject:=nil;
temp_DataModule:= TDataModule(TComponentClass(the_dm_Class).Create(Application));
for Loop := 0 to temp_DataModule.ComponentCount - 1 do
begin

if (temp_SimpleObject = nil) and (not terminated) and (UpperCase(temp_DataModule.Components[Loop].ClassName) = 'TSIMPLEOBJECTBROKER') then
begin
temp_SimpleObject := TSimpleObjectBroker(temp_DataModule.Components[Loop]);
end;
if (temp_socket = nil) and (not terminated) and (UpperCase(temp_DataModule.Components[Loop].ClassName) = 'TSOCKETCONNECTION') then
begin
temp_socket := Tsocketconnection(temp_DataModule.Components[Loop]);
end;
if (temp_ds = nil) and (not terminated) and (TFTClientDataset(temp_DataModule.Components[Loop]).Name = 'password_Query') then
begin
temp_ds := TFTClientDataset(temp_DataModule.Components[Loop]);
end;
if terminated then
break;
if (temp_DataModule<>nil) and (temp_socket <> nil) and (temp_SimpleObject<> nil) and (temp_ds<> nil) then
begin
try
temp_socket.Connected := true;
if (temp_ds<> nil) then
begin

temp_ds.Open;
synchronize(export_dataset);
end;

except
MessageBox(Application.Handle, pchar(' &Oacute;&euml;·&thorn;&Icirc;&ntilde;&AElig;÷&Aacute;&ordf;&frac12;á&Ecirc;§°&Uuml;&pound;&not;&Ccedil;&euml;&micro;&Ccedil;&Acirc;&frac12;&ordm;ó&Ouml;&Oslash;&Ecirc;&Ocirc;&iexcl;&pound;'), '&Iacute;&oslash;&Acirc;&ccedil;&acute;í&Icirc;ó', MB_OK + MB_ICONSTOP);
temp_ds.close;
end;
break;
end;

end;

end;
end;

end;

procedure get_sever_data.export_dataset;
begin
[red]//左边变量为公用bpl中的全局变量[/red]
dm_Global:=temp_DataModule;
SimpleObject_global:= temp_SimpleObject;
socket_global:=temp_socket;
datamodule_handle:=the_dm_handle;
dataModuleClass:=the_dm_Class ;
the_password_dataset:=temp_ds ;

end;

 
估计数据库还未打开,而客户端一开始就设置当打开时就连接,也就说SOCETCONNECTION为TRUE。
或者应用服务器端被强行关闭了
早前我开发时也遇到这个问题,你试试骂
 
to:delphilove
我一步步调试,并未发现有 应用服务器端被强行关闭 的语句。而且我多次将 SOCETCONNECTION设为TRUE;
请帮帮我检查一下上面的 线程语句有无错误。回忆一下您当时是如何解决问题的。
万分感谢! 分不够再加!
 
没有找到可靠的答案,也不想将帖子拖太久,如果那位高人找到了答案,望告知。结贴。
 
顶部