本来想实现的功能是:当选中TCombox某个选项时能直接取得选中项相关的信息,所以在生成列表的时候就直接将相关信息作为对象插入到TCombox的选项。
问题是:当调用Button1Click方法插入一个(或多个)ITEM时不会出错,
但当关闭整个Form时会抛出一个读地址出错(Exception EAccessViolation in module Project1.exe at 00019106.Access violatioin at address 00419106 in Project1.ext.Read of address 74736574),不晓得为什么?望高手指教。!!
另外,不晓得大家是怎么实现我这样的功能的,先谢谢大家了。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Msg = class(TObject)
Name:String;
ID:String;
end;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton; procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
objMsg:Msg;
begin objMsg.Name :='TestUserName';
objMsg.ID :='123456';
ComboBox1.Items.AddObject(objMsg.Name,objMsg);
end;end.
问题是:当调用Button1Click方法插入一个(或多个)ITEM时不会出错,
但当关闭整个Form时会抛出一个读地址出错(Exception EAccessViolation in module Project1.exe at 00019106.Access violatioin at address 00419106 in Project1.ext.Read of address 74736574),不晓得为什么?望高手指教。!!
另外,不晓得大家是怎么实现我这样的功能的,先谢谢大家了。unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Msg = class(TObject)
Name:String;
ID:String;
end;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton; procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
objMsg:Msg;
begin objMsg.Name :='TestUserName';
objMsg.ID :='123456';
ComboBox1.Items.AddObject(objMsg.Name,objMsg);
end;end.
PMsg = ^TMsg;
TMsg = Record
Name:String;
ID:String;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
objMsg:PMsg;
begin
new(objMsg);
objMsg.Name :='TestUserName';
objMsg.ID :='123456';
ComboBox1.Items.AddObject(objMsg.Name,TObject(objMsg));
end;//釋放procedure DestroyComboBox(aComBoBox: TComBoBox);
var
i: integer;
begin
for i := 0 to aComBoBox.Items.Count - 1 do
if Assigned(aComBoBox.Items.Objects[i]) then
Dispose(PObj(aComBoBox.Items.Objects[i]));
end;
var
i: integer;
begin
for i := 0 to aComBoBox.Items.Count - 1 do
if Assigned(aComBoBox.Items.Objects[i]) then
Dispose(PMsg(aComBoBox.Items.Objects[i]));
end;