Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi 5 mal klicken (https://www.delphipraxis.net/3018-5-mal-klicken.html)

citybreaker 18. Feb 2003 16:13


5 mal klicken
 
Hallo!

Ich will ein Bild machen, auf
das man 5 mal klicken muss,
damit es verschwindet.
Wie kann man das machen?

cYa Citybreaker :D

NeoDeluxe 18. Feb 2003 16:22

So ganz genau, weiss ich das nicht. Aber du kannst eine Variabele reinschweissen, und bei jedem klick abzählen z.
Code:
procedure Image1.Click...
var
  i:integer
begin
  i:=0
  i:=i+1;
  if i=5 then
    //muss du schreiben was passieren wird wenn man das Bild 5 Mal angeklickt hast
da gibt es bestimmt eine andere methode, ich kenne diese hab auch schon öfter benutzt.

NeoDeluxe 18. Feb 2003 16:24

Mist wie konnte ich nur :wall: , hab ganz vergessen die Semikoliume.
Bitte um Vergebung......... :oops:

janjan 18. Feb 2003 16:30

das wir so in der form nicht klappen, du musst i global definieren und im ImageKlick hochzählen:

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure Image1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  i:Integer=0;
implementation

{$R *.dfm}

procedure TForm1.Image1Click(Sender: TObject);
begin
  i:=i+1;
  form1.Caption:=inttostr(i);
  if i = 5 then image1.Visible:=false;
end;

end.

oki 18. Feb 2003 16:31

Hallo,


NeoDeluxe hat prinzipiell Recht, aber seine lokale variable wird bei jedem Aufruf des OnClick-Ereignisses neu initialisiert!

I muß global definiert werden! Etwa so
Delphi-Quellcode:
TMyObject = class(TObject)
private
  FCount : Integer

.
.
.

 procedure Image1.Click...
begin
  Inc(FCount);
  if FCount=5 then
    //muss du schreiben was passieren wird wenn man das Bild 5 Mal angeklickt hast
  FCount := 0;
Eventuell in der OnCreate-Methode FCount := 0; aufnehmen, aber eigentlich werden die Property's durch das Objekt automatisch instanziiert (Zeiger = nil, Integer = 0 usw.)

Gruß oki

oki 18. Feb 2003 16:33

Und wieder mal nachträglich korrigiert:

Delphi-Quellcode:
  if FCount=5 then begin
    //muss du schreiben was passieren wird wenn man das Bild 5 Mal angeklickt hast
    FCount := 0;
  end;
Gruß oki

sakura 18. Feb 2003 16:33

@NeoDeluxe: lokale Variablen sind dafür nicht brauchbar ;)

Eine Möglichkeit wäre auch den TagWert zu nutzen.
Delphi-Quellcode:
procedure TForm1.ImageOnClick(Sender: TObject);
begin
  if Sender is TImage then
    with TImage(Sender) do
    begin
      Tag := Tag + 1;
      if Tag = 5 then
      begin
        Tag := 0;
        Visible := False;
      end;
    end;
end;
end;
...:cat:...

NeoDeluxe 18. Feb 2003 16:33

jup :oops: , Sorry jetzt weiss ich warum das bei mir manchmal nicht ging!

citybreaker 18. Feb 2003 16:59

Okay!
Danke für die schnellen Antworten.

cYa Citybreaker :D

nailor 18. Feb 2003 17:27

man kann aber auch Tag einfach immer mod 5/6 (je nach dem) nehmen


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:27 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 by Thomas Breitkreuz