Difference between revisions of "RPC HELP TMult Sorted Example"

From VistApedia
Jump to: navigation, search
(Created page with " RPC Broker Help Home <h2>Sorted Example</h2> The following program code demonstrates the effect the Sorted property has on a TMult variable. Notice that b...")
 
Line 56: Line 56:
 
       '''until''' Subscript = '';
 
       '''until''' Subscript = '';
 
      
 
      
    //existing entries will remain in sorted order
+
      //existing entries will remain in sorted order
    Mult1.Sorted := False;
+
      Mult1.Sorted := False;
    Memo1.Lines.Add('');
+
      Memo1.Lines.Add('');
    Memo1.Lines.Add('Unsorted order:');
+
      Memo1.Lines.Add('Unsorted order:');
   
+
     
    //set a starting point
+
      //set a starting point
    Subscript := '';
+
      Subscript := '';
    '''repeat'''
+
      '''repeat'''
      //get next Mult element
+
        //get next Mult element
      Subscript := Mult1.Order(Subscript, 1);
+
        Subscript := Mult1.Order(Subscript, 1);
      //if not the end of list
+
        //if not the end of list
      '''if''' Subscript <> '' '''then'''
+
        '''if''' Subscript <> '' '''then'''
      //display subscript – value
+
        //display subscript – value
      Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult1[Subscript])
+
        Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult1[Subscript])
      //stop when reached the end
+
        //stop when reached the end
 
     '''until''' Subscript = '';
 
     '''until''' Subscript = '';
 
      
 
      

Revision as of 22:24, 3 July 2015

RPC Broker Help Home

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:

  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.