Einzelnen Beitrag anzeigen

Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#1

Sender abfragen klappt nicht richtig

  Alt 24. Feb 2014, 19:45
Ich hab einen kleinen Objectinspektor (Siehe Anlage). Die einzelnen Zeilen sind z.B. so aufgebaut.

Delphi-Quellcode:
  TPropComboBox = class(TComboBox)
  private
    Info: TEdit;
    CheckBox: TCheckBox;
    procedure SetTopIndex(const Value: integer);
    procedure SetVisible(const Value: boolean);
  public
    property TopIndex: integer write SetTopIndex;
    property Visible: boolean write SetVisible;
    constructor Create(AOwner: TComponent); override;
  end;

{ TPropComboBox }

constructor TPropComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Info := TEdit.Create(Self);
  CheckBox := TCheckBox.Create(Self);
end;

procedure TPropComboBox.SetTopIndex(const Value: integer);
begin
  Top := (Value - 1) * 25 + 40;
  Info.Top := Top;
  CheckBox.Top := Top;
  TabOrder := Value;
end;

procedure TPropComboBox.SetVisible(const Value: boolean);
begin
  inherited Visible := Value;
  Info.Visible := Value;
end;
Erzeugen tue ich eine Reihe z.B. so:
Delphi-Quellcode:
function TDrawPadProperties.CreateComboBox(const Name, Text: string;
  const Tag: TProp): TPropComboBox;
begin
  Result := TPropComboBox.Create(FOwner);
  Result.Name := NameSubStr + Name + '_Prop';
  Result.Parent := FOwner.Pages[0];
  Result.Visible := false;
  Result.Left := 155;
  Result.Width := 130;
  Result.Style := csOwnerDrawFixed;
  Result.Font.Assign(FFontBlack);
  Result.OnClick := EditExit;
  Result.Tag := Integer(Tag);
  Result.ShowHint := Length(Text) > 20;
  Result.Hint := Text;

  Result.Info.Name := NameSubStr + Name + '_PropInfo';
  Result.Info.Parent := FOwner.Pages[0];
  Result.Info.Left := 20;
  Result.Info.Width := 130;
  Result.Info.ReadOnly := true;
  Result.Info.TabStop := false;
  Result.Info.Font.Assign(FFontInfo);
  Result.Info.Text := Text;

  if not FSimple then
  begin
    Result.CheckBox.Name := NameSubStr + Name + '_MultiProp';
    Result.CheckBox.Parent := FOwner.Pages[0];
    Result.CheckBox.Visible := false;
    Result.CheckBox.Left := 290;
    Result.CheckBox.Width := 20;
    Result.CheckBox.Height := 20;
    Result.CheckBox.Font.Assign(FFontBlack);
    Result.CheckBox.TabStop := false;
    Result.CheckBox.Caption := '';
    Result.CheckBox.OnClick := EditExit;
    Result.CheckBox.Tag := Integer(Tag);
    Result.CheckBox.ShowHint := true;
    Result.CheckBox.Hint := 'Auf alle markierten Objekte anwenden';
  end;
end;
In OnExit (= OnClick für diese Komponente) frage ich den Sender ab. Klappt aber nicht (***)?

Delphi-Quellcode:
function TDrawPadProperties.GetAll(Sender: TObject): integer; // ****
begin
  Result := 0;
  if not FSimple then
  begin
    if Sender is TCheckBox then
      if TCheckBox(Sender).Checked and (Pos('_MultiProp', TControl(Sender).Name) > 0) then
        Result := 1;
    if Result = 0 then
    begin
      if Sender is TPropCheckBox then
        if TPropCheckBox(Sender).CheckBox.Checked then
          Result := 2
        else
          if Sender is TPropEdit then
            if TPropEdit(Sender).CheckBox.Checked then
              Result := 3
            else
              if Sender is TPropComboBox then
                if TPropComboBox(Sender).CheckBox.Checked then
                  Result := 4;
    end;
  end;
  // ShowMessage(TControl(Sender).Name);
end;

procedure TDrawPadProperties.EditExit(Sender: TObject);
var
  All: boolean;
begin
  if FEnabled and Assigned(FOnPropertiesChange) then
  begin
    StoreToStringList(FSL2);
    All := GetAll(Sender) <> 0; // ***
    if All or (not Compare) then
    begin
      FSL1.Assign(FSL2);
      FOnPropertiesChange(TProp(TControl(Sender).Tag), All);
    end;
  end;
end;
Die GetAll reagiert nicht so wie beabsichtigt. Die soll sagen, wenn OnExit (=ComboBoxClick) betätigt wird, ob die abgehängte Checkbox gecheckt ist (liefert Result = 0)?

Im Beispiel habe ich Stiftfarbe auf himmelblau gesetzt. Wie man sieht ist nur ein Object himmelblau dargestellt (sollten aber alle sein weil eben die dazugehörige Checkbox gecheckt ist).
Angehängte Dateien
Dateityp: pdf Props.pdf (956,1 KB, 15x aufgerufen)
  Mit Zitat antworten Zitat