vbdavie Posted August 20, 2015 Share Posted August 20, 2015 With the understanding that there is NO SUCH THING as a "blocking" modal form, How would I turn my windows logic into uniGUI logic<web logic> ? This is my pseudo-code that I would like to transform into using NON-BLOCKING web-ified code. Please keep in mind that I have only used this system for about 20 hours, so I'm pretty much a NEWBIE at this. 40 years experience at programing and 30 years with pascal and 16 years with Delphi. Procedure GetProperAge(Var Age:Integer);Var IRA:Boolean; IRA_LotsOfMoney:Boolean; IAmStupid:Boolean;BeginAge:=ReadAge;IAmStupid:=False;IRA_LotsOfMoney:=False;If Age>70 Then Begin If MessageDlg('Are you taking money from IRA?',[mbYes,mbNo]) = mrYes Then Begin IRA:=True; If MessageDlg('Do you take a lot of money?',[mbYes,mbNo]) = mrYes Then IRA_LotsOfMoney:=True End Else Begin IRA:=False; If MessageDlg('Are you stupid?',[mbYes,mbNo]) = mrYes Then IAmStupid:=True; End; End;If IAmStupid Then DoSomeStupidLogicIf IRA_LotsOfMoney Then DoOtherLogic// Now save the dataSaveMySettings(IRA_LotsOfMoney,IAmStupid);End; // My function that ends up calling the GetProperAge procedureProcedure SomeFunction;Var Age:Integer;Begin...GetProperAge(Age);...more logic...End; What would the web-ified code look like. When going from non object oriented code to object oriented code, there were key "concepts" that helped to understand it. When going from DOS based code, where the program would monitor keystrokes, and then going to event driven windows programming, there were key "concepts" that helped to understand it. I am not stupid, but I must admit, I am having a heck of a time trying to visualize how to convert this simple code over to the web-ified version that would work in the uniGUI system Any help is much appreciated. Thanks Davie Quote Link to comment Share on other sites More sharing options...
gerhard.kimmeringer Posted August 20, 2015 Share Posted August 20, 2015 Look at Demos - Dialogs at the callback-functions Quote Link to comment Share on other sites More sharing options...
vbdavie Posted August 20, 2015 Author Share Posted August 20, 2015 Thanks, but since I mentioned that I am new to the "web" way of thinking, AND new to uniGUI, your 8 word response doesn't help me at all. Sorry for being new to all this. I'm sure a seasoned person would make good use of that answer. The only thing that comes "close" to what I want is the DialogAnonymousCallBack.pas file. It shows some nested dialogs. But again, the examples DO NOT show how I can use variables that I set depending on the dialog answers in the code logic at the end of my procedure. The sample code looks like this... procedure TUniDialogAnonymousCallBack.UniButton6Click(Sender: TObject);begin{$ifdef COMPILER_12_UP} MessageDlg('Dialog3', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin case Res of mrYes : MessageDlg('Dialog4', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin case Res of mrYes : UniMemo1.Lines.Add('DResult: YES'); mrNo : UniMemo1.Lines.Add('DResult: NO'); end; end ); mrNo : UniMemo1.Lines.Add('DResult: NO'); end; end );{$else} ShowMessage('This feature is NOT available in this version of Delphi');{$endif}end; It's funny, I think the coders forgot the word "NOT" in the message I see the same mistake in may places and units, I wonder if I am missing something. Hmmm. Anyway, the example does NOT allow me to have local variables in the "uniButton6Click" method that are SET by the callback methods Also, since the messagedlg NEEDS to exit the uniButton6Click event right away, there's no chance for me to do anything with variables that I may have set. Look at my example again and you will see that once I have captured all the answers from the dialogs, I THEN use them to make some sort of database update. Begin .... // nested dialogs to obtain a series of answers...(IAmStupid, IRA_LotsOfMoney) ... // Logic to take those answers and then store them into the database If IAmStupid Then DoSomeStupidLogicIf IRA_LotsOfMoney Then DoOtherLogic// Now save the dataSaveMySettings(IRA_LotsOfMoney,IAmStupid);End; Also, the nested example doesn't indicate how to properly CALL the particular method. My example pseudo-code had this.... // My function that ends up calling the GetProperAge procedureProcedure SomeFunction;Var Age:Integer;Begin...GetProperAge(Age);...more logic...End; As you can see, my procedure called "SomeFunction" does some stuff and THEN CALLS GetProperAge (which has nested dialogs) and then does some more stuff. It is my understanding that if I call the GetProperAge or any method that contains nested dialogs, that the CALLING method should NOT have ANY logic after that calling statement. IE: It needs to exit right away so all the communication to the browser can do it's thing. That means where I have "more logic", should not be there according to the way I understand it. But yet my logic flow chart on paper and in my brain, indicates that after I call GetProperAge, I need to then do some stuff <more logic> SOOoooo, how do I accomplish this? I could be wrong. But I don't think so. Davie Quote Link to comment Share on other sites More sharing options...
Ron Posted August 23, 2015 Share Posted August 23, 2015 Hi Davie, Lets say you have a wizard kind of thing and needs to ask a number of questions, like this in linear fashion with blocking calls: .. MessageDlg('Question 1.... MessageDlg('Question 2.... MessageDlg('Question 3.... MessageDlg('Question 4.... StoreResults ...in the client-server non-blocking world you instead get this structure: procedure StartProcess MessageDlg('Question 1....callBack1); Procedure CallBack1(res) unimainModule.answer1:=res; MessageDlg('Question 2....callBack2); Procedure CallBack2(res) unimainModule.answer2:=res; MessageDlg('Question 3....callBack3); Procedure CallBack3(res) unimainModule.answer3:=res; MessageDlg('Question 4....callBack4); Procedure CallBack4(res) StoreResults(unimainModule.answer1, unimainModule.answer2, unimainModule.answer3, res) So you store the results along the way and then trigger new questions or branch out in a more decision tree-like structure if you like. /Kaj 1 Quote Link to comment Share on other sites More sharing options...
vbdavie Posted August 23, 2015 Author Share Posted August 23, 2015 So basically, you are saying that you can NOT keep a nice concise logic flow. It's going to be spread out all over the place and in order to get an overview of what's happening you have to do mental girations to get the full picture.... as opposed to the full picture being right in front of you in the desktop version? Davie Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted August 24, 2015 Share Posted August 24, 2015 You have the same problem if you are using delphi/firemonkey for programming android: there are no blocking calls (showmodal, message Dialog, ...). Quote Link to comment Share on other sites More sharing options...
Ron Posted August 24, 2015 Share Posted August 24, 2015 Full picture...well, I'm tempted say that programming itself involves a bunch of mental gyrations, and as you probably know, you never really get the full picture from any piece of abstract code...and that's why this suits some nerds like us and also why they pay us well - to think and try and create some order in this mess... As Henry Ford said, "Thinking is hard work - that's why so few do it." But you could probably do this with nested dialogs - you have this basic construct: MessageDlg('Dialog1', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin answer1:=res; //next end); Then try this: MessageDlg('Dialog1', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin uniMainModule.a1:=res; MessageDlg('Dialog2', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin uniMainModule.a2:=res; MessageDlg('Dialog3', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin uniMainModule.a3:=res; MessageDlg('Dialog4', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin StoreResults(uniMainModule.a1, uniMainModule.a2, uniMainModule.a3, res); end;); end;); end;); end;); If that works, you may have your full picture 1 Quote Link to comment Share on other sites More sharing options...
vbdavie Posted August 24, 2015 Author Share Posted August 24, 2015 DelphiDude; thanks. Look at my first text at the top of the thread. You will see an example of "GetProperAge" function. It's like 30 lines. Then I show about a 5 line example of how I might CALL the GetProperAge function. If you could pretty please with sugar on top please construct the proper equivilent code for UniGUI to make the "GetProperAge" work and to make the "SomeFunction" procedure to work. Many many thanks in advance. Davie Quote Link to comment Share on other sites More sharing options...
Ron Posted August 25, 2015 Share Posted August 25, 2015 //Hi Davie - I've not tested this but I hope you get the idea... //you may have to store the variables in mainform or unimainmodule Procedure GetProperAge(Var Age:Integer); Var IRA:Boolean; IRA_LotsOfMoney:Boolean; IAmStupid:Boolean; Begin Age:=ReadAge; IAmStupid:=False; IRA_LotsOfMoney:=False; If age>70 then begin MessageDlg('Are you taking money from IRA?', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin case res of mrYes: begin IRA:=True; MessageDlg('Are you taking money from IRA?', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin if res=mrYes then IRA_LotsOfMoney:=True If IRA_LotsOfMoney Then DoOtherLogic //If IAmStupid Then DoSomeStupidLogic - never needed in this branch // Now save the data SaveMySettings(IRA_LotsOfMoney,IAmStupid); end;); //second message dlg - first branch end; //case 1 mrNo: begin IRA:=False; MessageDlg('Are you stupid?', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin if res=mrYes then IAmStupid:=True; If IAmStupid Then DoSomeStupidLogic //If IRA_LotsOfMoney Then DoOtherLogic - not needed in this branch // Now save the data SaveMySettings(IRA_LotsOfMoney,IAmStupid); end;); //second message dlg - second branch end; //case 2 end); //first message dlg end; //if age... SaveMySettings(false, false); //if you are younger. end; // My function that ends up calling the GetProperAge procedure Procedure SomeFunction; Var Age:Integer; Begin ... GetProperAge(Age); ... //more logic <--- this must be moved into the branches to make sure they get executed after the other stuff //if this process depends on the results of the other stuff ... End; 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.