RPC HELP TMult Assign Example

From VistApedia
Jump to: navigation, search

RPC Broker Help Home

Assign Example (TMult Class)

Back

The following program code demonstrates the use of the TMult assign method to assign listbox items (Tstrings) to a TMult:

  1. Start a new application.
  2. Drop one listbox, 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 listbox with some strings
     ListBox1.Items.Add('One');
     ListBox1.Items.Add('Two');
     ListBox1.Items.Add('Three');
     ListBox1.Items.Add('Four');
     ListBox1.Items.Add('Five');
     
     //assign (copy) listbox strings to Mult
     Mult1.Assign(ListBox1.Items);
     	
     //configure memo box for better display
     Memo1.Font.Name := 'Courier';
     Memo1.Lines.Clear;
     Memo1.Lines.Add('Tstrings assigned:');
     
     //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 the project and click on the button.

Expected output:



The following program code demonstrates the use of the TMult assign method to assign one TMult to another:

  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, Mult2: TMult;
     Subscript: string;
   begin
     //Create Mult1. Make Form1 its owner
     Mult1 := TMult.Create(Form1);
     //Create Mult2. Make Form1 its owner
     Mult2 := TMult.Create(Form1);
     
     //Fill Mult1 with some strings
     Mult1['First'] := 'One';
     Mult1['Second'] := 'Two';
     Mult1['Third'] := 'Three';
     Mult1['Fourth'] := 'Four';
     Mult1['Fifth'] := 'Five';
     	
     //assign (copy) Mult1 strings to Mult2
     Mult2.Assign(Mult1);
     
     //configure memo box for better display
     Memo1.Font.Name := 'Courier';
     Memo1.Lines.Clear;
     Memo1.Lines.Add('TMult assigned:');
     
     //set a starting point
     Subscript := ;
     repeat
       //get next Mult element
       Subscript := Mult2.Order(Subscript, 1);
       //if not the end of list
       if Subscript <>  then
         //display subscript – value
   	  Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult2[Subscript])
       //stop when reached the end
     until Subscript = ;
   end;

4. Run the project and click on the button.

Expected output: