Componentes - propriedades numeradas |
Top Previous Next |
|
=========== Propriedades numeradas ===============
Antes da declaração do componente crie um tipo numerada:
type TPrinterType = ( EpsonLQ, EpsonFX, EpsonLX, Emilia, Rima, HPDeskJet680C, XeroxDeskJet, HPLaserJet4L, StylusC800 );
TmlPrinter = class(TComponent) private fPrinterType : TPrinterType; procedure SetPrinter(const Value: TPrinterType); public constructor Create(AOwner: TComponent); override; published property Driver: TPrinterType read fPrinterType write SetPrinter default StylesC800; end; // note que o Default diminui tam. do exe (veja a dica sobre ele)
Constructor TmlPrinter.Create(AOwner: TComponent); begin inherited Create(AOwner); SetPrinter(StylusC800); end;
// neste exemplo foi usado um SetPrinter ao inves da var direta porque quando o use // troca o valor da propriedade é necessário modificar outra cositas: procedure TmlPrinter.SetPrinter(const Value: TPrinterType); begin fPrinterType := Value; Case fPrinterType of EpsonLQ: begin ciDescricao := 'EPSON LQ'; ciMaxLin_66 := 60; end; EpsonFX: begin ciDescricao := 'EPSON FX'; ciMaxLin_66 := 60; end; ... Etc... end; |