Page 1 of 1

Unsuccessful use of CHPX Property!

Posted: Fri Dec 25, 2020 1:27 pm
by nalanfeng
Hi,

When I run the example that comes with TDOCXReadWriteVCL, I want to insert a formatted string into the doc document, but it fails. The code is as follows:

procedure TfrmMain.Button7Click(Sender: TObject);
var
Para: TAXWLogPara;
CHPX: TAXWCHPX;
begin
// MasterCHP contains the default characher properies.
// The CHPX is a list of exeptions of the CHP.
CHPX := TAXWCHPX.Create(DOCX.Editor.MasterCHP);
try
Para := DOCX.Editor.Paras.AppendPara;

CHPX.Size := 24;
CHPX.Bold := True;
CHPX.TColor := clRed;
CHPX.FillTColor := clBlack;
CHPX.FontName := 'Times New Roman';
Para.AppendPlainText(CHPX,'Lorem ipsum dolor sit amet.');
finally
CHPX.Free;
end;
end;

However,The string ‘Lorem ipsum dolor sit amet.’ is not formatted. Maybe I'm doing something wrong or else it would realy be great if this can be fixed soon.

Thanks for your help.

Re: Unsuccessful use of CHPX Property!

Posted: Fri Dec 25, 2020 9:19 pm
by larsa
Hello

The doc i formatted correct when I test the code.

How do you see that the doc is not formatted? Do you save it to a file?

Re: Unsuccessful use of CHPX Property!

Posted: Sat Dec 26, 2020 6:32 am
by nalanfeng
hello.
thank you for answer.I save str to abc.docs. my using office version is 2016. Maybe it has something to do with this?

Re: Unsuccessful use of CHPX Property!

Posted: Sun Dec 27, 2020 5:31 pm
by larsa
Hello

Please try this code:

Code: Select all

var
  DOCX: TDOCXReadWrite;
  Para: TAXWLogPara;
  CHPX: TAXWCHPX;
begin
  DOCX := TDOCXReadWrite.Create(Nil);
  try
    Para := DOCX.Editor.Paras.AppendPara;
    Para.AppendPlainText(DOCX.ComponentVersion);

    CHPX := TAXWCHPX.Create(DOCX.Editor.MasterCHP);
    try
      Para := DOCX.Editor.Paras.AppendPara;

      CHPX.Size := 24;
      CHPX.Bold := True;
      CHPX.TColor := clRed;
      CHPX.FillTColor := clBlack;
      CHPX.FontName := 'Times New Roman';
      Para.AppendPlainText(CHPX,'Lorem ipsum dolor sit amet.');
    finally
      CHPX.Free;
    end;

    DOCX.SaveToFile('Test.docx');
  finally
    DOCX.Free;
  end;

Re: Unsuccessful use of CHPX Property!

Posted: Mon Dec 28, 2020 2:59 am
by nalanfeng
Hello

Thank you very much

I tried this code, but still no success.But this code inspired me, so I browsed the “axolot.com”, in the "Version history" TOPIC, I saw this message:

---------------
2.00.01
! Wrong character properties when inserting text.
---------------

After running this code, I got the version of the component I used:

---------------
1.01.36
Lorem ipsum dolor sit amet.
---------------

I am guessing whether my component version is too low, causing this problem.

Re: Unsuccessful use of CHPX Property!

Posted: Mon Dec 28, 2020 2:30 pm
by larsa
Hello

Where did you download the component?

Re: Unsuccessful use of CHPX Property!

Posted: Tue Dec 29, 2020 2:55 am
by nalanfeng
Hello
I got it in a group related to Delphi, but it is an unregistered version, I just tried it.I downloaded the latest trial version from axolot.com. and now, this problem has been solved. It seems that this is indeed caused by the lower version.