Jump to content

Unigui call Datasnap function simultaneously


hendrang

Recommended Posts

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 :

post-930-0-76166400-1354233797.jpg

 

but if I call the DataSnap function simultaneously by opening the uniGui in two firefox tabs, it retuns variety

wrong value.

 

post-930-0-24353800-1354233986.jpg post-930-0-17451000-1354233994.jpg

 

 

post-930-0-82027600-1354234051.jpg post-930-0-39842000-1354234043.jpg

 

 

How can I solve the problem and thanks in advance.

 

Thanks

Hendra

Link to comment
Share on other sites

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...