一个有趣的小错误!谁有空来瞧瞧!
新建一个窗体,放上一个Win32页的组件TComboBoxEx,再放两个TButton:
简单的代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
ComboBoxEx1: TComboBoxEx;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
Str:string;
procedure TForm1.Button1Click(Sender: TObject);
begin
Str:='莫名其妙';
ComboBoxEx1.Text:=Str;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Str:=ComboBoxEx1.Text;
ShowMessage(IntToStr(Length(Str)));
end;
end.
先点Button1再点Button2,显示为“7”。
如果将Button2的事件该为如下:
procedure TForm1.Button2Click(Sender: TObject);
begin
Str:=ComboBoxEx1.Text;
ShowMessage(Str+IntToStr(Length(Str)));
end;
则输出:“莫名其妙8”。