Jump to content

pyscripter

Members
  • Content Count

    914
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by pyscripter

  1. pyscripter

    RegExpressions and preUnGreedy

    See the record helpers in https://github.com/pyscripter/Pcre-Jit-Delphi/blob/master/Demos/benchmark.dpr and the methods SetAdditionalPCREOptions
  2. XML used to be considered the universal data format. Now is a bit passé with JSON, YAML etc being "in". I got involved in XML parsing, since SVG files are in XML format. XML Delphi support At the surface the XML support in Delphi is very good: You have TXMLDocument/IXMLDocument offering high-level support (Xml.xmldoc) Support for the standard DOM interfaces (Xml.XmlDom) Multiple implementations including (MSXML, OmniXML, OpenXML and more) Ability to plug in your own implementation Multiple platform support. The most common way of accessing XML is through TXMLDocument/IXMLDocument. However there is a big catch: PERFORMANCE. Say you want to use MSXML and you specify 'MSXML' as your DefaultDomVendor. (or you simply include the implementation unit Xml.Win.msxmldom in your uses clause). Your create an XML document and you access the top node: var Doc: IXMLDocument = TXMLDocument.Create(nil); var Node: IXMLNode := Doc.DocumentElement; Node is an IXMLInterface implemented by TXMLNode (TInterfacedObject defined in Xml.XmlDoc). TXMLNode wraps an IDOMNode stored in a private field FDOMNode. IDOMNode is defined in Xml.Xmldom. The IDOMNode is implemented by the used vendor in this case Xml.Win.msxmldom by a class TMSDOMNode TMSDOMNode (also a TInterfacedObject) wraps IXMLDOMNode stored in a private field FMSNode. IXMLDOMNode is defined in Winapi.msxml. As a result when you create any IXMLNode, a TXMLNode is created and this creates a TMSDOMNode which points to an IXMLDOMNode. Any call/property access to IXMLNode translates in a call of IDOMNode which then calls IXMLDOMNode. The created TInterfaced objects also need to be destroyed when you release your XML Node. The same two-level indirection applies to all XML objects (attributes, Children) and cause a huge degradation of performance. Conclusion If you care about speed forget about TXMLDocument. You can access the Vendor implementation or even better in the case of MSXML the Microsoft ActiveX objects directly: uses WinAPI.msxml var XML: IXMLDOMDocument3 := CoDOMDocument60.Create; XML.loadXML(XMLString); var DocNode: IXMLDOMNode := XML.documentElement; In SVG parsing and processing accessing directly the ActiveX objects reduced processing time by more than 50%. Additional tip A common performance pitfall with MSXML is explained in http://www.gerixsoft.com/blog/delphi/msxml. The fastest way to iterate through ChildNodes is via getFirstChild/nextSibling and Attributes via nextNode.
  3. pyscripter

    Multi Istance problem

    I think this has to do with the default encoding of the pipe stdout. Python uses utf8, however since the script is run from a Delphi program it may inherit the encoding from the parent process. Just a guess.
  4. uses VarPyth; ... var Res, S: string; PythonEngine1.ExecStrings(sl); Res := MainModule.Parser(S); It would help to watch the tutorial videos and play with the Demos.
  5. A single TPythonModule and TPyDelphiWrapper should do. Running python code in threads is quite complex. See PythonThreads · pyscripter/python4delphi Wiki (github.com) for details.
  6. Why create/destroy/recreate the PythonModule and PythonWrapper instead of reusing them? To avoid the finalization of the PythonEngine keep at least one client alive.
  7. pyscripter

    P4D FMX requirements

    Do you have the appropriate python lib in your system? eg. See also the replies in Getting started with Ubuntu 18.04. Error Could not open DLL - Python4Delphi - Delphi-PRAXiS [en] (delphipraxis.net) I would try first to run a console app and when this works then try an FMX app.
  8. pyscripter

    Howto use P4D Demo29 with PIL and OpenCV

    I meant call CheckError before that.
  9. pyscripter

    Howto use P4D Demo29 with PIL and OpenCV

    Also have a look at Demo 35 to see how you transfer arrays and array-like objects from Python to Delphi using the buffer protocol.
  10. pyscripter

    Howto use P4D Demo29 with PIL and OpenCV

    Add some error checking after the call. GetPythonEngine.CheckError; What is the error you are getting? It might help to post a minimal project.
  11. pyscripter

    Is there any edit/memo which allows multiselect?

    It is explained in the link to CudaText I gave above.
  12. pyscripter

    Is there any edit/memo which allows multiselect?

    All modern code editors have multi-select and multi-caret functionality (Visual Studio, VS-Code, Scintilla, Atom etc.). Also the freepascal CudaText. See CudaText - Free Pascal wiki for how it works. Very useful. I am currently working to add this to SynEdit.
  13. The sample code above uses VarPyth for high level access to python objects. MainModule is custom variant wrapping the __main__ python module. Unless you provide optional parameters to ExecStrings, the code is executed in the context of the __main__ module.
  14. How about? var SL := TStringList.Crete; try SL.LoadFromFile('example.py'); PyEngine.ExecStrings(SL); var Res := MainModule.DoExample('input'); finally SL.Free; end;
  15. pyscripter

    Problems while importing libraries with conda

    Are you calling SetPythonHome, as suggested in that page? Have you tried MaskFPUExceptions(True) instead? Is the Conda Library\bin subdirectory in the system path? If not try adding it.
  16. pyscripter

    Problems while importing libraries with conda

    Have you read FindingPython · pyscripter/python4delphi Wiki (github.com) regarding Conda? Is the DLLs subdirectory in the environment path?
  17. Please open an issue and describe the problem. Using SearchBuf should be OK.
  18. pyscripter

    D4P_export_demo

    Have seen https://github.com/Embarcadero/DelphiVCL4Python/issues/12?
  19. pyscripter

    Delphi4PythonExporter

    Please submit an issue to the relevant repo. I would expect that simply recompiling the component source with Delphi 12 should work.
  20. pyscripter

    TDirect2dCanvas Issues

    The Direct2D way of printing is to use the ID2D1PrintControl interface (Printing and command lists - Win32 apps | Microsoft Learn). You can look at SynEdit/Source/SynEditPrint.pas at master · pyscripter/SynEdit (github.com) for how this works.
  21. Features missing in the Delphi editor: Proper Unicode handling . It does not even support combining characters. Multi-cursor/selection editing Modification (track changes) bar that works with undo. Accessibility support Drag & drop editing triple and quadruple click support double/triple click and drag support Enhanced scroll bar as in VS Code ...
  22. pyscripter

    2D numpy Array back to delphi

    See The buffer protocol has been implemented · pyscripter/python4delphi · Discussion #443 (github.com) and demo 35.
  23. pyscripter

    Locking an Object

    Here is a lock-free implementation for your FHIROperationFactory function. var SingletonFHIROperationFactory : IFHIROperationFactory function FHIROperationFactory: IFHIROperationFactory; var LFHIROperationFactory: IFHIROperationFactory; begin if SingletonFHIROperationFactory = nil then begin LFHIROperationFactory := TFHIROperationFactory.Create; if InterlockedCompareExchangePointer(Pointer(SingletonFHIROperationFactory), Pointer(LFHIROperationFactory), nil) = nil then SingletonFHIROperationFactory._AddRef; end; Result := SingletonFHIROperationFactory; end; Delphi does something similar in some places.
  24. pyscripter

    Locking an Object

    Indeed. This is the whole purpose of locking.
×