Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: Probleme mit Custom Propertyeditor für ComboBox
16. Jun 2014, 15:21
Ich hab mal ganz grob (die in meinen Augen) wichtigsten Codestellen rausgesucht:
Delphi-Quellcode:
type
TMyComboBoxStrings = class(TCustomComboBoxStrings)
private
FMapValues: TList<TValue>;
public
function AddMapped(const S: String; AValue: TValue): Integer;
// ..
end;
TMyComboBox = class(TComboBox)
protected
function GetItemsClass: TCustomComboBoxStringsClass; override;
procedure DefineProperties(Filer: TFiler); override;
procedure ReadMapList(Stream: TStream);
procedure WriteMapList(Stream: TStream);
end;
implementation
function TMyComboBox.GetItemsClass: TCustomComboBoxStringsClass;
begin
Result := TMyComboBoxStrings;
end;
procedure TMyComboBox.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineBinaryProperty('MappedValues',ReadMapList, WriteMapList, Items.Count > 0);
end;
Property-Editor:
Delphi-Quellcode:
// Form was beim Klick auf "..." im Propertyeditor aufgerufen wird
TMyComboBoxItemEditForm = class(TForm)
// ...
end;
TMyComboBoxItemEditor = class(TPropertyEditor)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: String; override;
end;
implementation
procedure TMyComboBoxItemEditor.Edit;
var tmpForm: TMyComboBoxItemEditForm;
tmpStrings: TMyComboBoxStrings;
begin
inherited;
tmpStrings := TMyComboBoxStrings(GetOrdValue);
if Assigned(tmpStrings) then
begin
tmpForm := TMyComboBoxItemEditForm.Create(Application, TMyComboBox(GetComponent(0)), tmpStrings);
try
if tmpForm.ShowModal = mrOK then
begin
SetOrdValue(Integer(tmpForm.GetResultList()));
Modified;
end;
finally
tmpForm.Free;
end;
end;
end;
function TMyComboBoxItemEditor.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;
function TMyComboBoxItemEditor.GetValue: String;
begin
if GetOrdValue <> 0 then
Result := '<' + TObject(GetOrdValue).ClassName + '>'
else
Result := '-';
end;
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TStrings), TMyComboBox, '', TMyComboBoxItemEditor);
end;
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
Geändert von Neutral General (16. Jun 2014 um 15:24 Uhr)
|