在一次对ini文件操作时;由于笔误;将代码敲错;于是combobox的change事件的代码成了下面这个;
procedure TForm1.ComboBox1Change(Sender: TObject);
var INIfile: TINIfile;
begin
   INIfile := Tinifile.Create(extractfilepath(application.ExeName) + '1.ini');
   inifile.ReadSection(combobox1.Text,combobox1.Items);
end;这时出现了一点意外;就是往combobox1中输入的东西全部变成了反序排列的;
譬如输入【张类】变成了【类张】;
 相应的【123】..【321】
       【zaq】..【qaz】哪位朋友给点提示;为什么会这样;先谢谢了;

解决方案 »

  1.   

    我试了一下没有这个问题嘛。。我的combobox中的内容在执行这样的操作后全都变为空了。
      

  2.   

    我看了一下,确实是这样的原因是因为这句
    procedure TIniFile.ReadSection(const Section: string; Strings: TStrings);
    const
      BufSize = 16384;
    var
      Buffer, P: PChar;
    begin
      GetMem(Buffer, BufSize);
      try
        Strings.BeginUpdate;
        try
          Strings.Clear;//////////////////////////////////原因是因为这句
          if GetPrivateProfileString(PChar(Section), nil, nil, Buffer, BufSize,
            PChar(FFileName)) <> 0 then
         ……
    不信的话可以这样看看Procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
      Combobox1.Items.Clear;
    end;是不是效果是一样的?那我们就看这个Clearprocedure TCustomComboBoxStrings.Clear;
    var
      S: string;
    begin
      S := ComboBox.Text;
      SendMessage(ComboBox.Handle, CB_RESETCONTENT, 0, 0);
      ComboBox.Text := S;
      ComboBox.Update;
    end;
    看到他是先保存原来的text,
    然后发一个重置消息,
    然后再还原text
    所以光标就跑到在前面了其实最后就是这样啦Procedure TForm1.ComboBox1Change(Sender: TObject);
    var
      S: string;
    begin
      S := ComboBox1.Text;
      SendMessage(ComboBox1.Handle, CB_RESETCONTENT, 0, 0);
      ComboBox1.Text := S;
    end;
      

  3.   

    这是CB_RESETCONTENT消息的帮助An application sends a CB_RESETCONTENT message to remove all items from the list box and edit control of a combo box. CB_RESETCONTENT  
    wParam = 0;     // not used; must be zero 
    lParam = 0;     // not used; must be zero 
     ParametersThis message has no parameters. Return ValuesThis message always returns CB_OKAY. ResIf you create the combo box with an owner-drawn style but without the CBS_HASSTRINGS style, the owner of the combo box receives a WM_DELETEITEM message for each item in the combo box.