Componentes - propriedade TStrings lendo de arquivoComponentes - propriedade TStrings lendo de arquivo |
Top Previous Next |
{I'm trying to get a new non-visual component created, and one of the properties will be a FileName property. How can I set it up so that at design time the user will get the ellipses button on the property manager and get the file open box if they click on it and then be able to select a file name that way?
A: The following code is taken out of dsgnintf.pas (a file worth exploring!) for the TMPLayer.filename property, with help for C.Calvert.. } // In the component unit file header...
TFileNameProperty = class (TStringProperty) public function getattributes: TPropertyattributes; override; procedure Edit; override; end;
// add to the register function... RegisterPropertyEditor(Typeinfo(String), TMyComponent, 'Filename', TFileNameProperty);
// and the code...
function TFileNameProperty.GetAttributes; begin Result := [paDialog]; end;
Procedure TFilenameProperty.edit; var MFileOpen: TOpenDialog; begin MFileOpen := TOpenDialog.Create(Application); MFileOpen.Filename := GetValue; MFileOpen.Filter := 'The Right Kind Of Files|*.*'; (* Put your own filter here...*) MFileOpen.Options := MFileOpen.Options + [ofPathMustExist,ofFileMustExist]; try if MFileOpen.Execute then SetValue(MFileOpen.Filename); finally MFileOpen.Free; end; end; |