WPCubed Product Support

Date field does not use date format

The date field does not use the date mask that can be specified through the Source property. I am using WPTools VCL Demo 5.18.1 for Delphi 5.

// insert date (reversed)
WPRichText.InputString( 'Date: ');
Field := WPRichText.InputTextFieldName( 'DATE');
Field.Source := '\@ dd-mm-yyyy';
// insert time (reversed)
WPRichText.InputString( 'Time: ');
Field := WPRichText.InputTextFieldName( 'TIME');
Field.Source := '\@ ss:mm:hh';
#1 ♥ 0
7.1k Views 4 users read 3 min
support

Hi,

no, it does not use any mask. If you need that you can create a formatted string using OnTextObjectGetTextEx

Julian

#2 ♥ 0

@wpsupport:
no, it does not use any mask. If you need that you can create a formatted string using OnTextObjectGetTextEx

It's a bug. See function TWPRTFEnginePaint.MeasureObject in unit WPRTEPaint where the date field is processed. The line s:= wcomands.GetValue('@') is missing. That is the reason why the mask only worked for a time field and not a date field.

#3 ♥ 0
support

Tim,

Good you found it - Still, in this version I do will not implement support for the format strings Word uses (incl. dialog box etc) - this is what I meant.

Julian

#4 ♥ 0
WPRichText.InputString( 'Date: ');
Field := WPRichText.InputTextFieldName( 'DATE');
Field.Source := '\@ dd-mm-yyyy';

Puting s:= wcomands.GetValue('@') where fedpol told, How to format the date to show "15 of May - 2006"?

#5 ♥ 0

Hi,

You could use:

InputTextFieldName ('TIME \\@ "d'' de ''MMMM'' de ''yyyy"');

and in OnTextObjGetTextEx event, handle it whit this pieces of code:

if (copy (TXTObject.Name, 1, 10) = 'TIME \\@ "') then
    sFormato := copy (TXTObject.Name, 11, length (TXTObject.Name) - 10);
 
  ...
 
  if sFormato <> '' then
  begin
    DateTimeToString(sResult, sFormato, Now);
    printString := sResult;
  end
  else....

  TXTObject.Params := printString;

This is what I use, and it is compatible with MSWord datetime field signature, working perfectly. But I'm having a problem while transfering the contents from one TWPRichText to another using WPRichTextNEW.RTFText.AsString = WPRichTextORIGINAL.RTFText.AsString. It is loosing the double quotes, so if I copy from WPTools and Paste in MSWord, trying to "update field value" it shows an error: "Error! The character sequence has no coincident quotes" (or something like that)

I sent this issue to Julian and hope he could solve it.

Hope this helps

Alessandro Fragnani

#6 ♥ 0
support

Hi,

after re-reading your post I finally understand:

InputTextFieldName ('TIME \\@ "d'' de ''MMMM'' de ''yyyy"');

is not correct since you make the format part of the name! Here the RTF writer will enclose the name in quotes since they contain spaces.

Please use the 'Source' property fo the format string

Field := WPRichText1.InputTextFieldName( 'TIME');
Field.Source := '\\@ "d'' de ''MMMM'' de ''yyyy"';

I will add code to make the formatstrings work in thge default code which handles TIME and DATE fields.

Regards,

Julian

#7 ♥ 0

Hi Julian,

I tested with WPTools 5.20.5 but I have to change a bit your suggestion. Both to be compatible to MSWord date/time field definitions:

Adding a field (internally it doubles the backslash, so if I use '\\' it will save as '\\\\'):

oField := oDocumentoAtual.oWPRichText.InputTextFieldName('TIME');oField.Source := '\@ "d'' de ''MMMM'' de ''yyyy"';

Handling OnTextObjGetTextEx (treating for \\@):

if (TXTObject.Name = 'TIME') then
  ..
  if (copy (TXTObject.Source, 1, 5) = '\\@ "') then
  begin
      sFormato := copy (TXTObject.Source, 6, length (TXTObject.Source));
      sFormato := Copy(sFormato, 1, Length(sFormato) - 1);
  end

Thanks

Alessandro Fragnani

#8 ♥ 0
This category is archived. No new posts are possible.