一个有趣的小错误!谁有空来瞧瞧!

enlightenment 2002-09-24 02:06:34
新建一个窗体,放上一个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”。

...全文
33 67 打赏 收藏 转发到动态 举报
写回复
用AI写文章
67 条回复
切换为时间正序
请发表友善的回复…
发表回复
freekany2002 2002-09-27
  • 打赏
  • 举报
回复
我也碰到了类似的问题,很奇怪
hansion3406 2002-09-27
  • 打赏
  • 举报
回复
如果把STR初始化为空的话的话就都是8了!
HuangWei_China 2002-09-27
  • 打赏
  • 举报
回复
我可是一次也没有做出"莫名其妙8"来不知你们是怎么做出来的.
zyc 2002-09-26
  • 打赏
  • 举报
回复
用ComboBox没有问题,是ComboBoxEx的问题。不要在D6下用ComboBoxEX
happyfancy 2002-09-26
  • 打赏
  • 举报
回复
D7在Win2000下的汉字显式有问题,Label标签会最后一个汉字显示一半,今天我编译了下,第一次显示7,第二次显示8
我该怎么解决。
S_C 2002-09-26
  • 打赏
  • 举报
回复
我的环境是:Win2K server +Delphi 7,系统补丁sp3;

运行正常!

结论:只有Delphi6有此问题,(Delphi5没有试过)。
drizzt123 2002-09-25
  • 打赏
  • 举报
回复
再测了一次,就是TComboBoxEx的Bug;
什么代码都不写,直接在属性编辑器里将text赋值'莫名其妙'然后运行程序,可以看见显示出来的值为'莫名其';直接退出程序,检查属性编辑器中text值,发现在妙字后多了半个字符
boynicky 2002-09-25
  • 打赏
  • 举报
回复
???我为什么第一次做出来就是8啊!

第二次就是莫名其妙8?
xiaoqianghan 2002-09-25
  • 打赏
  • 举报
回复
莫名其妙!!!!
在我的机器上出错
提示为:[Fatal Error] Required package 'nmfast' not found
莫名其妙!!!!
Sterntaler 2002-09-25
  • 打赏
  • 举报
回复
SetLength(astr, Length(str) + Length(astr));
strcat(PChar(astr), PChar(str)); // 如果写成 astr := astr + str 不行。
Caption := astr;

上面的问题是解决了,不过我不是很理解其中的原因。谁告诉我一声?
leon2k 2002-09-25
  • 打赏
  • 举报
回复
我很久之前就觉得D6在Win2000下的汉字显式有问题,Label标签会最后一个汉字显示一半,有的时候会计算出基数个字节?明显是有BUG,可能打SP会好一些,不过我现在用的是D5,没有这些问题。因为我总觉得D6问题挺多。
noall 2002-09-25
  • 打赏
  • 举报
回复
还在争啊。

跟你们说了。。

没有错啊。。

打打补丁嘛。


Sterntaler 2002-09-25
  • 打赏
  • 举报
回复
Unicode.
Sterntaler 2002-09-25
  • 打赏
  • 举报
回复
把 ComboBoxEx 换成 ComboBox 可以解决问题,看似是 ComboBoxEx 的毛病;如果说是 ComboBoxEx.Text 的问题的话,下面的问题又怎么解释?!

procedure TForm1.Button2Click(Sender: TObject);
var
pstr: PChar;
i: Integer;
astr: string;
begin
Str:=ComboBoxEx1.Text;

i := 0;
pstr := @str[1];
repeat
astr := astr + IntToHex(Byte(pstr[i]), 2) + #10#13;
Inc(i);
until pstr[i] = #0;
Caption := str; // 如果 Caption := str, 运行多少次都没问题;
// 如果 Caption := str + astr,结果str也错了!
end;
Sterntaler 2002-09-25
  • 打赏
  • 举报
回复
把 ShowMessage 该成 Form1.Caption := Str + IntToStr(Length(Str)); 也就没上述问题了。
lzf913 2002-09-25
  • 打赏
  • 举报
回复
估计这是个bug,我把代码改成这样就没问题了:
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.Items.Add(str);
ComboBoxEx1.ItemIndex:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Str:=ComboBoxEx1.Items[ComboBoxEx1.ItemIndex];
ShowMessage(Str+IntToStr(Length(Str)));
end;

end.
zhangking 2002-09-25
  • 打赏
  • 举报
回复
重要通告:
我的测试结果是:以上人好象在集体做梦啊,我的运行结果表明代码没错,结果也没错。每次都是 8 !!!
我的机器配置是,Win98se+Delphi6.0. 装了Office2000,IE6.0。Windows在线 Update 过。
不是也“莫名其妙”吗?
主要代码是从楼顶那儿拷贝粘贴的。我的代码如下:
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.
daniel007 2002-09-25
  • 打赏
  • 举报
回复
有这等事?可惜现在手头的机子没装delphi,明天试试看?
neilwq 2002-09-25
  • 打赏
  • 举报
回复
建议有谁e文好的把此问题发给borland
ddvboy 2002-09-25
  • 打赏
  • 举报
回复
我用的DELPHI5直接出的八!
是不是你们用的DELPHI版本问题?
加载更多回复(47)

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧