Alexey-T / Python-for-Lazarus

Fork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
MIT License
127 stars 42 forks source link

New Demo added (02,03) #19

Closed mamin27 closed 4 years ago

mamin27 commented 4 years ago

I was added two Demo's. Demo02 was correctly tested. Demo03 is not currently worked correctly. Next are mentioned potential code part responsible for issue. Demo was tested at linux with python3.7. Input data for Memo1 was "test.Value = 10". Are you able to help where is the issue in Demo03?

PythonEngine.pas line: 5245

PyRun_String python api function does not work correct


function TPythonEngine.Run_CommandAsObjectWithDict(const command : AnsiString; mode : Integer; locals, globals : PPyObject) : PPyObject;
var
  m : PPyObject;
  _locals, _globals : PPyObject;
begin
  CheckPython;
  Result := nil;
  Traceback.Clear;
  CheckError(False);

  m := GetMainModule;
  if m = nil then
    raise EPythonError.Create('Run_CommandAsObject: can''t create __main__');

  if Assigned(locals) then
    _locals  := locals
  else if Assigned(FLocalVars) then
    _locals  := LocalVars
  else
    _locals  := PyModule_GetDict(m);

  if Assigned(globals) then
    _globals := globals
  else if Assigned(FGlobalVars) then
    _globals := GlobalVars
  else
    _globals := PyModule_GetDict(m);

  try
    Result := PyRun_String(PAnsiChar(CleanString(command)), mode, _globals, _locals);
    if Result = nil then
      CheckError(False);
    Py_FlushLine;
  except
    Py_FlushLine;
    if PyErr_Occurred <> nil then
      CheckError(False)
    else
      raise;
  end;
end;
Alexey-T commented 4 years ago

https://github.com/pyscripter/python4delphi Pls post this PR to that repo, later if author will accept it, i can take his changes, he may change something in your PR

Alexey-T commented 4 years ago

"Change demo_lazarus to unix version" has no useful changes, demo don't need it. other commits- pls post to Lazarus4Delphi repo, I don't support Py4D demos.

mamin27 commented 4 years ago

ok

mamin27 commented 4 years ago

Did you update your Lazarus version with Py4D? Because Demo works only with your clone.

Alexey-T commented 4 years ago

I updated it n months ago from Py4D.

mamin27 commented 4 years ago

I recommend you to update Py4D in near future because in actual version of Py4D was a lot of minor and major issues during compilation. Your attention is very helpful for Py4D project. (Lazarus part). Thanks for all your work.