Autor Beitrag
DXC
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Di 06.09.05 15:13 
Hallo,

also ich habe auf meiner Form mehrere Bilder. Jedesmal wenn ich auf einen button drücke soll sich irgendein ZUFÄLLIGES ausblenden (visible := False...). Keinen Peil wie ich dass machen soll...

Hab mal als random funktion das da gedacht...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function RandomRange(min, max: integer): integer;
begin
  result := 0;
  if min > max then
    exit;
  result := random(max - min + 1) + min;
end;


Nur dann... dann hab ich ne zahl gehabt und jetzt?

Image + RandomRange(1, 3).Visible := False (... wenn ich jetzt drei bilder hätte, also image1, image2, image3)?

Funktioniert aber leider nicht

Würd mich über jede Antwort freun

MFG
DXC
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Di 06.09.05 15:24 
hab hier grad mal was aus meinem code rauskopiert...
ich denke/hoffe es erklärt sich von selbst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.zufallsFarben(number:integer);
var img : Timage;
    randomNr,i:integer;
begin
 for i := 89 to 88+number do
  begin
  img := TImage(FindComponent('image' + inttostr(i)));
   if img <> nil then
   begin
    randomNr:=random(3)+1;
    img.Picture.Bitmap.LoadFromFile('skins\standard\color'+intToStr(randomNr)+'.bmp');
    img.Hint:=intToStr(randomNr);
   end;
  end;
end;
gin2309
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98; Win XP
D5 Prof, D7 Prof
BeitragVerfasst: Di 06.09.05 15:25 
Nimm die zufällig erstellte Zahl doch für eine case Anweisung:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
case result of
  1: Image1.visible:=false;
  2: Image2.visible:=false;
  3: Image3.visible:=false;
end;


Mfg Gino

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Di 06.09.05 15:26 
ja das geht auch...aber wenn man das ganze aber mit etlichen bildern machen will, ist es nicht so gut
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Di 06.09.05 15:58 
? :oops:
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Di 06.09.05 16:07 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.RandomRange(min, max: integer);
var img : Timage;
    randomNr:integer;
begin
  randomNr:=random(max-min)+min;
  img := TImage(FindComponent('image' + inttostr(randomNr)));
   if img <> nil then
   img.visible:=false;
end;


habs nich getestet.
ebs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 213

Suse Linux 9.2, Win 98, Win NT, Win XP, Win for Workgroups, Win XP SP2, Dos 6.1
D3 Prof, D2005 PE, Delphi 2006 Prof.
BeitragVerfasst: Di 06.09.05 16:08 
Hallo!
Wenn du weist, wieviele Bilder du hast ist das so kein Problem.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.VisibleImage;
const Anzahl: Integer; //Anzahl der Bilder
var ImageL : Array[0..Anzahl) of TImage // Ich würde es über ein Array machen :!:
begin
ImageL[0] := Image1;
ImageL[1] := Image2;
ImageL[2] := Image3;
//.
//.
//.
ImageL[random(Anzahl)].visible := true;
end;


Für Fragenstehe ich gerne zur :evil: verfügzung :evil:
:D

//Edit Stimmt, wenn man mehrere hat, dann ist deine besser ;)


Zuletzt bearbeitet von ebs am Di 06.09.05 16:11, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 06.09.05 16:10 
Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT(); ist hierfür die beste Lösung.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Di 06.09.05 18:01 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage; :? 
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    Image19: TImage;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    Image23: TImage;
    Image24: TImage;
    Image25: TImage;
    Image26: TImage;
    Image27: TImage;
    Image28: TImage;
    Image29: TImage;
    Image30: TImage;
    Image31: TImage;
    Image32: TImage;
    Image33: TImage;
    Image34: TImage;
    Image35: TImage;
    Image36: TImage;
    Image37: TImage;
    Image38: TImage;
    Image39: TImage;
    Image40: TImage;
    Image41: TImage;
    Image42: TImage;
    Image43: TImage;
    Image44: TImage;
    Image45: TImage;
    Image46: TImage;
    Image47: TImage;
    Image48: TImage;
    Image49: TImage;
    Image50: TImage;
    Image51: TImage;
    Image52: TImage;
    Image53: TImage;
    Image54: TImage;
    Image55: TImage;
    Image56: TImage;
    Image57: TImage;
    Image58: TImage;
    Image59: TImage;
    Image60: TImage;
    Image61: TImage;
    Image62: TImage;
    Image63: TImage;
    Image64: TImage;
    Image65: TImage;
    Image66: TImage;
    Image67: TImage;
    Image68: TImage;
    Image69: TImage;
    Image70: TImage;
    Image71: TImage;
    Image72: TImage;
    Image73: TImage;
    Image74: TImage;
    Image75: TImage;
    Image76: TImage;
    Image77: TImage;
    Image78: TImage;
    Image79: TImage;
    Image80: TImage;
    Image81: TImage;
    Image82: TImage;
    Image83: TImage;
    Image84: TImage;
    Image85: TImage;
    Image86: TImage;
    Image87: TImage;
    Image88: TImage;
    Image89: TImage;
    Image90: TImage;
    Image91: TImage;
    Image92: TImage;
    Image93: TImage;
    Image94: TImage;
    Image95: TImage;
    Image96: TImage;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Button1: TButton;
    function TForm1.RandomRange(min, max: integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.RandomRange(min, max: integer);
var img : Timage;
    randomNr:integer;
begin
  randomNr:=random(max-min)+min;
  img := TImage(FindComponent('image' + inttostr(randomNr)));
   if img <> nil then
   img.visible:=false;
end;

end.


Urgs...

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
---------------------------
Fehler
---------------------------
'=' erwartet, aber '(' gefunden.
---------------------------
OK   
---------------------------


:gruebel: :?

MFG
DXC
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Di 06.09.05 20:01 
wo kommt der fehler denn?
welche zeile?
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Di 06.09.05 21:21 
Es kommt so eine Fehlermeldung:

---------------------------
Fehler
---------------------------
'=' erwartet, aber '(' gefunden.
---------------------------
OK
---------------------------

MFG
DXC
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Di 06.09.05 21:41 
function verlangt eine rückgabe.
ich hab oben auch procedure geschrieben
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Di 06.09.05 22:24 
So?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image7: TImage;
    Image8: TImage;
    Image9: TImage;
    Image10: TImage;
    Image11: TImage;
    Image12: TImage;
    Image13: TImage;
    Image14: TImage;
    Image15: TImage;
    Image16: TImage;
    Image17: TImage;
    Image18: TImage;
    Image19: TImage;
    Image20: TImage;
    Image21: TImage;
    Image22: TImage;
    Image23: TImage;
    Image24: TImage;
    Image25: TImage;
    Image26: TImage;
    Image27: TImage;
    Image28: TImage;
    Image29: TImage;
    Image30: TImage;
    Image31: TImage;
    Image32: TImage;
    Image33: TImage;
    Image34: TImage;
    Image35: TImage;
    Image36: TImage;
    Image37: TImage;
    Image38: TImage;
    Image39: TImage;
    Image40: TImage;
    Image41: TImage;
    Image42: TImage;
    Image43: TImage;
    Image44: TImage;
    Image45: TImage;
    Image46: TImage;
    Image47: TImage;
    Image48: TImage;
    Image49: TImage;
    Image50: TImage;
    Image51: TImage;
    Image52: TImage;
    Image53: TImage;
    Image54: TImage;
    Image55: TImage;
    Image56: TImage;
    Image57: TImage;
    Image58: TImage;
    Image59: TImage;
    Image60: TImage;
    Image61: TImage;
    Image62: TImage;
    Image63: TImage;
    Image64: TImage;
    Image65: TImage;
    Image66: TImage;
    Image67: TImage;
    Image68: TImage;
    Image69: TImage;
    Image70: TImage;
    Image71: TImage;
    Image72: TImage;
    Image73: TImage;
    Image74: TImage;
    Image75: TImage;
    Image76: TImage;
    Image77: TImage;
    Image78: TImage;
    Image79: TImage;
    Image80: TImage;
    Image81: TImage;
    Image82: TImage;
    Image83: TImage;
    Image84: TImage;
    Image85: TImage;
    Image86: TImage;
    Image87: TImage;
    Image88: TImage;
    Image89: TImage;
    Image90: TImage;
    Image91: TImage;
    Image92: TImage;
    Image93: TImage;
    Image94: TImage;
    Image95: TImage;
    Image96: TImage;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Button1: TButton;
    procedure TForm1.RandomRange(min, max: integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RandomRange(min, max: integer);
var img : Timage;
    randomNr:integer;
begin
  randomNr:=random(max-min)+min;
  img := TImage(FindComponent('image' + inttostr(randomNr)));
   if img <> nil then
   img.visible:=false;
end;

end.


Funtktioniert auch net...
Kommt der selbe fehler...

MFG
DXC
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 07.09.05 07:09 
In welcher Zeile denn?
Da steht bei den Compiler-Meldungen eine Zeile dran.
Sonst können wir dir schlecht helfen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Mi 07.09.05 08:35 
... in zeile 116 kommt der Fehler aber Comilier mariert sie nur so rot und dann kommt so ein fenster mit dem Fehler...

MFG
DXC
en!gma
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 378

win xp
delphi 7.0
BeitragVerfasst: Mi 07.09.05 09:02 
mach bei zeile 116 mal das TForm1. davor weg