S
sunshine1750
Unregistered / Unconfirmed
GUEST, unregistred user!
想在这个控件的析构事件里,释放ITEM里保存的对象时出错
请帮偶看看,先谢过了
————————————————————————————————
unit ComboboxExRm;
interface
uses
SysUtils, Classes, Windows, Messages, Controls, StdCtrls, ExtCtrls;
type
TSampObj = class
str: string;
end;
TComboboxExRM = class(TCustomComboBox)
private
protected
public
procedure AddItemRm (const ACaption, AID: string);virtual;
function GetCurrCaption: string;
function GetCurrID: string;
destructor Destroy; override;
published
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('RMComponent', [TComboboxExRM]);
end;
{ TComboboxExRM }
destructor TComboboxExRM.Destroy;
var
Cnt: integer;
begin
for Cnt := self.Items.Count - 1 downto 0 do
if Assigned(Items.Objects[Cnt]) then
Items.Objects[Cnt].Free;
inherited;
end;
procedure TComboboxExRM.AddItemRm(const ACaption, AID: string);
var
SampObj: TSampObj;
begin
SampObj := TSampObj.Create;
SampObj.str := AID;
AddItem(ACaption, SampObj);
end;
function TComboboxExRM.GetCurrCaption: string;
begin
Result := Text;
end;
function TComboboxExRM.GetCurrID: string;
begin
result := TSampObj(Items.Objects[ItemIndex]).str;
end;
end.
请帮偶看看,先谢过了
————————————————————————————————
unit ComboboxExRm;
interface
uses
SysUtils, Classes, Windows, Messages, Controls, StdCtrls, ExtCtrls;
type
TSampObj = class
str: string;
end;
TComboboxExRM = class(TCustomComboBox)
private
protected
public
procedure AddItemRm (const ACaption, AID: string);virtual;
function GetCurrCaption: string;
function GetCurrID: string;
destructor Destroy; override;
published
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('RMComponent', [TComboboxExRM]);
end;
{ TComboboxExRM }
destructor TComboboxExRM.Destroy;
var
Cnt: integer;
begin
for Cnt := self.Items.Count - 1 downto 0 do
if Assigned(Items.Objects[Cnt]) then
Items.Objects[Cnt].Free;
inherited;
end;
procedure TComboboxExRM.AddItemRm(const ACaption, AID: string);
var
SampObj: TSampObj;
begin
SampObj := TSampObj.Create;
SampObj.str := AID;
AddItem(ACaption, SampObj);
end;
function TComboboxExRM.GetCurrCaption: string;
begin
Result := Text;
end;
function TComboboxExRM.GetCurrID: string;
begin
result := TSampObj(Items.Objects[ItemIndex]).str;
end;
end.