versuche gerade mit Python4Lazarus eine Python-Funktion aufzurufen.
Ich finde leider keine Beispiele.
Wer kann mir ein paar Tipps geben.
Python Code
Code: Alles auswählen
#-------------------------------------------------------------------------------
# Name: LazPythonFncDemo
# Purpose:
#
# Author: Acia6850
#
# Created: 23.02.2026
# Copyright: (c) Acia6850 2026
# Licence: <your licence>
#-------------------------------------------------------------------------------
val1 = 20
val2 = 5
def PyAdd(a,b):
c = a+b
return(c)
def PyStrFnc():
sVal = 'Hello Python from Lazarus'
print(sVal)
print(len(sVal))
print(sVal.count('l'))
def main():
print(PyAdd(val1,val2))
PyStrFnc()
if __name__ == '__main__':
main()
Code: Alles auswählen
program cLazPyFnc;
{$mode objfpc}{$H+}
uses
{$IFDEF LINUX}
cthreads,
{$ENDIF}
Sysutils, Classes, xdmpython;
Const
conPySriptPath = '..\..\Python\Scripts\';
procedure xRun;
Var
slOut : TStringList;
begin
DmPy := TDmPy.Create(nil);
try
WriteLn(DmPy.PyEng.RegVersion);
slOut := TStringList.Create;
try
slOut.Clear;
slOut.LoadFromFile(conPySriptPath + 'LazPythonFncDemo.py');
DmPy.PyEng.ExecStrings(slOut);
finally
slOut.Free;
end;
finally
DmPy.Free;
end;
end;
begin
xRun;
end.
Code: Alles auswählen
unit xdmpython;
{$mode Delphi}
interface
uses
Classes, SysUtils, PythonEngine;
type
{ TDmPy }
TDmPy = class(TDataModule)
PyEng : TPythonEngine;
private
public
end;
var
DmPy: TDmPy;
implementation
{$R *.lfm}
end.