Implements a list of TMethod entries.

lazmethodlist.pas implements a list used TMethod instances representing event handler routines in LCL components.

This file is part of the LazUtils package.

Implements a list of TMethod entries.

TMethodList is class which implements a list of TMethod entries. TMethodList is implemented using an array of TMethod references that provide access to the Items in the list. Methods are provided to Add, Insert, Delete, and Move items in the list. Enumerators (forward and reverse) are also available for methods in the list.

TMethodList is used in the Lazarus IDE, plugins, and utilities such as: TComponentEditorDesigner, TCodeToolManager, TLazIDEInterface, TLazCompilerOptions, TDebuggerIntf, TGUITestRunner. It is also used in the implementation of Classes and Components like: TFreeNotifyingObject, TApplication, TCustomForm, TControl, TDateTimePicker, TLazSynTextArea, TSynCustomHighlighter, TSynGutterBase, and many more.

TMethod
Implements an enumerator for TMethodList. Owner of the enumerator. Index position for the current item in the enumerator. Indicates if items are enumerated in reverse order. Gets the current item in the enumerator. Current item for the enumerator. Initializes the enumerator. Owner of the enumerator. Indicates items are enumerated in reverse order. Gets the next item for the enumerator. Next item for the enumerator. Gets the enumerator instance. The enumerator instance. Current item for the enumerator. Gets the value for the Items property. Value for the Items property. Ordinal position for the item in the method list. Sets the value in the AllowDuplicates property. New value for the AllowDuplicates property. Sets the value for the Items property. Ordinal position for the item. New value for the item at the specified position. Performs actions needed to insert a method at the specified position. Ordinal position for the item. Method instance to store at the specified position. Raises an index out of bounds exception.

RaiseIndexOutOfBounds is a procedure which raises an EListError exception when an invalid index position is used when accessing the Items in the method list. Index is the invalid ordinal position requested, and is included in the exception message.

Raises an EListError exception that includes the value in Index in the exception message.

TMethodList.Items EListError
Ordinal position to include in the exception message. Destructor for the class instance.

Destroy is the destructor for the class instance. Destroy calls ReAllocMem to reset the size for memory allocated to the Items property. Destroy calls the inherited destructor.

TMethodList.Items
Gets the number of items included in the method list.

Count is an Integer function used to get the number of Items included in the method list. The value is derived from an internal member in the class instance which gets updated in the Add and Delete methods.

TMethodList.Add TMethodList.Delete
Value for the function. Provides access to items in the method list in reverse order.

NextDownIndex is a Boolean function which provides access to Items in the list in reverse order. NextDownIndex ensures that the variable parameter in Index is decremented, and remains in range for the number of methods in the Items property. The return value is True when the updated value in Index is a valid ordinal position in Items. The return value is False when Index contains -1.

NextDownIndex is used in the implementation of the CallNotifyEvents method.

TMethodList.Items TMethodList.CallNotifyEvents
True when Index is in the range needed to access Items. Ordinal position for the next item. Gets the position where the specified method is stored in the list.

IndexOf is an Integer function used to get the ordinal position in Items where the TMethod instance in AMethod is stored.

IndexOf examines the memory allocated for the Items property. When memory has not been allocated (no methods have been added to the list), the return value is -1. Otherwise, values in the Items property are compared to the TMethod instance in AMethod. The return value is set to the ordinal position in Items where AMethod was located. The return value is in the range 0..Count-1.

TMethodList.Items TMethodList.Count
Ordinal position for the specified method. Method to locate in the items for the list. Copies property values from Source into the current class instance.

Assign is an overridden method in TMethodList used to implement object persistence for the TMethodList class type. Assign calls Clear ro reallocate memory for the Items in the class instance. Values from the Items property in Source are added to the current class instance.

TMethodList instance with values copied in the method. Clears the values in Items by Reallocating memory for the property with a length of 0 bytes. Deletes the method stored at the specified position.

Delete is a procedure used to delete the method stored at the specified ordinal position in the list. Delete decrements the internal member used for the Count function.

The method instance is physically removed from the list by moving memory allocated beyond the position in Index (if needed) to the requested position. ReAllocMem is called to resize allocated memory to accommodate the new number of items in the Count property.

Use Remove to delete a specific TMethod instance from the Items in the list.

TMethodList.Items TMethodList.Count TMethodList.Remove
Ordinal position for the method to delete from the list. Removes the specified method from the items in the list.

Remove is a procedure used to remove the TMethod instance specified in AMethod from the Items in the list. Remove ensures that memory has been allocated for the list, and calls the IndexOf method to locate the specified method instance in AMethod. When it exists in the Items property, the Delete method is called to delete the method at the required ordinal position.

TMethodList.Items TMethodList.IndexOf TMethodList.Delete
Method to remove from the items in the list. Adds the specified method to the list.

Add is an overloaded procedure used to add the TMethod instance specified in AMethod to the Items in the list. Add uses the value in AllowDuplicates to determine if the Items in the list need to be checked for duplicates prior to adding the specified method. When AllowDuplicates is False, the IndexOf method is used to locate an existing entry in Items with the method in AMethod. If the method does not exist in Items, or AllowDuplicates is True, the method in AMethod is appended to the end of the memory allocated to the Items property. ReAllocMem is used to set the new size for the memory allocation.

Add ensures the the internal member used for the Count function is incremented when necessary.

An overloaded variant of the Add method includes the AsLast parameter. AsLast indicates if the position in items where the new method is stored. When AsLast is True, the method in AMethod is appended to the end of allocated memory using the Add method. When AsLast contains False, the Insert method is called to store the new method at the beginning of allocated memory.

TMethodList.AllowDuplicates TMethodList.IndexOf TMethodList.Count TMethodList.Insert
Method to add to the list. Indicates if the method should be appended to the end of the list. Inserts the specified method at the given position in the list.

Insert is a procedure used to inset the specified method at the given position in Index.

Insert uses the value in AllowDuplicates to determine if the Items in the list need to be checked for duplicates prior to adding the specified method. When AllowDuplicates is False, the IndexOf method is used to locate an existing entry in Items with the method in AMethod. If the method does not exist in Items, or AllowDuplicates is True, the InternalInsert method is called to store the new method at the required position.

When Index is a valid ordinal position in Items, the Move method is called to relocate existing method entries in the list. The RaiseIndexOutOfBounds method is called if the value specified in Index is not in the range 0..Count-1.

Use Add to append a method at the end of the Items in the list.

Raises an EListError exception when Index contains an invalid ordinal position for Items in the list (not in the range 0..Count-1).

TMethodList.AllowDuplicates TMethodList.Count TMethodList.Move
Ordinal position where the method will be inserted. Method to insert at the specified position. Moves the position for the specified method in the list.

Move is a procedure used to relocate a method stored in Items using the specified positions arguments. OldIndex contains the existing ordinal position where the method is stored in Items. NewIndex contains the new ordinal position for the method in the Items property.

No actions are performed in the method when OldIndex and NewIndex contain the same value. RaiseIndexOutOfBounds is called to raise an exception when NewIndex does not contain a valid ordinal position for the Items property. In other words, NewIndex contains a negative value or exceeds the value from the Count function.

Move calls the System.Move method to relocate allocated memory in the Items property using the specified ordinal positions, and stores the requested method at the position in NewIndex.

Raises an EListError exception when NewIndex contains an invalid ordinal position for Items in the list (not in the range 0..Count-1).

TMethodList.Items TMethodList.Count
Existing position for the specified method. New position for the specified method. Removes methods from the list if they are for the specified object.

RemoveAllMethodsOfObject is a procedure used to remove methods in the Items property which belong to the object instance specified in AnObject. RemoveAllMethodsOfObject iterates over the methods in the Items property (in reverse order), and compares the object in AnObject to the TMethod.Data for each of the store Items. When they refer to the same TObject instance, the Delete method is called to remove the method from Items.

No actions are performed in the method when memory has not been allocated to the Items property using the Add or Insert methods.

TMethodList.Items TMethodList.Delete TMethod
Object compared to the entries in the list. Performs event notifications using methods in the list.

CallNotifyEvents is a procedure used to perform event notifications using methods stored in the Items for the list. Methods stored in Items are processed in reverse order, and cast to a TNotifyEvent type using the value in Sender as the originator of the event notification.

TNotifyEvent
Originator of the event notification(s). Gets an enumerator for the list that navigates in reverse order.

GetReversedEnumerator is a TItemsEnumerator function used to get an enumerator that navigates Items in the list in reverse order. The enumerator provides access to the current value, and allows navigation to the next value for the enumerator. Item navigation occurs in reverse order (descending ordinal position) in the list.

The reverse enumerator for the list. Gets an enumerator for the list. GetEnumerator is a TItemsEnumerator function used to get an enumerator for Items in the list. The enumerator provides access to the current value, and allows navigation to the next value for the enumerator. Item navigation occurs in the natural order (ascending ordinal position) in the list. The enumerator for the list. Provides indexed access to methods in the list.

Items is a TMethod property that provides indexed access to methods in the list by the ordinal position specified in Index. The TMethod instance contains the Data (object reference) and Code (pointer to the method) store in the list items.

Reading a value in the Items property accesses the block of memory stored in an internal member at the position in Index. When Writing a value in the Items property, the value in AllowDuplicates is used to determine if duplicates of the TMethod value are allowed in the list. When AllowDuplicates is False, an EListError exception is raised for the error condition. The IndexOf method is called to determine if the method already exists in Items.

Items is the default property in TMethodList and provides support for enumerators using the GetEnumerator and GetReversedEnumerator methods.

Raises an EListError exception when a duplicate value is detected in the Items property.

TMethodList.AllowDuplicates TMethodList.IndexOf TMethodList.GetEnumerator TMethodList.GetReversedEnumerator TMethod EListError
Ordinal position for the method to access in the method list. Indicates if duplicate methods are allowed in the list.

AllowDuplicates is a Boolean property that indicates if duplicate entries for any given method are allowed in the method list. The default value for the property is False, and indicates that a duplicate method entry will be rejected and an exception will be raised for the error condition.

Changing the value in the AllowDuplicates property to False causes the existing Items in the list to be examined for duplicate methods. When a duplicate method is found, the Delete method is called to remove duplicate values for any of the method in the Items property.

AllowDuplicates is used in the implementation of the Add and Insert methods, and when setting a value in the Items property.

The default value for the property was change from True to False in version 1.3.

TMethodList.Add TMethodList.Insert TMethodList.Items TMethodList.Delete
Performs a comparison between the specified methods.

CompareMethods is a Boolean function used to compare the specified methods. m1 and m2 are TMethod parameters with the values compared in the function. The comparison examines the Code and Data members in the TMethod records. The return value is True when the Code and Data members are identical in both records.

True when the compared methods share the same code and data. Method for the comparison. Another method for the comparison.