hendrang Posted November 30, 2012 Share Posted November 30, 2012 Hi all, My unigui apps call a simple function in a Datasnap application simultaneously. I am using Delphi XE. the function in Datasnap is: function TServerMethods2.RetValue(aVal:Integer): Integer; begin Sleep(1000); // pause execution for simulating simultaneous execution Exit(aVal); end; the function just return back the parameter value, no other calculation. and the code to call the RetValue function in uniGui application : procedure TMainForm.UniBitBtn1Click(Sender: TObject); var i,x: Integer; begin UniListBox1.Clear; for I := 1 to 10 do begin x:= ClientModule1.ServerMethods2Client.RetValue(i); UniListBox1.Items.Add(IntToStr(x)); // Return value in listbox end; end; and the correct result is : but if I call the DataSnap function simultaneously by opening the uniGui in two firefox tabs, it retuns variety wrong value. How can I solve the problem and thanks in advance. Thanks Hendra Link to comment Share on other sites More sharing options...
hendrang Posted November 30, 2012 Author Share Posted November 30, 2012 My application project : uniGuiAndDataSnap.rar Link to comment Share on other sites More sharing options...
docjones Posted November 30, 2012 Share Posted November 30, 2012 In unigui applications, each user session can't share same vars/objects, becouse each user session have her own thread, then better way is create ojects/vars into unimainmodule. Remove ClientModule1 from autocreate, declare public var on mainmodule class, and create it on mainmodule.oncreate procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject); begin Client:=TClientModule1.Create(self); end; then, in mainform you must access UnimainModule.Client Procedure TMainForm.UniBitBtn1Click(Sender: TObject); var i,x: Integer; begin UniListBox1.Clear; for I := 1 to 10 do begin x:= UniMainModule.Client.ServerMethods2Client.RetValue(i); UniListBox1.Items.Add(IntToStr(x)); end; end; Link to comment Share on other sites More sharing options...
hendrang Posted November 30, 2012 Author Share Posted November 30, 2012 In unigui applications, each user session can't share same vars/objects, becouse each user session have her own thread, then better way is create ojects/vars into unimainmodule. Remove ClientModule1 from autocreate, declare public var on mainmodule class, and create it on mainmodule.oncreate procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject); begin Client:=TClientModule1.Create(self); end; then, in mainform you must access UnimainModule.Client Procedure TMainForm.UniBitBtn1Click(Sender: TObject); var i,x: Integer; begin UniListBox1.Clear; for I := 1 to 10 do begin x:= UniMainModule.Client.ServerMethods2Client.RetValue(i); UniListBox1.Items.Add(IntToStr(x)); end; end; Hello Docjones, I works, problem solved. Thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now