QAID # 15220 Published
Question / Problem:
Why might an Advanced Zone Locator report an "Invalid argument specified" or "Out of Memory" error when adequate system resources are still available?
Answer / Solution:
An Advanced Zone Locator might return an error like the following when it tries to extract information from a zone that extends beyond the bounds of the page:
BeforeExtraction: BeforeExtract: The execution of a locator method failed. Class = "Cover",
Locator = "AZL_Requestor", Original error message: Out of memory
This can also be a problem if the zones of the AZL are being relocated in a script and care is not taken to ensure that they are not moved off of the page.
In KTM 5.5, off-page zones are handled without error, but in previous versions, a script can be used to prevent the error by invalidating zones which go off of the page.
The following script function should be called from a Script Locator positioned before the AZL and after any script which is relocating AZL zones:
'Prevent AZL Zones which might go off a page from causing an error 'Call this after any script that moves AZL zones and before the actual AZL 'This can also cause the AZL to have alternatives with zeroed coordinates on PageNr - 1 'The only implication is that script using these values directly 'should check if the page number is valid Public Sub FixAZLCoordinates(ByVal pXdoc As CscXDocument) Dim Rep As CscXDocRepresentation Set Rep = pXdoc.Representations(0) Dim iZone As Integer Dim oZone As CscXDocZone Dim iPage As Integer Dim NewZones() ReDim NewZones(0) 'go through zones (backwards so removing items is fine) For iZone = Rep.Zones.Count - 1 To 0 Step -1 Set oZone = Rep.Zones(iZone) 'go through pages For iPage = 0 To pXdoc.Pages.Count - 1 Dim ZoneIsOnThisPage As Boolean If oZone.PageNr = iPage Then ZoneIsOnThisPage = True Else ZoneIsOnThisPage = False End If If ZoneIsOnThisPage Then Dim ZoneOffPageTooFarRight As Boolean ZoneOffPageTooFarRight = (oZone.Left + oZone.Width) > pXdoc.Pages.ItemByIndex(iPage).Width Dim ZoneOffPageTooLow As Boolean ZoneOffPageTooLow = (oZone.Top + oZone.Height) > pXdoc.Pages.ItemByIndex(iPage).Height If ZoneOffPageTooFarRight Or ZoneOffPageTooLow Then 'Remove the zone (will not cause index problems because 'we are stepping through backwards) 'Trace "Removing Zone: " & oZone.Name & ", TooRight/TooLow: " & _ 'ZoneOffPageTooFarRight & "/" & ZoneOffPageTooLow Rep.Zones.Remove(iZone) 'Create new zone Dim oZoneNew As CscXDocZone Set oZoneNew = New CscXDocZone oZoneNew.Name = oZone.Name oZoneNew.PageNr = oZone.PageNr oZoneNew.Left = 0 oZoneNew.Width = 0 oZoneNew.Top = 0 oZoneNew.Height = 0 'Add zone to array (we don't want to append it while we are ' still iterating though the zones) ReDim Preserve NewZones(UBound(NewZones) + 1) Set NewZones(UBound(NewZones)) = oZoneNew End If End If Next Next Dim i As Integer Dim ZoneToAppend As CscXDocZone For i = 0 To UBound(NewZones) If Not IsEmpty(NewZones(i)) Then Set ZoneToAppend=NewZones(i) 'Trace "Appending new zone: " & ZoneToAppend.Name Rep.Zones.Append ZoneToAppend End If Next End Sub