Difference between revisions of "RPC HELP TMult Sorted Example"

From VistApedia
Jump to: navigation, search
 
Line 1: Line 1:
 
[[RPC_Broker_Help| RPC Broker Help Home]]
 
[[RPC_Broker_Help| RPC Broker Help Home]]
 
<h2>Sorted Example</h2>
 
<h2>Sorted Example</h2>
 +
[[RPC_HELP_Mult_Sorted|Back]]
 +
 
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:
 
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.
 
# Start a new application.

Latest revision as of 22:25, 3 July 2015

RPC Broker Help Home

Sorted Example

Back

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:

  1. Start a new application.
  2. Drop one memo and one button on the form. Arrange controls as in the figure below.
  3. 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.