The following program code demonstrates the use of the TMult assign method to assign listbox items (TStrings) to a TMult:
procedure TForm1.Button1Click(Sender: TObject); var Mult1: TMult; Subscript: string; begin Mult1 := TMult.Create(Form1); //Create Mult1. Make Form1 its owner ListBox1.Items.Add('One'); //Fill listbox with some strings ListBox1.Items.Add('Two'); ListBox1.Items.Add('Three'); ListBox1.Items.Add('Four'); ListBox1.Items.Add('Five'); Mult1.Assign(ListBox1.Items); //assign (copy) listbox strings to Mult Memo1.Font.Name := 'Courier'; //configure memo box for better display Memo1.Lines.Clear; Memo1.Lines.Add('TStrings assigned:'); Subscript := ''; //set a starting point repeat Subscript := Mult1.Order(Subscript, 1); //get next Mult element if Subscript <> '' then //if not the end of list Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult1[Subscript]) //display subscript - value until Subscript = ''; //stop when reached the end end;
Expected output:
Assign Method Example
The following program code demonstrates the use of the TMult assign method to assign one TMult to another:
procedure TForm1.Button1Click(Sender: TObject); var Mult1, Mult2: TMult; Subscript: string; begin Mult1 := TMult.Create(Form1); //Create Mult1. Make Form1 its owner Mult2 := TMult.Create(Form1); //Create Mult2. Make Form1 its owner Mult1['First'] := 'One'; //Fill Mult1 with some strings Mult1['Second'] := 'Two'; Mult1['Third'] := 'Three'; Mult1['Fourth'] := 'Four'; Mult1['Fifth'] := 'Five'; Mult2.Assign(Mult1); //assign (copy) Mult1 strings to Mult2 Memo1.Font.Name := 'Courier'; //configure memo box for better display Memo1.Lines.Clear; Memo1.Lines.Add('TMult assigned:'); Subscript := ''; //set a starting point repeat Subscript := Mult2.Order(Subscript, 1); //get next Mult element if Subscript <> '' then //if not the end of list Memo1.Lines.Add(Format('%10s', [Subscript]) + ' - ' + Mult2[Subscript]) //display subscript - value until Subscript = ''; //stop when reached the end end;
Expected output: