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



BeitragVerfasst: So 21.05.06 10:20 
Hi!
Ist es möglich, dass man durch Variablen einem Programm verschiedene Styles verpassen kann?


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if a = 1 then
Ordner-Variable:=Ordner1;

if a = 2 then
Ordner-Variable:=Ordner2;

image1.picture.loadfromfile('[Ordner-Variable]/Bild.bmp');



Wisst ihr ungefähr was ich meine? Ich will in meinem Spiel mehrere Figuren unterbringen, welche natürlich alle anders aussehen sollen. Statist 1 hat alle Texturen in ordner1, Statist 2 hat alles in ordner2, etc..
Ich will aber nicht für jeden Statisten alles doppelt und dreifach schreiben müssen...

Danke schonmal im Vorraus!
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 21.05.06 10:31 
hey,

ich weiß ehrlich gesagt nicht, wo dein problem ist :roll:
Deklariere Ordner_Variable als String und weiße ihr den Pfad zum Ordner des Bildes zu.

Sieht dann in etwa so, oder so änhlich aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
const a: integer = 1;
var Ordner_Variable: String;
begin
 if a = 1 then
  Ordner_Variable := 'C:\Dokumente und Einstellungen\xxxx\Desktop\Bilder\';

  image1.Picture.LoadFromFile(Ordner_Variable+'1000.bmp');

end;

Hoffe konnt dir weiterhelfen ;)
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 21.05.06 10:32 
ausblenden Delphi-Quelltext
1:
image1.picture.loadfromfile( <Ordner-Variable>+'\Bild.bmp');					

_________________
Markus Kinzler.
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: So 21.05.06 10:48 
LOL da bin ich jetz dann wohl ehr intuitiv drüber gestolpert.. :D
Nur klappen will das leider nicht...

Habs jetzt erstmal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var a:string;
begin

if key = 'a' then
begin
a:='ordner1';
end;

if key = 'b' then
begin
a:='ordner2';
end;

image1.Picture.LoadFromFile(a+'\1.bmp');
end;

end.


Delphi zeigt zwar keine Fehler an, aber passieren tut dabei auch nix..
Die Unit müsste aber eigentlich im richtigen Ordner sein...
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 21.05.06 10:53 
Was geht nicht? Sind die Ordner Unterverzeichnisse des Ordners des Programms?
Dann versuchs mal so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if key = 'a' then
begin
    a:=ExtractFilePath(Application.ExeName)+'ordner1';
end;

_________________
Markus Kinzler.
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: So 21.05.06 11:04 
Wenn ich a oder b drücke passiert nix...

Ich hab dieses "a:=ExtractFilePath(Application.ExeName)+'ordner1';" mal eingefügt, es passiert aber immer noch nix.. :(

Ich hab das ganze mal hochgeladen.

asalenus.fortunecity.../ordnervariablen.zip

Vll bekommt ihr es ja zum laufen und könnt mir sagen wie ihrs gemacht habt... :roll:
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 21.05.06 11:08 
Hänge es doch hier an den Beitrag an. Der andere Link funktioniert nicht.

_________________
Markus Kinzler.
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: So 21.05.06 11:11 
Ach sorry, das mit dem Anhängen hab ich übersehen.. :lol:
Einloggen, um Attachments anzusehen!
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 21.05.06 12:05 
hallo,

ich habe deinen code mal ein wenig geändert.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var a:string;
begin
 case key of
  'a': a := extractfilepath(application.ExeName)+'\Ordner1';
  'b': a := extractfilepath(application.ExeName)+'\Ordner2';
 end;

 image1.Picture.LoadFromFile(a+'\1.bmp');
end;


das behebt dein problem zwar nicht, sieht aber übersichtlicher aus.

Das Problem ist, dass der Button1 den Focus besitzt, sodass nicht für Form1 das OnkeyPress-Ereignis auftritt, sondern für den Button. Enfernst du den Button, so klappts ;)

Mfg
GR-Thunderstorm Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 206



BeitragVerfasst: So 21.05.06 12:16 
Danke für den Hinweis! ^^

So wie ich das sehe, liegts also daran, dass der Button von Anfang an highlighted ist... Kann man das irgendwie weg machen?