repeat until as a single statement lazarus / 61-Beginners ---------------------------------------------------------------------- Weiss · 2022-08-21 03:52 I came across this, and can't wrap my head around what it does, when "repeat until [condition]; " is a single statement. Repeat what, if there is no code between the two? There is no  "Begin .. End" below or above. ---------------------------------------------------------------------- 440bx · 2022-08-21 04:14 Quote from: Weiss on August 21, 2022, 05:52:06 amI came across this, and can't wrap my head around what it does, when "repeat until [condition]; " is a single statement. Repeat what, if there is no code between the two? If the condition includes a function call then that would cause the function to be called until the result of the expression become true.  It could also be done with an empty "while" loop. IOW, what gets repeated is the function (or functions) that are part of the condition. ---------------------------------------------------------------------- MarkMLl · 2022-08-21 07:35 Quote from: Weiss on August 21, 2022, 05:52:06 amI came across this, and can't wrap my head around what it does, when "repeat until [condition]; " is a single statement. Repeat what, if there is no code between the two? There is no  "Begin .. End" below or above. Read the Pascal definition. Unlike while, which operated upon a single statement (which might be a compound statement, i.e. begin ... stuff ... end) a repeat always has a matching end and operates on the zero or more statements between them. MarkMLl ---------------------------------------------------------------------- Thausand · 2022-08-21 08:13 Quote from: Weiss on August 21, 2022, 05:52:06 amI came across this, and can't wrap my head around what it does, when "repeat until [condition]; " is a single statement. Repeat what, if there is no code between the two? no code = nothing. this similar; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program nothing; const  condition=false; begin  while not condition do {nothing};   repeat {nothing} until condition;end.  Not make many sense but similar. Make sense when condition change, example KeyPressed, Thread or Interrupt finish. ---------------------------------------------------------------------- MarkMLl · 2022-08-21 08:37 Quote from: Thausand on August 21, 2022, 10:13:58 amno code = nothing. this similar; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program nothing; const  condition=false; begin  while not condition do {nothing};   repeat {nothing} until condition;end.  It's worth highlighting there that the really important thing is the semicolon immediately after the do, i.e. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   while not condition do ;  somethingElse();  is the same as Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   while not condition do begin  end;  somethingElse();  It's absolutely essential for a beginner to understand this. begin-end does not need to be used if it is only enclosing a single statements, and getting the positioning of statements and semicolons will result in code that does not behave as expected (look up the "dangling else problem"). MarkMLl ---------------------------------------------------------------------- Bart · 2022-08-21 08:57 Quote from: Weiss on August 21, 2022, 05:52:06 amI came across this, and can't wrap my head around what it does, when "repeat until [condition]; " is a single statement. Classical example from my old TP days: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   ClrKbd; {remove any keystrokes from the keyboardbuffer}  write('Press any key to continue... ');  repeat until KeyPressed; {Pascal being a verbose language: this statement hardly needs explaining ;-) }  Bart ---------------------------------------------------------------------- Weiss · 2022-08-21 09:27 Quote from: Thausand on August 21, 2022, 10:13:58 am Make sense when condition change, example KeyPressed, Thread or Interrupt finish. it was actually “repeat until not lpressed” (mouse left button).  So, works like “wait until”? I implemented this chunk of someone’s else code out of desperation, couldn’t find documentation for winMouse, was looking for sort of equivalent for “readkey”, which does not exist for winmouse. Turned out better than I thought it would. But I don’t understand, why my interactive chart gets updated, replotted with new values, while I hold button pressed. To my understanding, program flow should have been locked in a loop until I release button, and then program was supposed to roll through to another cycle. Quote from: 440bx on August 21, 2022, 06:14:37 amIf the condition includes a function call then that would cause the function to be called until the result of the expression become true.  It could also be done with an empty "while" loop. IOW, what gets repeated is the function (or functions) that are part of the condition. interesting. You mean like a recursive call? ---------------------------------------------------------------------- MarkMLl · 2022-08-21 09:46 Quote from: Weiss on August 21, 2022, 11:27:23 amBut I don’t understand, why my interactive chart gets updated, replotted with new values, while I hold button pressed. ... interesting. You mean like a recursive call? Because the function being invoked in your until condition has side- effects. And it is nothing at all like a recursive call. MarkMLl ---------------------------------------------------------------------- Thausand · 2022-08-21 10:56 Quote from: Weiss on August 21, 2022, 11:27:23 amit was actually “repeat until not lpressed” (mouse left button). There was suspicion it something like button or key press  Note: condition can be: - function with many code, then return boolean (lpressed is that) - boolean variable that is change by program-code that is run somewere else (background/paralel/async). QuoteSo, works like “wait until”? In example you show, yes: Wait until left mouse button press. QuoteBut I don’t understand, why my interactive chart gets updated, replotted with new values, while I hold button pressed. To my understanding, program flow should have been locked in a loop until I release button, and then program was supposed to roll through to another cycle. If take look to unit winmouse then can see there assign function msghandler to graph.mousemessagehandler. Window program have msg-pump-loop that get message for mouse, keyboard, etc. it is for recognise message and then handle message. Example scroll-button message that is delegate to lazarus component. This loop is run in background and unit winmouse make special message handler (graph.mousemessagehandler) for mouse, then change variable winmouse.mousebuttonstate when mouse button is press up/down (left/right/middle). function LPressed look like: Code: [Select]Function LPressed:Boolean; begin   LPressed:=(mousebuttonstate and LButton)<>0; end; Flow: - In background window message-pump-loop is run and wait for message. Note: you program is run same time (after background window is create) - message-pump-loop delegate message to graph.mousemessagehandler - graph.mousemessagehandler call winmouse.msghandler - winmouse.msghandler then check when mouse-button press and change variable mousebuttonstate - you program (note: again is running, repeat until) is call lpressed (see code) - lpressed see change mousebuttonstate and condition is change, you program is continue from repeat until. For normal situation is important and know that repeat {nothing} until and while do {nothing} and have no code for nothing and is use in window program, that can make cpu run 100% power (because many times do nothing in loop). Then better use sleep(x) and ot {nothing}. Maybe winmouse/graph is different and have default better time-slice implement and there no need and call sleep(). You can check self  @MarkMLI: yes, ";" there very important. ---------------------------------------------------------------------- Weiss · 2022-08-21 16:09 Quote from: Thausand on August 21, 2022, 12:56:46 pm For normal situation is important and know that repeat {nothing} until and while do {nothing} and have no code for nothing and is use in window program, that can make cpu run 100% power (because many times do nothing in loop). Then better use sleep(x) and ot {nothing}. Maybe winmouse/graph is different and have default better time-slice implement and there no need and call sleep(). You can check self  @MarkMLI: yes, ";" there very important. I thought of adding delay in between, but it works so sweet as is. Where do I find winmouse unit documentation? I spent considerable time googling winmouse but all I can find is references to it, and someone’s code snippets, but not actual documentation. I need mouse wheel for example. ---------------------------------------------------------------------- MarkMLl · 2022-08-21 16:21 Quote from: Weiss on August 21, 2022, 06:09:48 pmI thought of adding delay in between, but it works so sweet as is. The behaviour you're seeing suggests that it's not blocking the OS, so since adding a delay in the main thread can be hazardous I'd suggest not worrying about it. QuoteWhere do I find winmouse unit documentation? I spent considerable time googling winmouse but all I can find is references to it, and someone’s code snippets, but not actual documentation. I need mouse wheel for example. It appears to be a Windows API, so presumably in the same place that MS documents all their stuff these days... wherever that is... Having said that, you'd probably be better off- at least in terms of portability- if you were using a facility from the LCL. But you'd need to provide a far more robust description of what you're trying to do, and it might be better in the LCL section of the forum. MarkMLl ---------------------------------------------------------------------- Thausand · 2022-08-21 17:01 Quote from: Weiss on August 21, 2022, 06:09:48 pmWhere do I find winmouse unit documentation? I make assumption you have use fpc packages that have unit winmouse. If yes, then here is source. QuoteI spent considerable time googling winmouse but all I can find is references to it, and someone’s code snippets, but not actual documentation. If yes it same unit, then there no documentation. Unit winmouse is not for use direct. Is implementation for unit Mouse. If you work with fpc and unit graph/mouse then is unfortuna no wheelmouse. QuoteI need mouse wheel for example. As write by MarkMLI: what you try do ? Maybe can make easier and use PTCGraph/SDL/OPenGL/LCL/fpGUI/other. There many option but depend on you what want  (*) there also very old winmouse/wingraph units that was Delphi that make DOS unit Graph/Mouse work graphical for Windows. That unit not FPC supported. I think if you have use FPC unit for that then is 3th party unit. Is confuse and all have same name for nit. ---------------------------------------------------------------------- Weiss · 2022-08-21 22:01 what I am trying to do (since this was asked more than once): the application I built is very basic data visualization. I made it in FPC. I haven’t learned Lazarus yet. I open text file, filled with numeric data from diesel engines, boost pressure, engine speed, fuel press etc, long list of channels I can choose from. Text file is converted into two-dimentional array from comma separated text, which is further converted to numeric data. First three lines are names of channels, measure units etc, ( all strings) which I also incorporate into graph. I also build a timeline, since I know when data log has started and sample rate. Then I display channels names available, and let user to choose which channels to plot, and from there I scale every channel to the size of plot area. I also incorporated graph controls from keyboard, to zoom in-out, pan left, pan right, etc. With your help, I also learned how to save graph, which shows the are of interest (engine interlock, loss of parameter etc). At that point I was pretty much done, achieved basic functionality. Except everybody is so used to mouse, my coworkers always seem to start rolling a mouse and clicking buttons. So I decided to add mouse to my interactive graphs. I think will finish rough implement today. Will polish later, if I feel like. This is a goodwill hobby-at-work project, on a very old computer (1997 windows xp) which is not connected to internet. I build new version and port it to target computer from usb stick. That is why I wasn’t doing it in c#, or matlab, those are heavy as pile of bricks. ---------------------------------------------------------------------- MarkMLl · 2022-08-22 06:49 So can we assume for the moment that this is a console program running under Windows, with users selecting items from a list and results displayed in a graph component? I think that really you should be relying on the graph component to handle the mouse, since mouse support was very much "tacked onto" console operations for just about every target. If the graph component doesn't support it directly, I don't think you'll do better than you currently are. I think you'd make life easier for yourself if you investigated Lazarus since the components in the class library are fairly comprehensive, but you'd still start jumping through hoops if the data display component didn't support some UI idiom that your users assumed. I think it's also safe to say that you'll have problems on just about any platform if your user interface resembles the original AutoCAD one, whether there were both GUI elements and an interactive command line. MarkMLl ---------------------------------------------------------------------- Weiss · 2022-08-22 18:08 Quote from: MarkMLl on August 22, 2022, 08:49:08 amI don't think you'll do better than you currently are. ... I think you'd make life easier for yourself if you investigated Lazarus... MarkMLl Mark, I totally agree, should finally start tapping away at Lazarus. The reason I built my project in FPC is because I was still learning basics of the language. ---------------------------------------------------------------------- MarkMLl · 2022-08-22 18:27 Quote from: Weiss on August 22, 2022, 08:08:50 pmMark, I totally agree, should finally start tapping away at Lazarus. The reason I built my project in FPC is because I was still learning basics of the language. There's actually two things here. The first is that moving to a full GUI-oriented app (subject to my point about an internal command line not being very well-supported) using the LCL would probably be a pleasant treat for your users. The second is that even for a console-oriented app, using Lazarus as the IDE will probably make debugging etc. more pleasant. MarkMLl