02-13-2019, 08:33 PM
Greetings!
Using Tokyo 10.2.3
IW 14.2.7
I started a new "Test" object to do some proof of concept stuff work work.
Currently I have a REST server wrote that we use FMX iOS/Android apps talk to. Works great for past 2.5+ years.
I have code that works with XSuperJSON/XSuperObject and some custom code to wrap all communications
and to wrap up JSON into objects. This works great too.
Sooooo... I took this existing code from my FMX app and put it into a VCL IW stand alone server program.
Since the calls may take upwards of 10-15 seconds to run while it hits up the REST server.. REST server hits up a database back end,
does its magic and sends back... I wanted to use a thread.
I have something that "works" but not 100% sure if this is the proper way.... or can be done better.
So in this case... I kick of the anonymousthread and start an ASYNC timer to check the status of the salesSearchRequest object.
Not sure if using the timer is the "best" way... it works... but is there a better method?
After the salesSearchRequest.execute; I can't do "iwtimer1.enabled:=true;" ... as nothing happens... but if i hit F5 to refresh the page,
then the timer starts working. I don't know how or if even, so i can do something like
or if there is way to something with tthread.Synchronize that will play happy with IW client and can get code to kick off then to update the screen via async?
Any ideas would help!
As mentioned, what I have today works... but I figure better to check in to see if better/proper ways of doing this.
Using Tokyo 10.2.3
IW 14.2.7
I started a new "Test" object to do some proof of concept stuff work work.
Currently I have a REST server wrote that we use FMX iOS/Android apps talk to. Works great for past 2.5+ years.
I have code that works with XSuperJSON/XSuperObject and some custom code to wrap all communications
and to wrap up JSON into objects. This works great too.
Sooooo... I took this existing code from my FMX app and put it into a VCL IW stand alone server program.
Since the calls may take upwards of 10-15 seconds to run while it hits up the REST server.. REST server hits up a database back end,
does its magic and sends back... I wanted to use a thread.
I have something that "works" but not 100% sure if this is the proper way.... or can be done better.
Code:
..
..
private
salesSearchRequest: TSalesSearchRequest;
public
end;
..
..
procedure TIWForm117.btnGoClick(Sender: TObject);
begin
IWMemo1.Clear;
salesSearchRequest := TsalesSearchRequest.create;
salesSearchRequest.serveraddress := 'myserver.com';
salesSearchRequest.username := '<username>';
salesSearchRequest.password := '<password>;
salesSearchRequest.VIN := e_VIN.text; /// <---- on the form itself, user types in a vehicle VIN
tthread.CreateAnonymousThread(
procedure
begin
salesSearchRequest.Execute; // this takes the request and sends it out the REST server and does the magic to take the JSON response and turn it into object code.
end).Start; // start the AnonymousThread so not to stop the user interface.
IWTimer1.Enabled := true; // kicks off an Async timer that checks every 500ms
end;
..
..
..
procedure TIWForm117.IWTimer1AsyncTimer(Sender: TObject; EventParams: TStringList);
var
idx: integer;
begin
if assigned(salesSearchRequest) then
begin
case salesSearchRequest.State of
jRunning: IWMemo1.Lines.Add('Waiting...'); // the salesSearchRequest is still running... so spit something out to memo box
jComplete: // the salesSearchRequest is "finished" running... so now do something.
begin
IWTimer1.Enabled := false; // turn off timer
for idx := 0 to salesSearchRequest.inventory.inventoryresults.Count - 1 do
begin
IWMemo1.Lines.Add(inttostr(idx + 1) + ' : ' + salesSearchRequest.inventory.inventoryresults[idx].guid + // inventory GUID / ID
' ' + salesSearchRequest.inventory.inventoryresults[idx].year + ' ' + // year of vehicle
salesSearchRequest.inventory.inventoryresults[idx].model); // model of vehicle
end;
freeandnil(salesSearchRequest);
end;
end;
end;
end;
Not sure if using the timer is the "best" way... it works... but is there a better method?
After the salesSearchRequest.execute; I can't do "iwtimer1.enabled:=true;" ... as nothing happens... but if i hit F5 to refresh the page,
then the timer starts working. I don't know how or if even, so i can do something like
Code:
salesSearchRequest.execute; // do my REST call magic
iwTimer1.enabled := true;
webapplication.updatestuff;
).start;
Any ideas would help!

As mentioned, what I have today works... but I figure better to check in to see if better/proper ways of doing this.