Hi!
Indeed.
Alle visuellen Komponenten haben left,top,width,height.
Die kann man einzeln setzen.
Oder mit setBounds bzw. setSize mehrere auf einmal.
Winni
Code: Alles auswählen
TRect = packed
record
......
public
property Height: Longint read getHeight write setHeight;
property Width : Longint read getWidth write setWidth;
property Size : TSize read getSize write setSize;
property Location : TPoint read getLocation write setLocation;
case Longint of
0: (Left,Top,Right,Bottom : Longint);
1: (TopLeft,BottomRight : TPoint);
2: (Vector:TArray4IntegerType);
end;
end;
Code: Alles auswählen
type
TMyDingen = class
private
fFrameSize : integer;
fSize : TRect;
function GetInnerframe : TRect;
function SetInnerframe(const Value : Trect);
public
property Innerframe : TRect read GetInnerframe write SetInnerframe;
end;
function TMyDingen.GetInnerframe : TRect;
begin
with Result do
begin
Left := fSize.Left + fFrameSize;
Top := fSize.Top + fFrameSize;
Right := fSize.Right - fFrameSize;
Bottom := fSize.Bottom - fFrameSize;
end;
end;
procedure TMyDingen.SetInnerframe(const Value : TRect);
begin
with Value do
begin
fSize.Left := Left - fFrameSize;
fSize.Top := Top - fFrameSize;
fSize.Right := Right + fFrameSize;
fSize.Bottom := Bottom + fFrameSize;
end;
end;
Du hast nicht richt richtig gelesen:
Code: Alles auswählen
program tproptest;
{$mode objfpc}{$H+}
uses
Types;
type
TTest = class
private
FRect: TRect;
function GetRect: TRect;
public
property Rect1: TRect read GetRect;
property Rect2: TRect read FRect;
end;
function TTest.GetRect: TRect;
begin
Result := FRect;
end;
var
t: TTest;
p: PLongInt;
begin
t := TTest.Create;
try
p := @t.Rect1; // Error: Variable identifier expected
p := @t.Rect2; // ok
finally
t.Free;
end;
end.
Code: Alles auswählen
procedure Foo;
type
PRect = ^TRect;
begin
PRect(@SomeObj.Rect)^.Top := 42;
end;
Code: Alles auswählen
TTest = class
FInternalMemory: Array of Array of Byte;
FSize: TPoint;
procedure SetSize(const AValue: TPoint);
...
property Size: TPoint read FSize write SetSize;
...
procedure TTest.SetSize(const AValue: TPoint);
begin
SetLength(FInternalMemory, AValue.X, AValue.Y);
FSize := AValue;
end;
Winni hat ja nicht mal wirklich OOP ausgetrickst. Das man die addresse von Properties holen kann ist ein Feature. Das ist zwar natürlich kaputtes design, aber dank delphi kompatibilität ist kaputtes design auch ein feature im FPC.
Du hast natürlich recht, dass hier auch Ungereimtheiten auf tieferer Ebene vorliegen.
Dazu hätte ich gern mal eine Definition, wo OOP anfängt. Bei manchen ist OOP ja schon, wenn man paar Variablen in ein Record packt und das weiterreicht. Bei anderen darf kein Programmablauf mehr erkennbar sein.