RPC HELP TMult Sorted Example
From VistApedia
Sorted Example
The following program code demonstrates the effect the Sorted property has on a TMult variable. Notice that by setting the Sorted property back to False, the list does not revert to its unsorted order:
- Start a new application.
- Drop one memo and one button on the form. Arrange controls as in the figure below.
- Copy the following code to the Button1.OnClick event:
procedure TForm1.Button1Click(Sender: TObject);
var
Mult1: TMult;
Subscript: string;
begin
//Create Mult1. Make Form1 its owner
Mult1 := TMult.Create(Form1);
//Fill Mult1 with some strings
Mult1['First'] := 'One';
Mult1['Second'] := 'Two';
Mult1['Third'] := 'Three';
Mult1['Fourth'] := 'Four';
Mult1['Fifth'] := 'Five';
//configure memo box for better display
Memo1.Font.Name := 'Courier';
Memo1.ScrollBars := ssVertical;
Memo1.Lines.Clear;
Memo1.Lines.Add('Natural order:');
//set a starting point
Subscript := ;
repeat
//get next Mult element
Subscript := Mult1.Order(Subscript, 1);
//if not the end of list
if Subscript <> then
//display subscript – value
Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult1[Subscript])
//stop when reached the end
until Subscript = ;
//list will now be sorted alphabetically
Mult1.Sorted := True;
Memo1.Lines.Add();
Memo1.Lines.Add('Sorted order:');
//set a starting point
Subscript := ;
repeat
//get next Mult element
Subscript := Mult1.Order(Subscript, 1);
//if not the end of list
if Subscript <> then
//display subscript – value
Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult1[Subscript])
//stop when reached the end
until Subscript = ;
//existing entries will remain in sorted order
Mult1.Sorted := False;
Memo1.Lines.Add();
Memo1.Lines.Add('Unsorted order:');
//set a starting point
Subscript := ;
repeat
//get next Mult element
Subscript := Mult1.Order(Subscript, 1);
//if not the end of list
if Subscript <> then
//display subscript – value
Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult1[Subscript])
//stop when reached the end
until Subscript = ;
end;
4. Run project and click on the button.
Expected output:
You may have to scroll up and down to see all of the output.