The AfterMap Event on the dataset has a special purpose - it allows you to skip the processing of child datasets. The fields in the current record will process but no lower level dataview records will be processed.

This Event fires once after each record is processed - after all of the fields of the current record are processed.

If LinkedData is set, then multiple records could be processed and this Event will fire once after each of those records. But if LinkedData is not set then this will only fire once.

The AfterMap event has one parameter called Value. This parameter defaults to the parameter value from the corresponding record-level BeforeMap Event process - where the BeforeMap parameter Value was set to False, then AfterMap is called and its Value parameter will also automatically be set to False.

The value of this parameter at the end of the AfterMap Event determines whether child datasets will be processed or not. Set the parameter to False to skip processing of any child datasets. If there are multiple child datasets this will skip the processing of all of them.

If you want finer control, you should instead use the BeforeMap Events of the child datasets - set the ones you don't want to process to False and leave the others.

Setting The AfterMap Event

Within the script you can perform some checks as to whether you want to process the child datasets and set the parameter Value appropriately.

If you do not specify a script for the AfterMap Event then it defaults to the Value from the BeforeMap Event and the child datasets may or may not be processed. False means they will not be processed.

By clicking anywhere within the script window, the following skeleton script code is generated, including a useful reminder about the parameter value and the relationship between BeforeMap and AfterMap.

procedure AfterMapEvent(var Value:Variant); //ORDER_HEADER
begin
// The AfterMap event will fire even for records that are skipped by setting Value:=False
// in the BeforeMap. To run AfterMap code only for records that were not skipped wrap your
// code with the following commented check
// if Value then
// Begin
 
// End;
 
Value :=
end;

The following example sets the AfterMap Event to False.

procedure AfterMapEvent(var Value:Variant); //ORDER_HEADER
begin
Value := False;
end:

Remember that by the time the AfterMap Event is called, a record has been created in the destination dataset and typically values will have been set for individual fields via the field-level OnMap Events.

To remove this current and about-to-be-saved record, use the Delete(0) method on the dataset. Please refer to Dataset Class (TDataset) . If the dataset has one or more child datasets, then also set the Value parameter to False as described above.

And just like BeforeMap, a successful AfterMap Event will display in the Map as green. A failed AfterMap Event will display in the Map as red.