Jump to content

FranzB

Members
  • Content Count

    49
  • Joined

  • Last visited

Everything posted by FranzB

  1. FranzB

    Utility to import/convert simple Python code

    Delphi Community edition is free, just download latest DELPHI 🙂 https://www.embarcadero.com/products/delphi/starter/free-download?aldSet=en-GB
  2. which unit contains the TArray class , I*m using Delphi 10.4 not working units : System.Generics.Collections.TArray, System.TArray,
  3. thanks, the issue is now solved ... did too much coding in JAVA as well 🙂
  4. I want to compile this test code below for regular expressions, but none uses option works for me ... error [dcc32 Fatal Error] ..... .pas(10): F2613 Unit 'System.Generics.Collections.TArray' not found. uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types, FMX.StdCtrls, FMX.ScrollBox, FMX.Memo, FMX.Controls.Presentation, FMX.Edit, // System.Generics.Collections.TArray, // System.TArray, System.RegularExpressions;; ..... procedure TForm2.Button_evalregexpressionsClick(Sender: TObject); var regex: string; analysistxt: string; list: TArray<string>; item: String; begin regex := Edit_regexp.Text; analysistxt := Edit_analysisText.Text; list := TRegEx.Split(analysistxt, regex); for item in list do begin ShowMessage(item); end; end; end.
  5. I need to extract a word from a text file, the word is defined like MyWord ( ......... . ); MyWord( .....) MyWord ; MyWord; Can I extract MyWord with one regex expression or do I need 2 spilt lines of code and compare ? list := TRegEx.Split(Input_Text, '(' );
  6. MyWord is the string i want to extract, in the brackets come a list of numbers or strings LongList ( 1,2,3,4,5) Towns ( Paris, London, NY, Berlin) later I also need to extract the text between the brackets and need to port this code to delphi txt = "Town (my) simple test"; reg = /((.*))/; Ausgabe = txt.match(reg);
  7. I use this code below to read an integer value from an database aObject.IntValue := Fieldbyname('IntegerField').AsInteger; my code is functional, if there is an integer value stored. Reading an " " empty field I get an exception failure. What is the best coding style to avoid this error in an application ?
  8. Delphin 10.4 does not compile this code , but to my understanding this is a correct set of parameters calling MessageDialog FMX version TDialogService.MessageDialog('You want to ........ ', TMsgDlgType.mtConfirmation, TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo, nil, procedure(const aResult: TModalResult) begin if (aResult = mrYes) then begin // Write code here for pressing button OK ...... Label_Statusbar.Text := ' -> done '; end else begin // Write code here for pressing button NO ...... Label_Statusbar.Text := ' -> canceled '; end; end ); end;
  9. FranzB

    FMX : TDialogService.MessageDialog wrong parameter ?

    still no luck, compiling this code .... TDialogService.MessageDialog('You want to ........ ', TMsgDlgType.mtConfirmation, mbYesNo, TMsgDlgBtn.mbNo, nil, procedure(const aResult: TModalResult) begin if (aResult = mrYes) then begin // Write code here for pressing button OK // ...... Label_Statusbar.Text := ' -> done '; end else begin // Write code here for pressing button NO // ...... Label_Statusbar.Text := ' -> canceled '; end; end );
  10. I changed from Delphi 10.3. to Delphi 10.4 and want to compile functional projects again. The first error msg goes now like that , how to fix ?? [DCC Fatal Error] ......t.pas(20): F2613 Unit 'FMX.graphics' not found.
  11. I found this post here : How popular is Pascal/Delphi in 2019 and did not know this : with a link . https://www.quora.com/How-popular-is-Pascal-Delphi-in-2019-and-how-big-are-its-capabilities-compared-to-other-languages Is this still true in 2021 ?
  12. FranzB

    InputQuery texts

    are you asking to modify the input dialog or are yos asking to get data from Delphi to Python or the opposite way ?
  13. there is a tool available on githut which supports the GetIt package manager for RAD Studio (Delphi) by calling the GetIt command-line. I need to install DosCommand component (available on GetIt) , but I found several DosCommand Classes on git, what link should I use to get correct DosCommand class ? AUTO GET IT
  14. how to get the FMXLInux package with an offline installation of Delphi found with autogetit this command , how to execute, getitcmd -ae -i="FmxLinux-1.48"
  15. I'm using delphi4python components with an app where I can define all config parameters by an ini file as given here : How to get the config data in windows is explained here : https://github.com/pyscripter/python4delphi/wiki/FindingPython found this on windows as show above 🙂 my problem, I found only working parameter set for RED HAT 7, but can't find the settings for ubuntu , any help - parameter set possible ?
  16. uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.StdCtrls, System.SyncObjs, FMX.Memo.Types, FMX.ListBox, System.IniFiles, PythonEngine, PythonVersions; var PyVersion: TPythonVersion; begin FPyVersions := GetRegisteredPythonVersions; for PyVersion in FPyVersions do cbb_Pyversions.Items.Add(PyVersion.DisplayName); if cbb_Pyversions.Items.Count > 0 then begin cbb_Pyversions.ItemIndex := 0; end; end; I failed to compile above code for LINUX OS, is there any workaround in the UNIX platform ?
  17. FranzB

    GetRegisteredPythonVersions for LINUX

    what is the correct path setting for using python4delphi with UBUNTU ? can I get a parameter recommendation
  18. based on demo code 34 I wrote this code with the following new features a) create Pythonengine and PythonInOut at run time b) config pythonengine from an INI file c) find/exchange config parameter for different python installations , UNIX systems here in this forum d) set path to python libs via this INI file, no need for recompile Issues with this code a) OS=WINDOWS : text output of python is not shown in the memo. Guess this is due to the fact that I create the PythonInOut at run time and the is no property defined ( memo, using FMX or VCL ???) b) OS=LINUX : text output of python is not shown in the memo but in the calling CMD Window of this app. Guess a fix of a) will also help here c) pls. share addition setting to python libs like numpy etc. , what settings worked on your computer , how to find our the correct parameter on my computer etc. ....... i added the complete project, pls. share your improvement ideas 🙂 the used config file for windows did not have any problem calling a few NumPy statements [PythonEngine] DLLName=python39.dll DLLPath= AutoFinalize=0 AutoLoad=0 AutoUnload=0 RedirectIO=0 UseLastKnownVersion=0 UseWindowsConsole=0 the used config file for LINUX, simple code runs well, but I failed to set the path to the NumPy lib on the target system [PythonEngine] DLLName=libpython3.6m.so DLLPath=/usr/lib/x86_64-linux-gnu/ AutoFinalize=0 AutoLoad=0 AutoUnload=0 RedirectIO=0 UseLastKnownVersion=0 Config_linux .ini Config_windows.ini P4Ddemo34Config.dpr demopython34config.fmx demopython34config.pas
  19. good news : changed the code according your help and also created new *.ini file -> text is written to output file now 🙂 bad news : its difficult to find the correct parameter settings on a client computer system - there are to many options where python might be installed ...... https://github.com/pyscripter/python4delphi/wiki/FindingPython action : improve finding and setting of correct parameters ..... otherwise an app won't run on a different computer procedure TPythonEngineConfig.SetPythonengineValues(PythonEngine : TPythonEngine); var FPyVersions: TPythonVersions; begin /// /// convert this https://github.com/pyscripter/python4delphi/wiki/FindingPython /// into a small automatic setting of parameter /// PythonEngine.UseLastKnownVersion := Self.UseLastKnownVersion; if Self.UseLastKnownVersion then begin {$IFDEF MSWINDOWS} FPyVersions := GetRegisteredPythonVersions; FPyVersions[0].AssignTo(PythonEngine); {$ENDIF} {$IFDEF LINUX} /// see https://en.delphipraxis.net/topic/4700-getregisteredpythonversions-for-linux/ {$ENDIF} end else begin PythonEngine.DllName := Self.DllName; PythonEngine.DllPath := Self.DllPath; PythonEngine.AutoFinalize := Self.AutoFinalize; PythonEngine.AutoLoad := Self.AutoLoad; PythonEngine.AutoUnload := Self.AutoUnload; PythonEngine.RedirectIO := Self.RedirectIO; PythonEngine.UseWindowsConsole := Self.UseWindowsConsole; end; end; demo project : demopython34config.fmx demopython34config.pas P4Ddemo34Config.dpr screen dumps.
  20. yes, tried debugging function TForm_P4Deval.PythonInputOutputSendUniData(Sender: TObject); is never called , even I assigned this function during the create components function for data output. I'm using FMX framework and lastest Delphi 10.4.2 , full working code is attached below FPythonInOut.UnicodeIO := True; FPythonInOut.RawOutput := True; FPythonInOut.OnSendUniData := PythonInputOutputSendUniData; {$IFDEF MSWINDOWS} FPyVersions := GetRegisteredPythonVersions; FPyVersions[0].AssignTo(FPythonEngine); {$ENDIF} FPythonEngineConfig.SetPythonengineValues(FPythonEngine); FPythonEngine.Loaddll; FPythonEngine.IO := FPythonInOut; Config_windows.ini demopython34config.fmx demopython34config.pas P4Ddemo34Config.dpr
  21. I still need a helping hand on one failure of the demo34Extend sample : Q : why is python text output not written to the output memo in Delphi app, python engine for sure is running, see post above procedure TForm_P4Deval.btn_CreatePythonEnviromentClick(Sender: TObject); begin // run this function prior to execute python code FPythonEngine := TPythonEngine.Create(nil); FPythonInOut := TPythonInputOutput.Create(nil); try FPythonInOut.UnicodeIO := True; FPythonInOut.RawOutput := True; FPythonInOut.OnSendUniData := PythonInputOutputSendUniData; {$IFDEF MSWINDOWS} FPyVersions := GetRegisteredPythonVersions; FPyVersions[0].AssignTo(FPythonEngine); {$ENDIF} FPythonEngineConfig.SetPythonengineValues(FPythonEngine); FPythonEngine.Loaddll; FPythonEngine.IO := FPythonInOut; { TPythonModule } FPythonModule1 := TPythonModule.Create(Self); FPythonModule1.Name := 'PythonModule1'; FPythonModule1.Engine := FPythonEngine; FPythonModule1.ModuleName := 'spam'; with FPythonModule1.Errors.Add do begin Name := 'PointError'; ErrorType := etClass; end; with FPythonModule1.Errors.Add do begin Name := 'EBadPoint'; ErrorType := etClass; ParentClass.Name := 'PointError'; end; except on E: Exception do writeln(E.ClassName, ': ', E.Message); end; end; procedure TForm_P4Deval.btn_FreePythonEnviromentClick(Sender: TObject); begin FPythonEngine.Free; FPythonInOut.Free; end; Config_windows.ini demopython34config.fmx demopython34config.pas P4Ddemo34Config.dpr
  22. yes , here comes a numpy short demo on windows .... execution is perfect I installed numpy via pip , did not need to set a DLL path see screen dump (on LINUX i don't have admin rights to install software using pip, will report results later - need other LINUX computer ) # demo script import matplotlib.pyplot as plt import numpy as np x = np.arange(0,8*np.pi,0.1) # start,stop,step y = np.cos(x) *1/(1+x) plt.plot(x,y) plt.show()
  23. working also on this topic, and need to find out how get the correct settings on different UNIX system, I started from your code and did this code now :
  24. I have created the following simple application which should run on WINDOWS and LINUX using FMX framework and creating delphi4python components on run time . Why does this demo code not show any output result ? Most important line of code is this , or not ...? PythonInOut.OnSendUniData := PythonInputOutputSendUniData; I know this source https://blogs.embarcadero.com/learn-how-to-dynamically-create-and-destroy-python4delphi-components-with-a-delphi-windows-app/ but I intend to create a minimum code sequence type TForm1 = class(TForm) memoIn: TMemo; Splitter1: TSplitter; memoOut: TMemo; Panel1: TPanel; Button1: TButton; btnLoadScript: TButton; dlgOpen_pythonscript: TOpenDialog; btn_CreatePythonEnviroment: TButton; btn_FreePythonEnviroment: TButton; procedure Button1Click(Sender: TObject); procedure PythonInputOutputSendUniData(Sender: TObject; const Data: string); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure btnLoadScriptClick(Sender: TObject); procedure btn_CreatePythonEnviromentClick(Sender: TObject); procedure btn_FreePythonEnviromentClick(Sender: TObject); private { Private declarations } FOutputStream: TMemoryStream; FCriticalSection: TCriticalSection; public { Public declarations } PythonEngine: TPythonEngine; PythonInOut: TPythonInputOutput; end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.btnLoadScriptClick(Sender: TObject); begin if dlgOpen_pythonscript.Execute then begin memoIn.Lines.Clear; memoIn.Lines.LoadFromFile(dlgOpen_pythonscript.FileName) end; end; /// /// did not drop components on a form , create components at run time ... /// procedure TForm1.btn_CreatePythonEnviromentClick(Sender: TObject); begin PythonEngine := TPythonEngine.Create(nil); PythonInOut := TPythonInputOutput.Create(nil); try PythonEngine.AutoLoad := true; {$IFDEF LINUX} PythonEngine.DllName := 'libpython3.6m.so'; PythonEngine.DllPath := '/usr/lib/x86_64-linux-gnu/'; {$ENDIF} {$IFDEF MSWINDOWS} PythonEngine.DllName := 'python310.dll'; PythonEngine.DllPath := ''; {$ENDIF} PythonEngine.AutoFinalize := true; PythonEngine.AutoLoad := true; PythonEngine.AutoUnload := true; PythonEngine.RedirectIO := true; PythonEngine.UseLastKnownVersion := true; PythonEngine.Loaddll; PythonEngine.IO := PythonInOut; PythonInOut.RawOutput := True; PythonInOut.OnSendUniData := PythonInputOutputSendUniData; except on E: Exception do writeln(E.ClassName, ': ', E.Message); end; end; procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine.ExecString(UTF8Encode(memoIn.Text)); end; procedure TForm1.FormCreate(Sender: TObject); begin FOutputStream := TMemoryStream.Create; FCriticalSection := TCriticalSection.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin FOutputStream.Free; FCriticalSection.Free; end; procedure TForm1.PythonInputOutputSendUniData(Sender: TObject; const Data: string); { FMX TMemo is slow when adding many lines one by one. To avoid this we accumulate output and print it in one go. The critical section allows for multiple threads to print. If you use this code then set PythonInputOuput.RawOutput to True A simpler solution would be to set RawOuput to False and then do MemoOut.Lines.Add(Data); MemoOut.GoToTextEnd; This should be good enough if python does not produce a massive amount of output. } Var ScheduleWrite: Boolean; begin if Data = '' then Exit; FCriticalSection.Enter; try ScheduleWrite := FOutputStream.Size = 0; FOutputStream.Write(Data[1], Length(Data) * 2); if ScheduleWrite then TThread.ForceQueue(nil, procedure var WS: string; begin FCriticalSection.Enter; try if FOutputStream.Size > 0 then begin SetLength(WS, FOutputStream.Size div 2); FOutputStream.Position := 0; FOutputStream.Read(WS[1], Length(WS) * 2); FOutputStream.Size := 0; if (memoOut.Lines.Count > 0) and (memoOut.Lines[memoOut.Lines.Count - 1] <> '') then memoOut.Lines.Add(''); memoOut.Text := memoOut.Text + WS; memoOut.GoToTextEnd; end; finally FCriticalSection.Leave; end; end); finally FCriticalSection.Leave; end; end; end.
  25. FranzB

    create delphi4python at run time

    did a code rework and need to ask a different question
×