Einzelnen Beitrag anzeigen

jbg

Registriert seit: 12. Jun 2002
3.481 Beiträge
 
Delphi 10.1 Berlin Professional
 
#4

Re: JvInspector: "Enum-Item" hinzufügen

  Alt 14. Aug 2005, 18:06
Zitat von Basic-Master:
das New() in meiner Funktion ist notwendig
Ob es notwendig ist, habe ich nicht gefragt, sondern ob du dich auch wieder um das Freigeben des Speichers kümmerst, oder ein Speicherleck hast.

Zitat:
Ich suche im Moment leider eher eine Möglichkeit, Strings wie "||" und "&&" [im Style einer ComboBox; wie eben Enums] hinzuzufügen
Das hättest du vielleicht auch mal oben erwähnen können. (Hellsehen ist nicht meine stärke)

Delphi-Quellcode:
type
  TSelectionTextList = class(TStringList)
  private
    FSelected: Integer;
    function GetSelectedText: string;
    function GetSelected: Integer;
    procedure SetSelectedText(const Value: string);
    procedure SetSelected(const Value: Integer);
  public
    property Selected: Integer read GetSelected write SetSelected;
    property SelectedText: string read GetSelectedText write SetSelectedText;
  end;

  TJvInspectorSelectionTextListItem = class(TJvCustomInspectorItem)
  protected
    function GetDisplayValue: string; override;
    procedure GetValueList(const Strings: TStrings); override;
    procedure SetDisplayValue(const Value: string); override;
    procedure SetFlags(const Value: TInspectorItemFlags); override;
  end;

{ TSelectionTextList }

function TSelectionTextList.GetSelected: Integer;
begin
  if FSelected < -1 then
    FSelected := -1
  else if FSelected >= Count then
    FSelected := Count - 1;
  Result := FSelected;
end;

function TSelectionTextList.GetSelectedText: string;
begin
  if Selected >= 0 then
    Result := Strings[Selected]
  else
    Result := '';
end;

procedure TSelectionTextList.SetSelected(const Value: Integer);
begin
  FSelected := Value;
  GetSelected; // adjust FSelected
end;

procedure TSelectionTextList.SetSelectedText(const Value: string);
begin
  FSelected := IndexOf(Value);
end;

{ TJvInspectorSelectionTextListItem }

function TJvInspectorSelectionTextListItem.GetDisplayValue: string;
begin
  Result := TSelectionTextList(Data.AsOrdinal).SelectedText;
end;

procedure TJvInspectorSelectionTextListItem.GetValueList(const Strings: TStrings);
begin
  Strings.Assign(TSelectionTextList(Data.AsOrdinal));
end;

procedure TJvInspectorSelectionTextListItem.SetDisplayValue(const Value: string);
begin
  TSelectionTextList(Data.AsOrdinal).SelectedText := Value;
end;

procedure TJvInspectorSelectionTextListItem.SetFlags(const Value: TInspectorItemFlags);
begin
  inherited SetFlags(Value + [iifValueList]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FMyList := TSelectionTextList.Create;
  FMyList.Add('Blau');
  FMyList.Add('Grün');
  FMyList.Add('Weiß');
  FMyList.Add('Gelb');

  TJvCustomInspectorData.ItemRegister.Add(TJvInspectorTypeInfoRegItem.Create(TJvInspectorSelectionTextListItem, TypeInfo(TSelectionTextList)));

  TJvInspectorVarData.New(JvInspector1.Root, 'MyList', TypeInfo(TSelectionTextList), @FMyList);
end;

...
  Mit Zitat antworten Zitat