Page 1 of 1

How to truncate description in Print Report

Posted: 2012-09-23 09:59:53
by alecaf
Hi all,
I am a new use of AMC and not so expert with scripting so I hope someone will help with my problem.

I am creating a new print report (2-pass report) and since the field [Description] can contain a big text I want to truncate it just to show a preview of the trama...

In the memo field I checked the Script box and in the activated window I put:

Code: Select all

begin
des := [Description];
sht_des := copy([des],1,200)+'...';
end;
Finally in the memo box I put simply [sht_des]

Now, this code runs without errors but for each movie the report shows me just the description of the first movie selected (or the first movie of my db).
Some one can help me to work this issue out?

[/code]

Posted: 2012-09-23 11:00:19
by antp
I do not know why it does not work, maybe Soulsnake will have an idea
There are many bugs in that report component.

Posted: 2012-09-23 13:20:54
by soulsnake
Hi,

I will see why this doesn't work when I will have a little time ;).
Can you try with a single pass ?
I think you can truncate automatically the description if you don't set autosize on your description rectangle (right click on rectangle).

Soulsnake.

Posted: 2012-09-24 05:47:01
by alecaf
Hi soulsnake,
Yes, I previously set the field without autosize, and actually it truncated the desctiption...But I am trying understand a way to fix the number of chars and add a '...' string at the end.
It's also a way to understand scripting on AMC...

thank you for the fast reply

Posted: 2012-09-24 13:00:18
by soulsnake
What you do should work but it doesn't.
The function 'copy' seems to not recognize variables.
I will see to solve this problem.

But for now you can do the same in other manner since AMC 4.X.
You can create a custom field of type Text ('ShortDesc' for example) and run a little script to fill it from original description.

Here is a little script to put the 200 first characters of original description (fieldDescription) into the custom field 'ShortDesc':

Code: Select all

program PutShortDescriptionInCF;
var
  value: string;
begin
  value := GetField(fieldDescription);
  if Length(value) > 200 then
    value := copy(value, 1, 200) + '...';
  SetCustomField('ShortDesc', value);
end.
When custom field 'ShortDesc' is filled, you can use it everywhere in the program: for printing, for html display, for export (csv, html, ...), for scripting, ...

Soulsnake.

Posted: 2012-11-26 08:33:35
by fulvio53s03
soulsnake wrote:...You can create a custom field of type Text ('ShortDesc' for example) and run a little script to fill it from original description.
.......
Brilliant, Imaginative!
This can also solve the problem about splitting a data-base field into 2 report fields, isn't it?
:p ;)
viewtopic.php?t=4812

Posted: 2012-11-26 09:02:52
by soulsnake
Hi,

Just for information, in last version 4.1.2 beta, you can do the same directly in reports in scripting part.
You can see an example in this template 'KLUZO (FR) landscape 4.frf' in last version 4.1.2 beta.

Soulsnake.

Posted: 2012-11-26 14:40:48
by fulvio53s03
:clapping:
.... later.....
which is the field splitted, please?
to see "splitting script" is it sufficient to check 'SCRIPT' on selected field?
:??:

Posted: 2015-05-20 15:52:24
by Bunnie
Alecaf's script doesn't work because of the used [ ] in the copy-statement

Posted: 2015-05-21 09:36:45
by antp
:??: that's the syntax of FreeReport's variables

Posted: 2015-05-21 09:46:53
by Bunnie
being new with these scripts I found out that statements like

field1 := [field1] + blabla

results in an error when [field1] was used in the textbox of a report

changing it to

field1 := field1 + blabla

solved the error plus the statement worked

Posted: 2015-05-21 11:39:53
by antp
For user-declared variables, indeed the [ ] are probably too much, these are for pre-defined variables if I remember well.
By the way, your e-mail account is sending replies automatically (acknowledges), so when the forum sends you a notification e-mail of a new message on a thread I get several automatic e-mails from you...

Posted: 2015-05-21 11:47:19
by Bunnie
I'm still tuning. It should have stopped already.