Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.199 Beiträge
 
Delphi 12 Athens
 
#17

AW: Wie erfahre ich, auf welche Zeile im Stringgrid geklickt wurde?

  Alt 29. Okt 2021, 22:19
Beispiel TRect.

früher ging sowas wie
Delphi-Quellcode:
with MyRect do begin
  Width := Right - Left;
  Height := Bottom - Top;
Um die Größe einer Form zu setzen (z.B. im OnCreate), und jetzt wunderst du dich, dass scheinbar garnichts mehr passiert, obwohl der Compiler sagt "alles OK", weil
Delphi-Quellcode:
with MyRect do begin
  Self.Width := Right - Left;
  Self.Height := Bottom - Top;

// oder
Self.Width := MyRect.Right - MyRect.Left;
Self.Height := MyRect.Bottom - MyRect.Top;
dir zu lang war.


alt
Delphi-Quellcode:
  TRect = record
  case Integer of
    0: (Left, Top, Right, Bottom: FixedInt);
    1: (TopLeft, BottomRight: TPoint);
  end;
neu (Auszug, weil knapp 100 Zeilen)
Delphi-Quellcode:
  TRect = record
  private
    ...
  public
    ...
    property Width: Integer read GetWidth write SetWidth;
    property Height: Integer read GetHeight write SetHeight;

  case Integer of
    0: (Left, Top, Right, Bottom: FixedInt);
    1: (TopLeft, BottomRight: TPoint);
  end;

seit 10.4 (10.3) darf man gern Inline-Variablen verwenden
Delphi-Quellcode:
var R := MyRect; // mitten im Code, also "inline"
Width := R.Right - R.Left;
Height := R.Bottom - R.Top;
wobei ich in diesem Fall eher "absolute" verwenden würde, wenn mir "MyRect" zu lang ist.
Delphi-Quellcode:
var
  R: TRect absolute MyRect;
begin
  Width := R.Right - R.Left;
  Height := R.Bottom - R.Top;
Aber da ich faul bin, mach ich natürlich
Delphi-Quellcode:
Width := MyRect.Width;
Height := MyRect.Height;

// oder
Self.Width := MyRect.Width;
Self.Height := MyRect.Height;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (29. Okt 2021 um 22:25 Uhr)
  Mit Zitat antworten Zitat