Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Button.Caption "einfrieren"? (https://www.delphipraxis.net/170408-button-caption-einfrieren.html)

R0bin2o11 15. Sep 2012 17:19

Button.Caption "einfrieren"?
 
Hallo liebes Forum,

Gibt es in Delphi einen Befehl, mit dem man die Caption eines Buttons "einfrieren", also dass die Caption "unantastbar" und unter gar keinen Umständen zu ändern ist?

LG Robin

haentschman 15. Sep 2012 17:23

AW: Button.Caption "einfrieren"?
 
Hallo und willkommen in der DP :dp:

Als erstes leider ein Mini Anpfiff. Crossposts bitte in Zukunft gegenseitig verlinken damit Antworten nicht doppelt gegeben werden bzw. ein Forum die Lösung schon hat im anderen noch darüber geschwitzt wird. 8-)

Crosspost: http://www.entwickler-ecke.de/viewtopic.php?t=110218

Zum Thema:
Kannst du dein Anliegen etwas genauer definieren ? Wenn du in deinem Programm die Caption nicht änderst bleibt sie auch so. Oder meinst du von Extern ? Wer sollte so etwas versuchen ?

EWeiss 15. Sep 2012 17:26

AW: Button.Caption "einfrieren"?
 
Zitat:

also dass die Caption "unantastbar" und unter gar keinen Umständen zu ändern ist?
Keinen Befehl.
Aber was hält dich davon ab dieses selbst auf den Button zu zeichnen?

DrawTextToDC


gruss

R0bin2o11 15. Sep 2012 17:33

AW: Button.Caption "einfrieren"?
 
Edit: Ich möchte, dass sobald ein Button die richtige Caption (also die richtige Zahl [1-9]) hat, die Caption nicht mehr von den anderen Buttons geändert werden kann.

Ich gebe euch mal meinen Quellcode... ^^

Delphi-Quellcode:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin
RANDOMIZE;
Button1.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button2Click(Sender: TObject);

begin
RANDOMIZE;
Button2.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button3Click(Sender: TObject);

begin
RANDOMIZE;
Button3.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button4Click(Sender: TObject);

begin
RANDOMIZE;
Button4.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button5Click(Sender: TObject);

begin
RANDOMIZE;
Button5.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button6Click(Sender: TObject);

begin
RANDOMIZE;
Button6.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button7Click(Sender: TObject);

begin
RANDOMIZE;
Button7.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button8Click(Sender: TObject);

begin
RANDOMIZE;
Button8.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Button9Click(Sender: TObject);

begin
RANDOMIZE;
Button9.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin
  if Button1.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button1.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button2.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button3.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button4.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button5.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button6.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
  if Button7.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button8.Caption=Button9.Caption then Button9.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button1.Caption then Button1.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button2.Caption then Button2.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button3.Caption then Button3.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button4.Caption then Button4.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button5.Caption then Button5.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button6.Caption then Button6.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button7.Caption then Button7.Caption:=IntToStr(Random(9)+1);
  if Button9.Caption=Button8.Caption then Button8.Caption:=IntToStr(Random(9)+1);
end;

end.
LG Robin

EWeiss 15. Sep 2012 17:38

AW: Button.Caption "einfrieren"?
 
Dann hab ich da wohl was falsch verstanden..

BOahhh so viele, jedemenge Button. ;)

gruss

haentschman 15. Sep 2012 17:42

AW: Button.Caption "einfrieren"?
 
Ähmmm... ok. :roll:

Versuche mal zu beschreiben (Stichpunkte) wie dein Programm arbeiten soll. Bevor das nicht klar ist, können wir schlecht helfen.

DeddyH 15. Sep 2012 17:48

AW: Button.Caption "einfrieren"?
 
Japp, sehe ich auch so. Dann kann man auch gleich Logik und Darstellung trennen, denn Buttons sind ja nicht dazu da, irgendwelche Daten vorzuhalten, sondern um ein Ereignis auszulösen. Und wenn man doch unbedingt Daten darin verwalten will/muss, eignet sich die Tag-Eigenschaft wohl eher dazu, zumal sie auch noch zufällig nummerisch ist.

Uwe Raabe 15. Sep 2012 17:57

AW: Button.Caption "einfrieren"?
 
Zitat:

Zitat von R0bin2o11 (Beitrag 1183058)
Edit: Ich möchte, dass sobald ein Button die richtige Caption (also die richtige Zahl [1-9]) hat, die Caption nicht mehr von den anderen Buttons geändert werden kann.

Was ist denn die "richtige" Zahl für einen Button?

EWeiss 15. Sep 2012 18:01

AW: Button.Caption "einfrieren"?
 
Zitat:

Zitat von Uwe Raabe (Beitrag 1183066)
Zitat:

Zitat von R0bin2o11 (Beitrag 1183058)
Edit: Ich möchte, dass sobald ein Button die richtige Caption (also die richtige Zahl [1-9]) hat, die Caption nicht mehr von den anderen Buttons geändert werden kann.

Was ist denn die "richtige" Zahl für einen Button?

Denke mal das soll eine art Slottmachine sein.
Wobei wenn eine zahl zwischen 1 und 9 auftritt diese nicht mehr geändert werden soll.

Nur geraten.

gruss

Uwe Raabe 15. Sep 2012 20:13

AW: Button.Caption "einfrieren"?
 
Zitat:

Zitat von EWeiss (Beitrag 1183068)
Wobei wenn eine zahl zwischen 1 und 9 auftritt diese nicht mehr geändert werden soll.

Hmmm, was könnte bei
Delphi-Quellcode:
Random(9)+1
wohl an Zahlen herauskommen...


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:02 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz