-
Content Count
966 -
Joined
-
Last visited
-
Days Won
61
Everything posted by pyscripter
-
The following console app works fine: {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Classes, System.Generics.Collections; type TMethodList = TList<TMethod>; const Method: TMethod = (Code:nil; Data:nil); begin try var fKeyDownChain := TMethodList.Create; try fKeyDownChain.Add(Method); fKeyDownChain.Remove(Method); WriteLn(fKeyDownChain.Count); finally fKeyDownChain.Free; end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; ReadLn; end. However the exact same sequence results in an access violation when used in a larger Win64 application. const Method: TMethod = (Code:nil; Data:nil); begin fKeyDownChain := TMethodList.Create; fKeyDownChain.Add(Method); fKeyDownChain.Remove(Method); The error occurs when you call Remove, at the first statement of the following function of System.Generics.Defaults, class function TComparer<T>.EQOperCompare(Self: Pointer; const Left, Right: T): Integer; begin if TRecEqualityOperator<T>(_GetExtInstanceData(Self, 0))(Left, Right) then Result := 0 else Result := BinaryCompare(@Left, @Right, SizeOf(T)); end; In the console application this statement results in a call to TMethod.Equal, Any clues as to why the error occurs? Update: This is a consequence of [RSP-43423] Using {$WEAKLINKRTTI ON} causes access violation on TList<T>.IndexOf method - Embarcadero Technologies. The console application also fails with {$WEAKLINKRTTI ON}. I guess specifying a Comparer would be a workaround. Is there any other workaround apart from removing the WEAKLINKRTTI directive, which increases the size of the executable by 2Mb? . Beyond the executable size, this is quite a serious issue, because it makes the use of generic collections of records in components unsafe, since a user of such a component setting WEAKLINKRTTI to ON, could face unpredictable and hard to detect crashes.
-
Weird error with generic TList
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
Delphi 12.2 fixed this. -
New Warning in 12.2: Overloading a similar index type by declaring an array property 'Items'
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
Interestingly the build dialog box reports this as 3 warnings! -
This is the public interface: TParallelArrayForProc<T> = reference to procedure (const AValues: array of T; AFrom, ATo: NativeInt); TParallelArray = class public class procedure &For<T>(const AValues: array of T; const AProc: TParallelArrayForProc<T>); overload; static; class procedure &For<T>(const AValues: array of T; const AProc: TParallelArrayForProc<T>; AIndex, ACount: NativeInt); overload; static; class procedure &For<T>(const AValues: array of T; const AProc: TParallelArrayForProc<T>; AIndex, ACount: NativeInt; APool: TThreadPool; AThreshold: NativeInt); overload; static; class procedure &For<T>(const AValues: TArray<T>; const AProc: TParallelArrayForProc<T>); overload; static; inline; class procedure &For<T>(const AValues: TArray<T>; const AProc: TParallelArrayForProc<T>; AIndex, ACount: NativeInt); overload; static; inline; class procedure &For<T>(const AValues: TArray<T>; const AProc: TParallelArrayForProc<T>; AIndex, ACount: NativeInt; APool: TThreadPool; AThreshold: NativeInt); overload; static; inline; class procedure Sort<T>(var AValues: array of T); overload; static; class procedure Sort<T>(var AValues: array of T; const AComparer: IComparer<T>); overload; static; class procedure Sort<T>(var AValues: array of T; const AComparer: IComparer<T>; AIndex, ACount: NativeInt; APool: TThreadPool); overload; static; class procedure Sort<T>(var AValues: TArray<T>); overload; static; inline; class procedure Sort<T>(var AValues: TArray<T>; const AComparer: IComparer<T>); overload; static; inline; class procedure Sort<T>(var AValues: TArray<T>; const AComparer: IComparer<T>; AIndex, ACount: NativeInt; APool: TThreadPool); overload; static; inline; class property ForThreshold: NativeInt read FForThreshold write FForThreshold default 50000; class property SortThreshold: NativeInt read FSortThreshold write FSortThreshold default 5000; end;
-
New Warning in 12.2: Overloading a similar index type by declaring an array property 'Items'
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
Aha! So is the type of the indexed property that the compiler complains about and not just the fact that you overwrite the inherited indexed property! And it is the change of Integer to NativeInt that caused that. -
New Warning in 12.2: Overloading a similar index type by declaring an array property 'Items'
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
Could you please give an example of what you did? -
New Warning in 12.2: Overloading a similar index type by declaring an array property 'Items'
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
Great. Swap a warning in 12.2 with an error in earlier versions. -
New Warning in 12.2: Overloading a similar index type by declaring an array property 'Items'
pyscripter replied to pyscripter's topic in RTL and Delphi Object Pascal
Will this not cause an issue with earlier DELPHI versions? -
Forgot to do that. How can I fix it now? Update: Deleted Parnassus entries from Registry and now it works. Very annoying.
-
You can set ReportMemoryLeaksOnShutdown to True to see whether there are leaks on the Delphi side. Loading and unloading the python dll multiple times is not a good idea. There is no guarantee that it will release all allocated memory when it unloads and it does not unload all other dlls loaded by python. It was designed to be loaded once in a single process. And there is no need to do that. Your program will be faster and leaner if you reuse the python dll.
-
The GetIt version is created by Embarcadero based on a p4d fork. Eventually the fixes will be added to the Embacadero fork, but then it may take some time for the GetIt installation to be updated. Using the pyscripter/python4delphi: Free components that wrap up Python into Delphi and Lazarus (FPC) (github.com) repo will probably get you the latest fixes much faster.
-
TComponent.Create() equivalent in Python script?
pyscripter replied to eivindbakkestuen's topic in Python4Delphi
You can create instances of classes in the "pythonic" way: myform = Form() TForm.Create() is not supported (TForm is exposed in python as Form). -
OnData is called from a thread. You need to change it to: procedure TForm2.OnData(Sender: TObject; const Data: string); begin TThread.Synchronize(nil, procedure begin Memo1.Lines.Add(Data); //No Memo1.Lines.Add('2'); //No end); end; Also set DelayWrites to False. DelayWrites only makes sense with TPythonGUIInputOutput. With the above two changes your code works as expected.
-
Can you post a zip file with your project?
-
Use the OnSendUniData event to process data sent by the python engine.
-
TPythonGUIInputOutput works with a linked memo. Use TPythonInputOutput instead.
-
Parsing a python collection into a delphi collection
pyscripter replied to Chris Mathews's topic in Python4Delphi
As you can see from your output AddressNumber is a string (as well as the other fields). You need to convert it to an integer. -
Parsing a python collection into a delphi collection
pyscripter replied to Chris Mathews's topic in Python4Delphi
I am not exactly sure what you are trying to do, Also the 4th line in your script is doing nothing since you are assigning a new value in the next statement. However, if you want to access these values in Delphi and store them say in a Delphi data structure, the easiest way is using VarPyth. For instance to access the AddressNumber, after running the above script, you use something like: var AddressNumber := MainModule.od[0]['AddressNumber']; -
You can always use the this python module from Delphi using P4D . One of the most advanced such Delphi functions in the Jcl unit JclSysUtils. Look at ExecuteCmdProcess and the various Execute overloads. It uses overlapped IO for super efficient redirection of the produced output, instead of using a special thread or a timer. These functions are also suitable for execution from a task/thread, if you do not want to block the main thread. The unit pyscripter/Source/uSysUtils.pas at master · pyscripter/pyscripter (github.com) extends the jcl functions to allow for an stdin pipe, customized environment variables and a buffered raw output.
-
Python freezes when running a certain script
pyscripter replied to djxandytche's topic in Python4Delphi
You don't need to create and destroy zPythonDelphiVar in every thread. Add zPythonDelphiVar to the form: object zPythonDelphiVar: TPythonDelphiVar Engine = PythonEngine1 Module = '__main__' VarName = 'result' Left = 64 Top = 120 end Then modify ExecuteWithPython to procedure TPythonThread_Test1.ExecuteWithPython; var i: Integer; begin fOutputs := TStringList.Create; for i := 1 to 10000 do begin GetPythonEngine.ExecString(UTF8Encode(Script)); GetPythonEngine.CheckError; fOutputs.Add(Form1.zPythonDelphiVar.Value); end; end; and it should work as you would expect. And since you mentioned it, a fellow Brazilian @lmbelo Lucas Belo, is a major contributor to P4D and would certainly be in a position to help. -
Python freezes when running a certain script
pyscripter replied to djxandytche's topic in Python4Delphi
You never explained what is the problem. -
Python freezes when running a certain script
pyscripter replied to djxandytche's topic in Python4Delphi
@djxandytche "Here is my code, please check and find the bugs" is not a good way to get support. Why should anyone spend one hour of their time, understanding and debugging your code? You say you are beginner in Python. Then why do you start by running python code in threads, which requires some expert knowledge? Do you realize that there is no performance benefits in running python code in threads like this? They will be executed sequentially, thanks to the GIL. -
How do I exchange data between python/Lazarus for a 3channel 2d floating-point array
pyscripter replied to RegiStax's topic in Python4Delphi
For Delphi is here: Fundamental Syntactic Elements (Delphi) - RAD Studio (embarcadero.com) and for fpc Identifier - Free Pascal wiki. -
How do I exchange data between python/Lazarus for a 3channel 2d floating-point array
pyscripter replied to RegiStax's topic in Python4Delphi
arr := np.&ones(VarPythonCreate([N, N]), np.float64) You do not need the &. It is only needed when using a keyword such as "array" (and Delphi does not need it even then). -
How do I exchange data between python/Lazarus for a 3channel 2d floating-point array
pyscripter replied to RegiStax's topic in Python4Delphi
Also, since you are interested in image manipulations, have a look at this thread: Place image in a TImage - Python4Delphi - Delphi-PRAXiS [en] (delphipraxis.net)