Mega Code Archive

 
Categories / Delphi / Examples
 

Customizing the object inspector

The following peace of code adds a new feature to the Object Inspector. Whenever you create a component with a filename-property of the type TFileName, the Inspector will let you browse to find the file you want. unit filenameprop; interface uses SysUtils, DsgnIntf; type TFileNameProperty = class(TStringProperty) public function GetAttributes: TPropertyAttributes; override; procedure Edit; override; end; procedure Register; implementation uses Dialogs, Forms; function TFileNameProperty.GetAttributes: TPropertyAttributes; begin Result := [paDialog] end {GetAttributes}; procedure TFileNameProperty.Edit; begin with TOpenDialog.Create(Application) do try Title := GetName; { name of property as OpenDialog caption } FileName := GetValue; Filter := 'All Files (*.*)|*.*'; HelpContext := 0; Options := Options + [ofShowHelp, ofPathMustExist, ofFileMustExist]; if Execute then SetValue(FileName); finally Free end end {Edit}; procedure Register; begin RegisterPropertyEditor(TypeInfo(TFileName), nil, '', TFileNameProperty) end; end.