-
Content Count
920 -
Joined
-
Last visited
-
Days Won
56
Everything posted by pyscripter
-
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
Use for key in spam.myPoint.ColumnA.Keys.ToArray(): print(key) It is possible to allow for a more natural iteration, but it would require to hand craft the TDictionary wrapper. See for instance how it is done in TPyDelphiStrings in WrapDelphiClasses. -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
You could allow for both Point() and Point(x, y) by modifying CreateWith if PyArg_ParseTupleAndKeywords(args, kwds, '|ICreatePoint') then // no arguements else if PyArg_ParseTupleAndKeywords(args, kwds, 'ii|:CreatePoint', @fx, @fy) then // two integer arguements begin ... end; -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
To be able to create columns you need to also to customize the TColumn wrapper: TColumnWrapper = class(TPyClassWrapper<TColumn>) constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override; end; constructor TColumnWrapper.CreateWith(APythonType: TPythonType; args, kwds: PPyObject); var W: integer; P: PPyObject; begin Create(APythonType); GetPythonEngine.PyArg_ParseTuple(args, 'iO:CreateColumn', @W, @P); DelphiObject := TColumn.Create; DelphiObject.Width := W; DelphiObject.Visible := GetPythonEngine.PyObject_IsTrue(P) = 1; end; then register it in Form.Create PyDelphiWrapper.RegisterDelphiWrapper(TColumnWrapper).Initialize; PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<string, TColumn>>).Initialize; Then the following code works: from spam import myPoint, Column print(myPoint.ColumnA['Note'].Width) print(myPoint.ColumnA['Note'].Visible) new_column = Column(100, False) myPoint.ColumnA.Add('Note1', new_column) print(myPoint.ColumnA['Note1'].Width) print(myPoint.ColumnA['Note1'].Visible) -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
Assuming your register the dictionary as shown above the following works. from spam import myPoint print(myPoint.ColumnA['Note'].Width) print(myPoint.ColumnA['Note'].Visible) -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
Please use the latest version from https://github.com/pyscripter/python4delphi/. Not the Getit version. Here PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<string, TColumn>>).Initialize; works. You could also subclass TDictionary<string, TColumn>. type TColumnDict = class( TDictionary<string, TColumn>) end; and in Form.Create PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TColumnDict>).Initialize; -
Wrap TDictionary - TypeError: 'Object' object is not subscriptable
pyscripter replied to iqrf's topic in Python4Delphi
You need to register the TDictionary<String,TColumn> in Form.Create, PyDelphiWrapper.RegisterDelphiWrapper(TPyClassWrapper<TDictionary<String,TColumn>>).Initialize; Have not tested, Does it work? -
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?