Skip to content

Commit cce7fb3

Browse files
committed
Fix Demo29
1 parent 014e301 commit cce7fb3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Demos/Demo29/Unit1.pas

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ interface
1010

1111
uses
1212
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
13-
Dialogs, ExtDlgs, StdCtrls, ExtCtrls, PythonEngine, Vcl.PythonGUIInputOutput;
13+
Dialogs, ExtDlgs, StdCtrls, ExtCtrls, PythonEngine,
14+
PythonGUIInputOutput;
1415

1516
type
1617
TForm1 = class(TForm)
@@ -88,26 +89,26 @@ procedure TForm1.Button2Click(Sender: TObject);
8889
presult := PyEval_CallObjectWithKeywords(
8990
ExtractPythonObjectFrom(MainModule.ImageToBytes), pargs, nil);
9091
try
91-
if (P = nil) or (PyBytes_AsStringAndSize(presult, P, Len) < 0) then begin
92+
if PyBytes_AsStringAndSize(presult, P, Len) < 0 then begin
9293
ShowMessage('This does not work and needs fixing');
9394
Abort;
9495
end;
96+
97+
_stream := TMemoryStream.Create();
98+
try
99+
_stream.Write(P^, Len);
100+
_stream.Position := 0;
101+
Image1.Picture.Graphic.LoadFromStream(_stream);
102+
finally
103+
_stream.Free;
104+
end;
95105
finally
96106
Py_XDECREF(pResult);
97107
end;
98108
finally
99109
Py_DECREF(pargs);
100110
end;
101111
end;
102-
103-
_stream := TMemoryStream.Create();
104-
try
105-
_stream.Write(P^, Len);
106-
_stream.Position := 0;
107-
Image1.Picture.Graphic.LoadFromStream(_stream);
108-
finally
109-
_stream.Free;
110-
end;
111112
end
112113
else
113114
begin

0 commit comments

Comments
 (0)