![]() |
Re: boolean ohne variable?
Es gibt schon Fälle wo es nett ist:
Delphi-Quellcode:
Und schon kann ich ganz elegant auf die einzelnene Anteile einer Farbe zuweisen :stupid:
type
TmyColor = record case boolean of true : (Color : TColor); false : (ColorR : Byte; ColorG : Byte; ColorB : Byte;) end; procedure TForm1.Button1Click(Sender: TObject); var myColor : TmyColor; begin myColor.Color := clLime; Label1.Caption := 'Rotanteil : ' + IntToStr(mycolor.ColorR); Label2.Caption := 'Grünanteil : ' + IntToStr(mycolor.ColorG); Label3.Caption := 'Blauanteil : ' + IntToStr(mycolor.ColorB); end; |
Re: boolean ohne variable?
Oder eine matrix, die man über feldnamen oder array-adressierung ansprechen will:
Delphi-Quellcode:
Also, nix da 'finger weg' ...wenn man weiß was man tut.
TD3DMatrix = packed record
case Integer of 0 : (_00, _01, _02, _03, _10, _11, _12, _13, _20, _21, _22, _23, _30, _31, _32, _33 : Single); 1 : (m : array [0..3, 0..3] of Single); end; |
Re: boolean ohne variable?
Zitat:
|
Re: boolean ohne variable?
Zitat:
Delphi-Quellcode:
type
TTest = record case Variable: Typ of // Gleich hier, statt davor (verdeutlicht besser die Bedeutung von 'Variable') Wert1: ( a: Typa; // Semilkolon b: Typb); Wert2: ( x: Typx; y: Typy); { end; } // unnötig, da variante Member ohnehin nur am Ende erlaubt end; |
Re: boolean ohne variable?
man könnte es auch einsetzen, um geziehlt bitmanipulation zu betrieben:
Delphi-Quellcode:
:mrgreen:
type
TFlags = record case boolean of TRUE: (Flags: Byte); FALSE: (F1, F2, F3, F4, F5, F6, F7: Boolean;) end; damit kann man beliebigs bits im byte ändern, aber auch das ganze byte mit einem wisch aus/einlesen stefan |
Re: boolean ohne variable?
Zitat:
(Bitte erst Testen, bevor man wilde Behauptungen aufstellt...) |
Re: boolean ohne variable?
Na ja, bei FreePascal könnte es so gehen (wenn ich mich richtig erinnere).
Da gibts sowas wie
Delphi-Quellcode:
Hab aber leider den FPC grad nicht zur Hand, kanns also nicht testen,
type TPackedBool = packed Array[0..7] of Boolean;
Ist außerdem eh ein andres Thema ;) |
Re: boolean ohne variable?
Zitat:
|
Re: boolean ohne variable?
Zitat:
Zitat:
Zitat:
da hast dich aber schnell rausgeredet :P :mrgreen: |
Re: boolean ohne variable?
Zitat:
Bzw., wer soll das verstehen ? Sagen wir mal nach 1 Jahr ? :shock: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:00 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz