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
 How exactly does TPDFAnnotation.StringValue work?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

BBriefs

Germany
3 Posts

Posted - Oct 14 2024 :  09:55:36  Show Profile  Reply
Hello,
I recently installed the newest update and I am currently experimenting with the PDF-Annotation functionality.
When I found the attribute TPDFAnnotation.StringValue I thought that maybe it could be used like a Dictionary to establish an internal annotation structure with specified keys and values, but there is something that I don't understand.

Everything worked as expected until I tried something generic like this:


procedure TForm1.Button1Click(Sender: TObject);
Var I : Integer;
begin
//ImageEnView1.PdfViewer.Annotations[0] being an existing text-annotation without assigned StringValues
For I := 0 to 3
  Do ImageEnView1.PdfViewer.Annotations[0].StringValue['XYZ' + I.ToString] := 'Test';

I := 0;

While not (ImageEnView1.PdfViewer.Annotations[0].StringValue['XYZ' + I.ToString] = '')
  Do Begin
     ShowMessage(ImageEnView1.PdfViewer.Annotations[0].StringValue['XYZ' + I.ToString]);

     Inc(I);
     End;
end;


I expected this loop to break at I = 4, instead however it turns out to be an endless loop in which ShowMessage always throws out 'Test'.

Obviously the function behind StringValue is an API-call and the comments declare it to be experimental, but I would simply like to understand it to avoid using it in an erroneous fashion.
Am I doing something wrong in this example or would it be better to avoid using StringValue in this fashion or even alltogether?

xequte

38608 Posts

Posted - Oct 14 2024 :  17:43:01  Show Profile  Reply
Hi

Unfortunately the PDFium API functions are just not well documented, but you appear to be using it as I would expect it to work, so I'm not sure why it is failing (other than it being experimental).

I will test this when I am back in the office.

Documentation

Get the string value corresponding to |key| in |annot|'s dictionary. |buffer|
is only modified if |buflen| is longer than the length of contents. Note that
if |key| does not exist in the dictionary or if |key|'s corresponding value
in the dictionary is not a string (i.e. the value is not of type
FPDF_OBJECT_STRING or FPDF_OBJECT_NAME), then an empty string would be copied
to |buffer| and the return value would be 2. On other errors, nothing would
be added to |buffer| and the return value would be 0.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

BBriefs

Germany
3 Posts

Posted - Oct 15 2024 :  02:50:40  Show Profile  Reply
I continued to experiment around a bit and found out how to make it work and what went wrong:


procedure TForm1.Button1Click(Sender: TObject);
Var I     : Integer;
    AText : String;
begin
//ImageEnView1.PdfViewer.Annotations[0] being an existing text-annotation without assigned StringValues
For I := 0 to 3
  Do ImageEnView1.PdfViewer.Annotations[0].StringValue['XYZ' + I.ToString] := 'Test';

I     := 0;
AText := ImageEnView1.PdfViewer.Annotations[0].StringValue['XYZ' + I.ToString]; 

While not (AText.IsEmpty)
  Do Begin
     ShowMessage(AText);

     Inc(I);
     AText := '';//Loop only works with this. Comment out for endless loop
     AText := ImageEnView1.PdfViewer.Annotations[0].StringValue['XYZ' + I.ToString]; 
     End;
end;


This code works as expected.
The decisive part turns out to be manually emptying the iterator "AText", since assigning a non-existing StringValue apparently doesn't do that.
Go to Top of Page

xequte

38608 Posts

Posted - Oct 16 2024 :  19:44:48  Show Profile  Reply


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38608 Posts

Posted - Nov 05 2024 :  01:05:57  Show Profile  Reply
Hi

This is fixed in the latest beta. You can email me for it.

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