delphi 10.3 / TMS WEB Core 1.5.6.0
I'm storing an image inside a database as Base64 string. For testing purpose, I'm trying to store it in a file using a TElectronBinaryDataStream. I know, that I can assign the Base64 image string directly to the stream by
Var
stream : TElectronBinaryDataStream;
begin
stream:= TElectronBinaryDataStream.Create();
stream.Base64:= image_string_base64;
stream.SaveToFile(FileName);
end;
This is working, I get an image file.
I'm also trying to create a TGraphic object from the base64 image string and then storing it to a stream:
Var
g : TGraphic;
stream : TElectronBinaryDataStream;
begin
stream:= TElectronBinaryDataStream.Create();
g:= TGraphic.CreateFromURL(image_string_base64);
stream.Base64:= g.GetBase64Image;
stream.SaveToFile(FileName);
end;
Here I get an empty file. Which part is not working?
CreateFromURL is an asynchronous function. Calling it will not immediately yield a result on the next line. You might need to handle further processing from OnChange.
How to assign the event handler to the TGraphic.OnChange event? I saw in the form source code the method, but can't make it work.
Var
signature_base64 : string;
g : TGraphic;
begin
g:= TGraphic.Create;
SetEvent(g, self, 'OnChange', 'OnGraphicChanged');
g.LoadFromURL(signature_base64);
result:= g;
end;
procedure TForm1.OnGraphicChanged(Sender: TObject);
Var
g : TGraphic;
stream : TElectronBinaryDataStream;
begin
try
g:= Sender as TGraphic;
stream:= TElectronBinaryDataStream.Create;
stream.Base64:= g.GetBase64Image;
stream.SaveToFile('Image.png');
finally
g.free;
stream.free;
end;
end;
I tested a version using a TWebImageControl.OnLoaded event for storing the image file, which is working as expected. Why is my code, using the TGraphic object not working?
You set it like any Delphi event handler, i.e.
class.OnChange := yourhandler
That's what I did first, but it didn't work. In the chrome debugger window I saw this form creation code which is assigning the eventhandler by SetEvent()
![ElectronFormCreation](https://support.tmssoftware.com/uploads/default/original/2X/4/424762a56e7dc753e2c07b59d72723fc9c7d1f48.png)
please define "didn't work"
The assigned event handler procedure wasn't executed