Componentes - propriedade stringlist |
Top Previous Next |
|
Está com dificuldades de criar uma propriedade StringList? Tá dando Access Violation?
Veja abaixo um exemplo completo e delire:
type TComLista = class(TComponent) private FLines: TStrings; <--------- Declarado do tipo TStrings procedure SetLines (Value: TStrings); function GetLines: TStrings; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Lines: TStrings read GetLines write SetLines; <-------- no read e write são usados procedures e não directly end;
implementation
constructor TComLista.Create(AOwner: TComponent); begin inherited Create (AOwner); FLines := TStringList.Create; <---- Cria do tipo StringList end;
destructor TComLista.Destroy; begin FLines.Free; <------- antes do Destroy inherited Destroy; end;
function TComLista.GetLines: TStrings; begin Result := FLines; end;
procedure TComLista.SetLines(Value: TStrings); begin FLines.Assign (Value); end;
// Have fun! |