Less(LValue: IRdsDictionaryElement; RValue:IRdsDictionaryElement): Boolean;
Less(LValue: IRdsDictionaryElement; RValue:IRdsDictionaryElement): boolean;
LValue, RValue. Sorting elements.
The Less method compares elements that are passed by the LValue and RValue input parameters.
Executing the example requires a form with a button on named Button1, the RdsDictionaryBox component named RdsDictionaryBox1 and the UiRdsDictionary component which is used as a data source for RdsDictionaryBox1.
Add links to the Collections, ForeCollections, Rds system assemblies.
Class IRdsElementComparer_Less_FormForm: Form
Button1: Button;
RdsDictionaryBox1: RdsDictionaryBox;
UiRdsDictionary1: UiRdsDictionary;
dictionary: IRdsDictionaryInstance;
LValue, RValue: IRdsDictionaryElement;
sorter: IRdsElementsSorter;
com: CustomComparer;
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Begin
sorter.Sort(True);
RdsDictionaryBox1.RefreshElements;
End Sub Button1OnClick;
Sub IRDSELEMENTCOMPARER_LESS_FORMFormOnShow(Sender: Object; Args: IEventArgs);
Begin
com := New CustomComparer.Create;
dictionary := rdsdictionaryBox1.Source.Instance;
sorter := dictionary.Elements.CreateSorter(dictionary.Elements.Root);
sorter.Comparer := com As IRdsElementComparer;
End Sub IRDSELEMENTCOMPARER_LESS_FORMFormOnShow;
End Class IRdsElementComparer_Less_FormForm;
Class CustomComparer: Object, IRdsElementComparer
Function Less(LValue: IRdsDictionaryElement; RValue: IRdsDictionaryElement): Boolean;
Var
comp: IComparer;
Begin
comp := comparer.StringCaseInsensitiveComparer;
If (Comp.Compare(LValue.Name, RValue.Name) > 0) Then Return True
Else Return False;
End If;
End Function Less;
End Class CustomComparer;
Imports Prognoz.Platform.Interop.ForeCollections;
Imports Prognoz.Platform.Interop.Rds;
Public Partial Class IRdsElementComparer_Less_NET_FormForm: Prognoz.Platform.Forms.Net.ForeNetForm
dictionary: IRdsDictionaryInstance;
LValue: IRdsDictionaryElement;
RValue: IRdsDictionaryElement;
sorter: IRdsElementsSorter;
com: CustomComparer;
…
Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Begin
sorter.Sort(True);
RdsDictionaryBoxNet1.CtrlBox.RefreshElements();
End Sub;
Private Sub IRdsElementComparer_Less_NET_FormForm_Shown(sender: System.Object; e: System.EventArgs);
Begin
com := New CustomComparer.Create();
dictionary := rdsdictionaryBoxNet1.Source.Instance;
sorter := dictionary.Elements.CreateSorter(dictionary.Elements.Root);
sorter.Comparer := com As IRdsElementComparer;
End Sub;
End Class;
Public Class CustomComparer: Object, IRdsElementComparer
Public Function Less(LValue: IRdsDictionaryElement; RValue: IRdsDictionaryElement): boolean;
Var
comp: IComparer;
compclass: ComparerClass = New ComparerClass();
Begin
comp := compclass.StringCaseInsensitiveComparer;
If (Comp.Compare(LValue.Name, RValue.Name) > 0) Then Return True
Else Return False;
End If;
End Function Less;
End Class CustomComparer;
After executing the example pressing the button creates custom sorter of the MDM dictionary elements.
See also: