App freezes when uploading pictures to server

  

I made an app only to take photos and send these to the server. in those photos, I edit the date in the right bottom corner. If a user takes more than 9 photos the app freezes in the process and asks if you want to close the app. You can choose between close app or wait. Click on wait and the process works all the photos saved to the server. But it’s annoying and not professional to get this message. Below is the code and maybe some of you can spot the mistake I made.
I use the Tcameracomponent for making photos.
A TMSFMXtableview(TV1) to show the photos in the app.
And I use the Timage for linking to the Tcameracomponent.
This is the code for the save button onclick.
procedure TFMmain.Button10Click(Sender: TObject);
VAR
B: TBitmap;
R : TRectf;
LMemStream: TMemoryStream;
i2,I,AN, NewWidth, NewHeight : Integer;
lExtensie : string;
Scale : double;
Fid : Integer;
begin
Cameracomponent1.Active := false;
button11.Visible := false;
button10.Visible := true;

if TV1.Items.Count>0 then
begin
for I := 0 to tv1.Items.Count-1 do
begin
B:= TV1.Items.Items[i].Bitmap;
R.Create(B.Width – 250, B.Height – 100, B.Width, B.Height);
B.Canvas.BeginScene;
try
B.Canvas.Font.Size := 40;
b.Canvas.Fill.Color := TAlphaColorRec.red;
B.Canvas.FillText(
R, DateToStr(Now), False, 100, [TFillTextFlag.RightToLeft],
TTextAlign.Center);
finally
B.Canvas.EndScene;
end;
LMemStream := TMemoryStream.Create;
try
TV1.Items.Items[i].Bitmap.SaveToStream(LMemStream);
storedprocFotoUp.Params[0].AsStream :=LMemStream;
LMemStream.Position := 0;
storedprocFotoUp.ExecProc;
finally
Lmemstream.Free;
end;
end;
tv1.Items.Clear;
button11.Visible := true;
button10.Visible := true;
Cameracomponent1.Active := true;
end
else
begin
button11.Visible := true;
button10.Visible := true;
Cameracomponent1.Active := true;
end;
end;
end;

The storedprocfotoup is a procedure on the server side.
Procedure TServermodule.SavePhotoToServer(Stream: TStream);
const
BufSize = $8000;
var
Today : TDateTime;
Mem: TMemoryStream;
BytesRead, Vnr,Fnr: Integer;
Buffer: PByte;
fFilename, lExtensie, DT, Time: String;
begin
Today := NOW;
Flocation:= ‘C:\test\’;
lExtensie := ‘.jpg’;
Time:= IntToStr(Yearof(Today))+IntToStr(Monthof(Today))+IntToStr(Dayof(Today))+IntToStr(Hourof(Today))+ IntToStr(Minuteof(today))+ IntToStr(MilliSecondof(today));
fFilename := ‘F’+Tijd+lExtensie;

// save file to server

Mem := TMemoryStream.Create;
Mem.Position :=0;
GetMem(Buffer, BufSize);
try
repeat
BytesRead := Stream.Read(Pointer(Buffer)^, BufSize);
if BytesRead > 0 then
Mem.WriteBuffer(Pointer(Buffer)^, BytesRead);
until BytesRead < BufSize;
Mem.SaveToFile(Flocation+fFilename);

finally
FreeMem(Buffer, BufSize);
Mem.Free;
end;
end;

I hope I provided enough information.

Comments are closed.