WPCubed Product Support

Clearing removed (no longer used) objects from the document

Hi

I'm getting really big template binaries due orphaned objects that were manually deleted from the document and I'm wondering how can I find them and if possible how can I delete them completely from my template in order to shrink it, being careful to not delete actual/still used data.

My biggest template example that I have here is 11 mb size and has 2200 Document.RtfData.Count, but I assume there are bigger templates in some of my biggest customers.

When I call TWPRichText.Clear I'm able to erase everything, but I also lose the data that I want to keep (the visible data).

Any help would be highly appreciated.

#1 ♥ 0
6k Views 2 users 1 ♥ read 2 min
wpsupport

Thats difficult to say - this depends a lot on how those elements were created. Are this header and footers?

Using RTFData.Kind you can check what they are.

#2 ♥ 0

Hi

Thanks for the answer... I think I figure this out: I'm deleting all invisible RTFDataBlocks using this pseudo-code:

var
  I,
  itemsToDelete: TList<TWPRTFDataBlock>;
  WPRTFDataBlock: TWPRTFDataBlock;

begin
  for I := 0 to Document.RTFData.count - 1 do
    begin
      WPRTFDataBlock := wptDocument.RTFData[I];
      if not WPRTFDataBlock.IsVisible then
      begin
        WPRTFDataBlock.Clear(True);
        itemsToDelete.Add(WPRTFDataBlock);
      end;
    end;

  for WPRTFDataBlock in itemsToDelete do
    wptDocument.RTfData.DeleteRTFData(WPRTFDataBlock);
end;

The downsides:

1 - The Document needs to be loaded in desgin time;

2 - The Document needs to be focused (Document.SetFocus())

I had more than 2k useless objects loaded in the TWPRichText component!!

#3 ✎ ♥ 0
wpsupport

Thanks, this looks like good code.

I think if you do the loop backwards:

for I := Document.RTFData.count - 1 downto 0 do

you can delete the blocks also right away.

#4 ♥ 1
This category is archived. No new posts are possible.