如string a:='adfs?drt?wer?fdcv',其中?的数量不限,即加到combobox1中的items不限,
即怎样把adfs,drt,wer,fdcv加到combobox1中?

解决方案 »

  1.   

    例如:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        procedure FormCreate(Sender: TObject);
      private
        procedure SplitToComboBox(Combo: TComboBox;  S, Split: String);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.SplitToComboBox(Combo: TComboBox;  S, Split: String);
    var
      i : Integer;
    begin
      Combo.Items.Clear;
      i := pos(Split, S);
      while i > 0 do
      begin
        Combo.Items.Add(copy (S, 1, i-1));
        S := copy (S, i + 1, length(S) - i);
        i := pos(Split, S);
      end;
      if S <> '' then Combo.Items.Add(S);
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      SplitToComboBox (ComboBox1, '123?456?abc?def', '?');
    end;end.