Unsuccessful use of CHPX Property!

Questions and answers on how to use DOCXReadWrite
Post Reply
nalanfeng
Posts: 16
Joined: Fri Dec 25, 2020 12:49 pm

Unsuccessful use of CHPX Property!

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unsuccessful use of CHPX Property!

Post 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?
Lars Arvidsson, Axolot Data
nalanfeng
Posts: 16
Joined: Fri Dec 25, 2020 12:49 pm

Re: Unsuccessful use of CHPX Property!

Post 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?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unsuccessful use of CHPX Property!

Post 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;
Lars Arvidsson, Axolot Data
nalanfeng
Posts: 16
Joined: Fri Dec 25, 2020 12:49 pm

Re: Unsuccessful use of CHPX Property!

Post 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.
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Unsuccessful use of CHPX Property!

Post by larsa »

Hello

Where did you download the component?
Lars Arvidsson, Axolot Data
nalanfeng
Posts: 16
Joined: Fri Dec 25, 2020 12:49 pm

Re: Unsuccessful use of CHPX Property!

Post 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.
Post Reply