Hola a todos, estoy incursionando en Delphi(7) y tengo el siguiente problema:
Estoy tratando de crearme un componente que hereda de TComboBox. La idea es poder utilizar todas las funcionalidades del Combo, pero además estoy creando unas funciones para poder agregar valores a la propieded Object de cada Item. Esto con el fin de rescatar estos valores(dependiendo del item seleccionado) y realizar algunas taras con ese valor.
De acuerdo al código que he hecho, esto funciona, pero cuando cierro el formulario que contiene mi control, se dispara el Destroy de mi componente y cuando trato de accesar los Items, la aplicación me arroja el mensaje '.....has no parent windows'.
Agragdeceré cualquier ayuda al respecto......
Este el código del control que estopy haciendo:
Código Delphi
[-]
unit uRBComboBox;
interface
uses Classes, StdCtrls, SysUtils;
type
TString = class(TObject)
private
FStr: String;
public
constructor Create ;
property Str: String read FStr write FStr;
end;
TCustomComboIData = class(TComboBox)
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetItemData(Indice: Integer): String;
function NewItem(Cadena: String; Valor: String = ''): Integer;
end;
TRBComboBox = Class(TCustomComboIData);
procedure Register;
implementation
uses Windows;
var obj: TString;
procedure Register;
begin
RegisterComponents('Samples', [TRBComboBox]);
end;
constructor TString.Create();
begin
inherited Create;
end;
constructor TCustomComboIData.Create(AOwner: TComponent);
begin
inherited;
end;
destructor TCustomComboIData.Destroy;
var i:integer;
begin
for i:= 0 to Self.Items.Count-1 do begin
TString(Items.Objects[i]).Free;
Items.Objects[i]:= nil;
end;
inherited Destroy;
end;
function TCustomComboIData.NewItem(Cadena: String; Valor: String = ''): Integer;
begin
Result := Items.Add(Cadena);
obj := TString.Create;
obj.Str := Valor;
Items.Objects[Result] := obj;
end;
function TCustomComboIData.GetItemData(Indice: Integer): String;
begin
Result := TString(Items.Objects[Indice]).Str;
end;
end.
Gracias.......