-
Content Count
914 -
Joined
-
Last visited
-
Days Won
55
Everything posted by pyscripter
-
RegExpressions and preUnGreedy
pyscripter replied to Jacek Laskowski's topic in RTL and Delphi Object Pascal
See the record helpers in https://github.com/pyscripter/Pcre-Jit-Delphi/blob/master/Demos/benchmark.dpr and the methods SetAdditionalPCREOptions -
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.
-
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.
-
How to call a python function with parameter and get the result
pyscripter replied to softtouch's topic in Python4Delphi
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. -
The TPythonEngine instance is being terminated automatically
pyscripter replied to djxandytche's topic in Python4Delphi
A single TPythonModule and TPyDelphiWrapper should do. Running python code in threads is quite complex. See PythonThreads · pyscripter/python4delphi Wiki (github.com) for details. -
The TPythonEngine instance is being terminated automatically
pyscripter replied to djxandytche's topic in Python4Delphi
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. -
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.
-
I meant call CheckError before that.
-
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.
-
Add some error checking after the call. GetPythonEngine.CheckError; What is the error you are getting? It might help to post a minimal project.
-
It is explained in the link to CudaText I gave above.
-
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.
-
Load a Python module and call its functions within Delphi code without ExecString
pyscripter replied to araujoarthur's topic in Python4Delphi
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. -
Load a Python module and call its functions within Delphi code without ExecString
pyscripter replied to araujoarthur's topic in Python4Delphi
How about? var SL := TStringList.Crete; try SL.LoadFromFile('example.py'); PyEngine.ExecStrings(SL); var Res := MainModule.DoExample('input'); finally SL.Free; end; -
Problems while importing libraries with conda
pyscripter replied to delphivi's topic in Python4Delphi
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. -
Problems while importing libraries with conda
pyscripter replied to delphivi's topic in Python4Delphi
Have you read FindingPython · pyscripter/python4delphi Wiki (github.com) regarding Conda? Is the DLLs subdirectory in the environment path? -
SearchBuf issue since Delphi 11.2 fix for wholeword searching.
pyscripter replied to MarkShark's topic in RTL and Delphi Object Pascal
Please open an issue and describe the problem. Using SearchBuf should be OK. -
SearchBuf issue since Delphi 11.2 fix for wholeword searching.
pyscripter replied to MarkShark's topic in RTL and Delphi Object Pascal
See -
Have seen https://github.com/Embarcadero/DelphiVCL4Python/issues/12?
-
Please submit an issue to the relevant repo. I would expect that simply recompiling the component source with Delphi 12 should work.
-
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.
-
Favorite feature(s) of other editors that Delphi does not offer
pyscripter replied to dummzeuch's topic in Delphi IDE and APIs
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 ... -
See The buffer protocol has been implemented · pyscripter/python4delphi · Discussion #443 (github.com) and demo 35.
-
Locking an Object
pyscripter replied to fastbike's topic in Algorithms, Data Structures and Class Design
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. -
Locking an Object
pyscripter replied to fastbike's topic in Algorithms, Data Structures and Class Design
Indeed. This is the whole purpose of locking.