Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 23.08.06 00:54 
Hallo,

Ich möchte das Property BoundsRect von TForm überschreiben, weil da noch Berechnungen rein müssen. Das geht auch soweit, aber leider nur solange wie die Variable direkt als TMyForm deklariert ist. Ich habe eine Funktion, die TCustomForm als Parameter hat, un die verwendet dann das alte Property von TCustomForm bzw. TControl.
Das ist in soweit schlecht, als dass das Fenster an einer völlig falschen Stelle auftaucht.

Wenn das eine Methode wäre, würde ein override; doch dafür sorgen, dass immer die wirkliche Methode aufgerufen wird.
Es ist also das Problem verdecken/überschreiben.

Gibt es sowas auch für properties? Und wenn nicht, wie könnte ich das dann lösen?
Ich könnte theoretisch die Methode ändern, die das benutzt, aber nur äußerst ungern, da ich dann die komplette Flexibilität verlieren würde.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 23.08.06 01:06 
Zeig mal den Source der Methode, die die TCustomForm bekommt.

Zeig mal außerdem bitte kurz das Interface deiner MyForm (Auf die BoundRect betreffenden Zeilen + Abhängige Änderungen begrenzt reicht).

Was Du probieren könntest, ist deinen Get\Set-Handler mit virtual; reintroduce; zu kennzeichnen und unter Protected zu deklarieren ...
Ich kann ggf. auch mal in TCustomForm nachgucken, was die dort machen .... Wenn das Problem aber nur bei einem Aufruf auftritt, kannste dort ggf. abfragen Param IS TMyForm und dort dann explizit auf TMyForm casten ......

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 23.08.06 01:17 
Mach ich glatt:

Interface des neuen Forms:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  private
    { Private-Deklarationen }
    function GetBoundsRect: TRect;
    procedure SetBoundsRect(Value: TRect);
  published
    property BoundsRect : TRect read GetBoundsRect write SetBoundsRect; override
  end;

Implementation (es wird ein Rand hinzugefügt bzw. wieder abgezogen):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function TfmRectChoose.GetBoundsRect: TRect;
begin
  Result:= inherited BoundsRect;
  inc(Result.Top,Border);
  inc(Result.Left,Border);
  dec(Result.Bottom,Border+1);
  dec(Result.Right,Border+1);
end;

procedure TfmRectChoose.SetBoundsRect(Value: TRect);
begin
  dec(Value.Top,Border);
  dec(Value.Left,Border);
  inc(Value.Bottom,Border+1);
  inc(Value.Right,Border+1);
  inherited BoundsRect:= Value;
end;

Benutzt wird es so:
ausblenden Delphi-Quelltext
1:
FScrCam.FFrame.BoundsRect:= FScrCam.ActualCapRect;					

Dabei ist FScrCam.FFrame wie gesagt vom Typ TCustomForm.

Das mit dem Überschreiben der Get/Set wird auch nichts, da Borland diese beiden in TControl netterweise als private deklariert hat.

Und den Typecaste möchte ich auch nicht, da ich die beiden Klassen unabhängig haben möchte und vor allem auch andere Forms zulassen möchte (Wiederverwendbarkeit).


Völlig OT: 100ster Beitrag! :party: :dance: :party:

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 23.08.06 01:49 
IIRC kannst Du auch so Type-Casten: Param as Param.ClassType, dessen endgültiger Typ zwar nicht bekannt ist, aber immer die Laufzeit-Klasse liefern sollte (IMVHO).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 23.08.06 01:57 
Leider nicht, dann sagt der Compiler 'Undefinierter Bezeichner: BoundsRect'. Ich denke mal der nimmt das mit dem TClass=class of TObject so wörtlich, dass er die Möglichkeit des in TObject castens mit einbezieht.

Scheint so, als ob ich um das Verzahnen der Units doch nicht drumrum komme :(

Edit: hmpf, grade bei Google Groups gefunden:
Zitat:

Whether a property is hidden or overridden in a derived class, property
look-up is always static. That is, the declared (compile-time) type of
the variable used to identify an object determines the interpretation
of its property identifiers. Hence, after the following code executes,
reading or assigning a value to MyObject.Value invokes Method1 or
Method2, even though MyObject holds an instance of TDescendant. But you
can cast MyObject to TDescendant to access the descendant class's
properties and their access specifiers.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
type
  TAncestor = class
     ...
    property Value: Integer read Method1 write Method2;
  end;
  TDescendant = class(TAncestor)
     ...
    property Value: Integer read Method3 write Method4;
  end;
var MyObject: TAncestor;
 ...
MyObject := TDescendant.Create

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."