ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ImageEnVect sometimes doesn't save objects
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

jonneve

France
6 Posts

Posted - Apr 08 2016 :  08:43:58  Show Profile  Reply
Hi all,

I've got an ImageEnVect that I'm using to load photos which the end user can edit or add vector-based arrows to. I then save the edited photos to a database, in vector format so that the end user can move/delete the arrows later if necessary. Most of the time, it works, but from time to time, it ignores the changes made and doesn't save them correctly to the database, but I can't figure out why. Here's my code:


procedure TfmPhotoRetouche.SavePhoto;
var
  str: TStream;
begin
  if lImageChanged then
  begin
    qPoints.Edit;
    str := qPoints.CreateBlobStream(qPointsPHOTO_MODIFIEE, bmWrite);
    try
      qPoints.Edit;
      str.Seek(0, soFromBeginning);
      ImageEnVect.SaveToStreamAll(str);
    finally
      str.Free;
     end;
    qPoints.Post;
    lImageChanged := False;
  end;
end;

procedure TfmPhotoRetouche.qPointsBeforeScroll(DataSet: TDataSet);
begin
  SavePhoto;
end;

procedure TfmPhotoRetouche.qPointsAfterScroll(DataSet: TDataSet);
var
  str: TStream;
  f: TBlobField;
begin
  if qPointsPHOTO_MODIFIEE.IsNull then
    f := qPointsPHOTO_ORIGINALE
  else
    f := qPointsPHOTO_MODIFIEE;

  str := qPoints.CreateBlobStream(f, bmRead);
  try
    ImageEnVect.Clear;
    ImageEnVect.RemoveAllObjects;

    if f = qPointsPHOTO_ORIGINALE then
      ImageEnVect.IO.LoadFromStreamJpeg(str)
    else
      ImageEnVect.LoadFromStreamAll(str);
  finally
    str.Free;
   end;
  lImageChanged := false;
end;

procedure TfmPhotoRetouche.FormShow(Sender: TObject);
begin
  if fmMain.FormDocker.FormParameters[Self] <> nil then
    FDepart := fmMain.FormDocker.FormParameters[Self][0];

  lImageChanged := False;
  imageenvect.ObjEndShape[-1] := iesOUTARROW;
  imageenvect.ObjBrushColor[-1] := clRed;
  imageenvect.ObjBrushStyle[-1] := bsSolid;
  imageenvect.ObjPenWidth[-1] := 15;
  imageenvect.ObjPenColor[-1] := clRed;
  imageenvect.ObjAnchorToLayers := False;
  imageenvect.MouseInteractVt := [miObjectSelect];
  imageenvect.MouseInteract := [];
  ImageEnVect.SelectionAspectRatio := dmFich.tParamsPHOTOS_PROPORTIONS_RECADRAGE.Value;
  ImageEnVect.MouseWheelParams.Action := iemwZoom;
  ImageEnVect.MouseWheelParams.Variation := iemwPercentage;
  ImageEnVect.MouseWheelParams.value := 15;
  ImageEnVect.MouseWheelParams.InvertDirection := True;

  qPoints.Close;
  qPoints.ParamByName('depart').Value := FDepart;
  qPoints.Open;
end;

procedure TfmPhotoRetouche.ImageEnVectImageChange(Sender: TObject);
begin
  lImageChanged := True;
end;

procedure TfmPhotoRetouche.ImageEnVectNewObject(Sender: TObject; hobj: Integer);
begin
  qPoints.Edit;
  qPointsPHOTO_ETAT_RETOUCHE.Value := 2;
  btSelection.Click;
  lImageChanged := True;
end;

procedure TfmPhotoRetouche.ImageEnVectObjectMoveResize(Sender: TObject; hobj,
  Grip: Integer; var OffsetX, OffsetY: Integer);
begin
  qPoints.Edit;
  qPointsPHOTO_ETAT_RETOUCHE.Value := 2;
  lImageChanged := True;
end;



Is there anything obvious I'm doing wrong?

Thanks in advance,
Jonathan

xequte

39053 Posts

Posted - Apr 08 2016 :  20:46:42  Show Profile  Reply
Hi Jonathan

I don't know if it is the cause, but there are a number of issues in the code. In two events, you call Edit(), without calling Post() or Cancel(). And in your SavePhoto() event you call Edit() twice.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: