Autor Beitrag
GR-Thunderstorm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Fr 05.05.06 14:55 
Hi Leutz!
Hab vor kurzem erst mit Delphi angefangen und hab jetzt mal ne ziemlich dumme Frage...
Ich will erreichen, dass wenn ich eine bestimmte Taste drücke, sich mein Bild durch ein anderes auswechselt.
Ich hab alle Bilder in eine ImageList geladen und will nun je nach Taste, dass mein Bild zu einem der Bilder in der Liste wird.
Hab folgendes schon probiert:


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
if key:="d" then
begin
image1.picture:=imagelist.2{will dass das image1 zum 2. Bild aus der ImageList wird}
end;
end.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
if key:="d" then
begin
image1.picture:=C:\(...)\Bild2.bmp;
end;
end.


Beides funktioniert leider nicht... :(

Kann mir einer sagen wo der Fehler liegt?
DANKE!

Moderiert von user profile iconGausi: I- durch Delphi-Tags ersetzt


Zuletzt bearbeitet von GR-Thunderstorm am Fr 05.05.06 14:58, insgesamt 1-mal bearbeitet
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Fr 05.05.06 14:58 
hallo,
ich würde dir raten, die grundlagen von delphi nocheinmal durchzugehen.

verglichen wird in delphi nämlich mit dem '=' operator!

daher sollte dein code nun so aussehen: if key = 'd' then ...

mfg ;)
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Fr 05.05.06 15:11 
Ja sry hab mich da jetzt verschrieben, ich meinte ja eigentlich if key = 'd' then.... :roll:

Wenn ich das mit der Imagelist mache sagt er Identifier expected but number found und er springt an diese Stelle:

Zitat:
image.picture:=imagelist1.2|;


Wenn ich es mit der direkten Pfadangabe versuche sagt er mir Undeclared Identifier: 'C'.
Wenn ich den ganzen Pfad in Hochkommata setze sagt er: Incompatible types: 'TPicture' and 'String'
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Fr 05.05.06 15:24 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key ='d' then
  ImageList1.GetBitmap(0, Image1.Picture.Bitmap);
  if key ='f' then
  Image1.Picture.LoadFromFile('C:\Bild.bmp');
end;
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Fr 05.05.06 15:27 
du musst das bild entweder so

ImageList1.GetBitmap(2,Image1.Picture.Bitmap);

oder so laden

Image1.Picture.LoadfromFile('C:\...Bild2.bmp');


Xion

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: Fr 05.05.06 15:33 
Klappt! DANKE! :D

Eine Sache die mir jetzt auffällt:
Wieso is das Bild welches aus der ImageMap kommt so klein? Und wieso meckert er wenn ich größere Bilder reinmachen will?
MysticMike
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 21



BeitragVerfasst: Sa 06.05.06 16:24 
Hi!

Die Größe stellt du im Objektinspektor unter width und height (von der Imagelist) ein

greetz Mystix