Jump to content

Steve Maughan

Members
  • Content Count

    103
  • Joined

  • Last visited

Everything posted by Steve Maughan

  1. Hi Dany, Because the min before may change and not be the min before. I don't want to have to it's through to find a new minimum value. Thanks, Steve
  2. Hi Stefan, Each item's value changes slightly on each iteration. Note also, finding the min item may take more than one comparison per change (if the min item's value changes such that it's not now the min item). Thanks, Steve
  3. Thanks Tim, The algorithm updates the items' values 100k to 1 million times a second, so speed is important. Nevertheless, you might be right; I should probably keep it simple. Steve
  4. Hi Everyone, This could well be a complete "noob" question as I'm not that experienced with the parallel library. My objective is to utilize a parallel "for loop" in my optimization algorithm. Here's the code: TParallel.&For(0, fCriteria.Population - 1, procedure(i: integer) var xNode: TOptNode; begin //-- Get the latest node TThread.Synchronize(nil, procedure begin xNode := PopNode; end); //-- Get the new centers xNode.GenerateNewCenters; //-- Evaluate new centers xNode.Evaluate; //-- Push the node back onto the stack TThread.Synchronize(nil, procedure begin PushNode(xNode); end); end); Each iteration of the loop tests a new scenario (xNode.GenerateNewCenters) and stores the best one found (xNode.Evaluate). The TOptNode holds all the data that needs to be optimized. It's a large object and takes significant time to be created. So I've created a TStack of TOptNode object, and only create them when needed. I need to be able to "pop" the xNode objects off the stack and "push" them back on in a thread safe way. I would have thought the code above would work, instead it just freezes when it comes to the "for" loop. What's the best way to "push" and "pop" in a thread safe manner inside of a parallel "for loop"? Thanks, Steve
  5. I think I've solved it by using a TThreadList object as pseudo stack (FooList in the code below). This was something new for me. Previously I mistakenly thought "TThreadList" was a list of threads, whereas it's really a generic thread-safe list. The thread-safe pop and push procedures are as follows: function TForm1.PopFoo: TFoo; var xList: TList<TFoo>; begin xList := FooList.LockList; try if xList.Count > 0 then begin result := xList.Last; xList.Delete(xList.Count - 1); end else result := TFoo.Create; finally FooList.UnlockList; end; end; procedure TForm1.PushFoo(xFoo: TFoo); begin FooList.Add(xFoo); end; In case anyone is interested I've attached the full source of the example project. Thanks for the help, Steve Synchronize2.zip
  6. Hi David, Thanks for the input but I've just provided a complete example. See attached above. You have all the code. Based on your comment are you suggesting I mark the push and pop as Critical Sections? I haven't locked code before so please excuse my ignorance. Thank again, Steve
  7. See attached for a simplified example . The procedure "ProcessSingleThreaded" works as expected, but the procedure "ProcessMultiThreaded" freezes the system: procedure TForm1.ProcessMultiThreaded; var xBest: integer; i: integer; begin Screen.Cursor := crHourGlass; TParallel.&For(0, LoopSize - 1, procedure(j: integer) var xFoo: TFoo; begin //-- Get the Foo Object TThread.Synchronize(nil, procedure() begin xFoo := PopFoo; end); //-- Evaluate xFoo.Evaluate; //-- Push Back to the Stack TThread.Synchronize(nil, procedure() begin PushFoo(xFoo); end); end); xBest := 0; for i := 0 to FooList.Count - 1 do xBest := Max(xBest, FooList[i].BestValue); Form1.Caption := IntToStr(xBest); Screen.Cursor := crDefault; end; Why is the TThread.Synchronize freezing the application? All help appreciated, Thanks, Steve Synchronize.zip
  8. Hi David, PopNode and PushNode don't do anything special. I've listed the code below: function TOptimizer.PopNode: TOptNode; begin if fNodeStack.Count > 0 then result := fNodeStack.Pop else begin result := TOptNode.Clone(fMasterNode); fNodeList.Add(result); end; end; procedure TOptimizer.PushNode(xNode: TOptNode); begin fNodeStack.Push(xNode); end; All they do is either pop the Node if one already exists on the stack, or create a new node if the stack is empty. Clearly I don't want multiple threads popping and pushing at the same time. That's why the main thread should do all of the popping and pushing. Thanks, Steve
  9. Steve Maughan

    isFileInUSe

    I had the same problem. Here's the fix: https://stackoverflow.com/questions/28363917/delphi-2010-is-file-in-use/54138875?noredirect=1#comment99036951_54138875
  10. Has anyone had any success using Direct2D with multiple threads (i.e. multiple threads attempting to draw to the canvas at the same time)? It seems possible according to this link: https://docs.microsoft.com/en-us/windows/desktop/direct2d/multi-threaded-direct2d-apps But I can't find anything Delphi specific information. Any links or sample code appreciated. Thanks - Steve
  11. There are quite a few Excel components available but I can't find any component to generate a PowerPoint presentation file. I realize I can possibly do this via OLE automation but that seems a little "flaky" to me. Does anyone know of a such PowerPoint component? Thanks, Steve
  12. Steve Maughan

    How to Export a PowerPoint PPTX File?

    Thanks - it's news to me!
  13. I'm looking to implement high-definition printing and exporting for our mapping application. I'm planning to do this by creating a PDF. The solution will need to be able to create PDFs with custom polygons at a desired resolution. I've done a brief search and Gnostice's eDocEngine seems to fit the bill. Before I dive in I thought I'd ask if anyone had any other suggestions or any feedback about Gnostice's solution, Thanks, Steve
  14. Steve Maughan

    Advice Needed: PDF Graphics Rendering Suite??

    It's one of Joe Hecht's sites. He has a few and they all look the same. I gave him some similar honest feedback over on Google+ a few years' ago. He agreed, but nothing seems to have changed. It's a pity since I'm sure the components are decent. It would take no more than two days to replace these sites with a good WordPress theme.
  15. Steve Maughan

    Advice Needed: PDF Graphics Rendering Suite??

    Interesting!! I'll take a closer look. Thanks, Steve
  16. Steve Maughan

    Is there GIS library for delphi (Free or very cheap)

    CartoVCL looks interesting but hasn't been updated since 2015. Abandonware regards, Steve
  17. The way Delphi handles application icons seems to be terrible. Here's what happened. We have a new icon for our application. I managed to delete the old icon and all *.res file and update it with a new icon. Then suddenly the application is using the wrong icon in the main form. I've repeated the icon update process once again and now I seem to have messed things up. I now have the default icon as the application icon. OK - rant over, now for my questions: Is there an approved step-by-step process for changing a Delphi application's icon? How do I determine which size icon is used for the main form. Is it the 16x16 or 24x24 version of the main icon? Thanks, Steve
  18. Steve Maughan

    Right Process for Changing an Application's Icon?

    Anders - Awesome - thanks!
  19. Steve Maughan

    Right Process for Changing an Application's Icon?

    Thanks Anders. This is really helpful. Can I ask, what is the resource editor you're using in the screenshot? Steve
  20. I have a TPaintBox where I normally process OnMouseDown, OnMouseMove and OnMouseUp events. I'd like to perform an action using the DoubleClick even. It seems that when the user double clicks the order of events is as follows: OnMouseDown OnMouseUp OnDblClick OnMouseDown OnMouseUp I'd like to cancel / "eat" the second OnMouseDown and OnMouseUp events. How can I do this? Setting them to "nil" doesn't seem to work. Thanks - Steve
  21. Steve Maughan

    How to "eat" the second OnMouseDown / OnMouseUp events after a DblClick?

    Hi Attila, Thanks! Yes - I managed to get it working using a similar technique. I set a flag in the DblClick event and then sent a message to clear the flag. Steve
  22. Steve Maughan

    How to "eat" the second OnMouseDown / OnMouseUp events after a DblClick?

    Looks like I haven't figured it out at all. It seems much more complex. Here's the order of events: OnMouseDown (processed with no problem) OnMouseUp (processed with no problem) OnDblClick - I'm showing a form for the user at this point. The GUI is recording the mousemove actions and generating OnMouseMove messages OnMouseDown - the second OnMouseDown of the double click, which can be ignored using a flag OnMouseUp - the second OnMouseUp of the double click, which can be ignored using a flag, and the fag can be reset Multiple OnMouseMove - then all of the OnMouseMove messages that were generated while the form was showing are now processed How do I either ensure the OnMouseMove messages aren't generated when the form is shown, or how do I remove them from the message queue? Here's a short video that shows the behavior: All help appreciate! Thanks, Steve
  23. Steve Maughan

    How to "eat" the second OnMouseDown / OnMouseUp events after a DblClick?

    I figured it out. Set a flag on the DblClick event, exit out of the OnMouseDown if the flag is set, then do the same for OnMouseUp but also reset the flag.
  24. I hope this is an easy question to answer... How to get access to quality.embarcadero.com? My normal email and password that I use for the Maintenance site doesn't work. Thanks, Steve
×