Autor Beitrag
Peter18
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Sa 13.08.11 13:45 
Ein freundliches Hallo an alle,

ich habe eine Komponente von TEdit abgeleitet und ein Label hinzugefügt. Wenn ich diese Komponente dann per Drag&Drop bewege, nehme ich sie als TWinControl und setze "Top" und "Left" neu. Dann werden jedoch nicht meine Property-Routinen aufgerufen, sondern andere von TWinControl. (Work around: T_Edit(Sender).Top funktioniert, ist aber unschön)

Gibt es eine Möglichkeit von TEdit abzuleiten und die TWinControl-Routinen zu überschreiben oder muß ich von TWinControl ableiten??

Danke im Voraus
Peter
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 13:53 
Du hast aber SetBounds überschrieben um die Änderungen mitzubekommen?

// EDIT:
Siehe Quelltext von TWinControl:
ausblenden Delphi-Quelltext
1:
2:
  public
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
Peter18 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Sa 13.08.11 14:21 
Hallo jaenicke,

Danke für Deine Antwort. "SetBounds" habe ich nicht überschrieben. Wann wird sie denn aufgerufen?

Grüße Peter
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 14:25 
Immer, wenn Top, Left, Width oder Height geändert wird. Ich sehe aber gerade, das du noch ein aktikes Delphi hast, da gab es das vielleicht noch nicht. Da musst du mal schauen was beim Setzen der Eigenschaft in TWinControl passiert. :nixweiss:

Bei mir in XE sieht das so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TControl.SetTop(Value: Integer);
begin
  SetBounds(FLeft, Value, FWidth, FHeight);
  [...]
end;
Peter18 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Sa 13.08.11 14:36 
Hallo jaenicke,

noch mal Danke für die schnelle Antwort.

Ich habe die Komponente von TEdit abgeleitet. Wie komme ich den dann an "TWinControl" heran?
ausblenden Delphi-Quelltext
1:
2:
type
  T_Edit = class(TEdit)


Grüße Peter
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 15:02 
Habe ich doch schon geschrieben, einfach überschreiben.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  TExtendedEdit = class(TEdit)
  public
    procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  end;
Das funktioniert auch schon in Delphi 3 so.
Peter18 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Sa 13.08.11 15:24 
Hallo jaenicke,

danke, hatte es auch probiert, aber dummer Weise unter "private" eingetragen.

Nun bekomme ich aber einen Stacküberlauf, weil Die Routine beim setzen der Werte auch aufgerufen wird.
Was mache ich falsch??

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure T_Edit.Setbounds(ALeft, ATop, AWidth, AHeight: Integer); 
begin
  if ATop >= 16 then
  begin
    inherited Top     := ATop;
              Lbl.Top := ATop -16;
  end;
  inherited Left     := ALeft;
            Lbl.Left := ALeft;
  inherited Width    := AWidth;
  inherited Height   := AHeight;
end;


Grüße Peter
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 13.08.11 15:26 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure T_Edit.Setbounds(ALeft, ATop, AWidth, AHeight: Integer); 
begin
  inherited;
  if ATop >= 16 then
    Lbl.Top := ATop -16;
  Lbl.Left := ALeft;
end;
// EDIT:
Sieht ja fast aus als ob du dir das TLabeledEdit von Delphi 7+ nachbauen willst. :mrgreen:

Was machst du denn mit Lbl.Top, wenn ATop < 16? Undefiniert? :D
Peter18 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 489
Erhaltene Danke: 2


Delphi4
BeitragVerfasst: Sa 13.08.11 17:36 
Hallo jaenicke,

kann sein. Es soll ein TEdit mit Label sein. Die Abfrage ist zum Testen erst mal "hart verdratet" später wird es genauer geprüft und sichergestellt, dass das Objekt nicht über Parent hinausgeht (wenn möglich).

Hatte noch ein paar Schwierigkeiten mit dem rekursiven Aufruf, das Ding hat sich verkrümelt, weil bei T_Edit.Top=0 Label.Top=0 sein soll und Edit.Top=16. Aber nun funktioniert es, Danke!!

Grüße Peter