Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.191.254.0] |
|
Сообщ.
#1
,
|
|
|
Доброе утро!
Два вопроса по редакторам свойств. Первый редактор должен показать в свойстве Directory или Folder папку, которую я выбираю в диалоге OpenDialog: unit FileName; interface uses Windows, Messages, SysUtils, Variants, Dialogs, DesignIntf, Classes, Forms, DesignEditors, TypInfo; type TFileNameProperty = class(TPropertyEditor) public function GetAttributes: TPropertyAttributes; override; procedure Edit; override; end; procedure Register; implementation function TFileNameProperty.GetAttributes: TPropertyAttributes; begin Result := [paDialog] end; 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; procedure Register; begin RegisterPropertyEditor(TypeInfo(TFileName), nil, '', TFileNameProperty) end; Но, я получаю весь путь с файлом. Как правильно изменить код, чтобы получать только нужную директорию? Второй редактор должен в свойстве About просто показать форму. Примерный код ниже: unit AboutDlg; interface uses Windows, Messages, SysUtils, Variants, DesignIntf, Classes, Forms, DesignEditors, TypInfo, AboutDlgForm, Controls, MyComponent3; type TAboutDlgProperty = class(TStringProperty) public function GetAttributes: TPropertyAttributes; override; procedure Edit; override; function MyComponent: TMyComponent; end; implementation function TAboutDlgProperty.GetAttributes: TPropertyAttributes; begin Result := [paDialog] end; procedure TAboutDlgProperty.Edit; begin AboutForm := TAboutForm.Create(nil); try // show the dialog box if AboutForm.ShowModal = mrOK then Set?????Value(??????????); finally AboutForm.Free; end; end; function TAboutDlgProperty.MyComponent : TMyComponent; begin Result := GetComponent(0) as TMyComponent; end; procedure Register; begin RegisterPropertyEditor(TypeInfo(Integer), TMyComponent, 'About', TAboutDlgProperty) end; end. Что неверно прописано в коде, чтобы открывать форму диалога About? Как нужно в данном случае прописывать процедуру Edit? Спасибо. |
Сообщ.
#2
,
|
|
|
1. ExtractFilePath
2. Свойство About обычно не устанавливают, следовательно Set?????Value - не нужно |
Сообщ.
#3
,
|
|
|
касательно первого,
ExtractFileDir либо SelectDirectory из QDialogs второй вопрос не совсем понял |
Сообщ.
#4
,
|
|
|
Да, если я использую конструкцию:
procedure TFileNameProperty.Edit; begin with TOpenDialog.Create(nil) 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(ExtractFileDir(FileName)); finally Free end end; То в свойство компонента прописывается путь к директории, где он лежит. Но, мне нужно просто выделит директорию и все. Мне не нужно искать и выделять файл. Как в этом случае поступить. По второму вопросу: Я хочу просто показать диалог (свою форму) с информацией о компонента. Как изменить выше приведенный код в этом случае? Если Set?????Value не нужно, то что нужно указать? Спасибо. |
Сообщ.
#5
,
|
|
|
Первый вопрос решил заменив ЕOpenDialog на TFolderDialog.
а вот воторой вопрос не получается решить. Нужно просто показать форму-диалог "О компоненте". Как это сделать корректно? Спасибо |
Сообщ.
#6
,
|
|
|
1. С помощью OpenDialod нельзя выбрать папку, используйте SelectDirectory или SHBrowseForFolder.
2. Ничего не нужно указывать, вы же ничего не присваиваете свойству. procedure TAboutDlgProperty.Edit; begin with TAboutForm.Create(nil) do try ShowModal finally Free; end; end; |
Сообщ.
#7
,
|
|
|
Не получается вызвать форму-диалог About.
Нет в свойстве кнопки с тремя точками. Привожу код вцелом: unit AboutDlg; interface uses Windows, Messages, SysUtils, Variants, DesignIntf, Classes, Forms, DesignEditors, TypInfo, AboutDlgForm; type TAboutDlgProperty = class(TStringProperty) public function GetAttributes: TPropertyAttributes; override; procedure Edit; override; end; implementation function TAboutDlgProperty.GetAttributes: TPropertyAttributes; begin Result := [paDialog] end; procedure TAboutDlgProperty.Edit; begin with TAboutForm.Create(nil) do try ShowModal finally Free; end; end; procedure Register; begin RegisterPropertyEditor(TypeInfo(String), TMyComponent, 'About', TAboutDlgProperty) end; end. Где ошибка? Спасибо. |
Сообщ.
#8
,
|
|
|
А где объявление свойства ?
|
Сообщ.
#9
,
|
|
|
пробовал и так
property About : Integer read FAbout write FAbout; в свойстве ноль, кнопка с тремя точками отсутствует и так property About : String read FAbout write FAbout; кнопка есть, но открывается редактор строки? a не моя форма AboutForm. Может надо как-то иначе? Спасибо |
Сообщ.
#10
,
|
|
|
property About: string read fAbout write SetAbout; procedure SetAbout; begin // ничего не делаем end; RegisterPropertyEditor(TypeInfo(string), TMyComponent, 'About', TAboutDlgProperty) |
Сообщ.
#11
,
|
|
|
При такой конструкции есть кнопка с тремя точками в свойстве, но после ее нажатия получаем не мое окно About, а окно String-Edit.
Как изменить ситуацию? Спасибо |
Сообщ.
#12
,
|
|
|
У редактора String нет дополнительного окна редактирования, что то вы путаете.
TMyComponent = class(TComponent) private fAbout: string; procedure SetAbout(const Value: string); published property About: string read fAbout write SetAbout; end; TAboutDlgProperty = class(TStringProperty) public function GetAttributes: TPropertyAttributes; override; procedure Edit; override; end; implementation procedure Register; begin RegisterComponents('Standard', [TMyComponent]); RegisterPropertyEditor(TypeInfo(String), TMyComponent, 'About', TAboutDlgProperty) end; procedure TMyComponent.SetAbout(const Value: string); begin end; { TAboutDlgProperty } function TAboutDlgProperty.GetAttributes: TPropertyAttributes; begin Result := [paDialog]; end; procedure TAboutDlgProperty.Edit; begin with TForm.Create(nil) do try ShowModal finally Free; end; end; end. |
Сообщ.
#13
,
|
|
|
Доброе утро!
Я так и сделал, точно по Вашему последнему коду, но у меня появляется вот такое диалоговое окно как Вы можете видеть в аттач. У меня Delphi 2010. Может в этом проблема? Подскажите, Мастера, как все же можно вызвать просто свою собственную форму. Спасибо. Прикреплённый файлpropert_editor.jpg (26,96 Кбайт, скачиваний: 540) |
Сообщ.
#14
,
|
|
|
Сообщ.
#15
,
|
|
|
Думается мне, что процедуру Register нужно либо самому явно вызывать в initialization модуля, либо хотя бы объявить в interface
|
Сообщ.
#16
,
|
|
|
Покажите весь код модуля с формой и регистрацией
|
Сообщ.
#17
,
|
|
|
с процедурой Register все нормально. вызывается где положено. а выскакивает окно редакторования строки. Почему?
Спасибо |
Сообщ.
#18
,
|
|
|
сейчас должен ехать в институт, вечером выложу. спасибо. просто магия какая-то с этим окном.
|
Сообщ.
#19
,
|
|
|
все получилось, виной модуль стороннего компонента был. спасибо.
|