AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Probleme mit Custom Propertyeditor für ComboBox
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit Custom Propertyeditor für ComboBox

Ein Thema von Neutral General · begonnen am 16. Jun 2014 · letzter Beitrag vom 17. Jun 2014
 
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

AW: Probleme mit Custom Propertyeditor für ComboBox

  Alt 16. Jun 2014, 14: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 14:24 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:27 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz