Autor Beitrag
rokdd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: Mo 14.07.03 12:02 
Hallo,
ich habe folgendes Problem:in meinem programm habe ich mehrere konstanten(z.B. "file1", "file2") für verschiedene filename . Nach dem Eingeben der Name der Konstante (also z.b "file1") soll der filename der Konstante in eine Variablen geschrieben werden.

Wie geht so etwas???

Schon mal danke!
rokdd
kat1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 40

Win XP
D6 EntPr
BeitragVerfasst: Mo 14.07.03 12:15 
Sorry, ich weiß nicht ob ich der Einzige hier bin, aber so richtig schlau werde ich aus Deiner Message nicht. Du willst den Wert einer Konstanten einer Variable zuweisen? Das sollte doch eigentlich kein Problem sein.
Geht doch einfach mit := wenn die Variable den gleichen Typ hat wie die Konstante oder war das nicht Deine Frage. Am besten Du postest mal ein wenig Source-Code.

_________________
Mfg Uwe
Es ist eine Unsitte der Menschen, sich an alles zu gewöhnen.
rokdd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: Mo 14.07.03 12:38 
Titel: Source
ausblenden 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:
  const kies='C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\kies.bmp';
  const erde='C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\erde.bmp';
  const gras='C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\gras.bmp';
  const zypresse='C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\zypresse2.bmp';

....
procedure raster_add(i,k:integer;modus,bild:String);
var BitMap: Array[0..1] of TBitMap;
begin
//in raster eintragen:
BitMap[0] := TBitMap.Create;
BitMap[1] := TBitMap.Create;
try
BitMap[0].LoadFromFile ((*wenn bild='kies' dann nutze constante kies*));
BitMap[1].Assign(BitMap[0]);
Bitmap[1].Dormant;
Bitmap[1].Transparent:=true;Bitmap[1].TransparentColor:=BitMap[1].canvas.pixels[0,0];
BitMap[1].FreeImage;
frm_area.pb_area.Canvas.Draw(i*29,k*10,BitMap[1]);
BitMap[1].ReleaseHandle;
finally
BitMap[0].Free;
BitMap[1].Free;
end;
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 14.07.03 12:50 
ausblenden Delphi-Quelltext
1:
2:
If bild = 'kies' Then
  BitMap[0].LoadFromFile (kies)
kat1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 40

Win XP
D6 EntPr
BeitragVerfasst: Mo 14.07.03 13:03 
Genau so wie Tino das vorgeschlagen hat, würde ich das auch machen. :)

Und da Du mehrere Konstanten hast, würde sich dann evtl. noch die case of Anweisung anbieten.

ausblenden Delphi-Quelltext
1:
2:
3:
case bild of
  'kies': BitMap[0].LoadFromFile(kies);
  'erde': BitMap[0]. // .... usw.

_________________
Mfg Uwe
Es ist eine Unsitte der Menschen, sich an alles zu gewöhnen.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 14.07.03 13:18 
Nur dass man keine Strings als case-Statement verwenden kann... :roll:

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
kat1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 40

Win XP
D6 EntPr
BeitragVerfasst: Mo 14.07.03 13:19 
ups stimmt *im Boden versinkt*

Sollte man doch nicht einfach von seinen Problemen abstrahieren :D

_________________
Mfg Uwe
Es ist eine Unsitte der Menschen, sich an alles zu gewöhnen.
rokdd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: Mo 14.07.03 13:22 
Titel: re:Source
...ausserdem habe ich ja noch mehr konstanten irgendwann(so um die 50). wie dann?

rokdd
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 14.07.03 13:28 
ich würde 2 arrays nehmen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
const
  iNameCount = 50;
  szNames: array [1..iNameCount] of String = (
      'kies', 
      'erde', 
      'gras'
    );
  szPathes: array [1..iNameCount] of String = (
      'C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\kies.bmp',
      'C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\erde.bmp', 
      'C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\gras.bmp'
    );


der Rest ist dann ganz simpel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for i := 1 to iNameCount do
  if bild = szNames[i] then
  begin
    BitMap[0].LoadFromFile(szPathes[i]);
    Break;
  end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
rokdd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: Mo 14.07.03 13:32 
man braucht aber auch eine if-anweisung!!!
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 14.07.03 13:40 
Das ist meiner Meinung nach eine IF-Anweisung... :roll:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
for i := 1 to iNameCount do 
--->  if bild = szNames[i] then <---
  begin 
    BitMap[0].LoadFromFile(szPathes[i]); 
    Break; 
  end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 14.07.03 13:44 
rokdd hat folgendes geschrieben:
man braucht aber auch eine if-anweisung!!!

Und was spricht gegen die IF-THEN-Anweisung?

Gruß
Tino
rokdd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: Mo 14.07.03 13:59 
weil bei 50 Konstanten es ziemlich unübersichtlich und arbeitsentensiv ist, die ganzern if-anweisungen zu schreiben. Die alternative des Caseblockes funzt hier auch nciht, weil der keine strings verarbeiten kann. Laso gibt es keine andere lösung???


Rokdd
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 14.07.03 14:13 
Ähm.. Hallo?? Schaust du mal bitte 5 Beiträge weiter oben..!! :? :roll:

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: Mo 14.07.03 16:00 
Um Strings in Case zu nutzen schaut mal in die Faq, da hatte ich vor einiger zeit eine gute methode gepostet!

www.delphi-forum.de/viewtopic.php?t=11117
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: Mo 14.07.03 22:43 
Mal was anderes: Seh ich das richtig, daß die Bilder alle im gleichen Verzeichnis stehen, und noch dazu genau gleich heisen wie die mögliche Auswahl?

Wie wärs denn dann, wenn Du Dir den Dateinamen einfach daraus zusammensetzt?

ausblenden Delphi-Quelltext
1:
2:
const
  RootPath = 'C:\Programme\Borland\Delphi6\Projects\robert\dspiel\bilder\neu\';

und dann  BitMap[0].LoadFromFile(RootPath+bild+'.bmp');

Wie stellst Du eigentlich den User vor die Auswahlmöglichkeit? Falls Du die Elemente in einer StringList (TStrings) hast, könntest auch mit IndexOf(...) die Nummer des Elementes finden. Über diese Nummer lässt sich auch recht gut ein Array oder eine zweite StringList ansprechen.

Aber frag mich jetzt nicht, wieviele IF-Abfragen hinter IndexOf() stehen.

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 15.07.03 02:26 
Wie soll das mit den hardgecodeten Pfaden auf anderen Rechner funktionieren? Oder habe ich da jetzt was verpaßt?
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: Di 15.07.03 13:27 
Guter Einwand Luckie.
Aber wie wäre es dann gleich mit einer besseren Variante?

Eine VARIABLE RootPath := ExtractFilePath(Application.Exename) im OnCreate der Form setzen zum Beispiel!?

Oder gleich den Aufruf   BitMap[0].LoadFromFile(ExtractFilePath(Application.Exename)+'bilder\neu\'+bild+'.bmp');

Ich weis ja nicht mal, ob ich hier mit dieser Vereinfachung richtig liege. Die Pfade könnten ja auch verschieden sein. Aber ich denke es ist in diesem Fall vielleicht nicht schlecht sich Gedanken über die Methodik zu machen. Dabei erledigen sich manche Probleme von alleine.

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."
Tana´Ri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 230



BeitragVerfasst: Di 15.07.03 14:34 
Leute wie wärs mit -> RESOURCESTRING
weitere Infos siehe Delphi Help

_________________
mfg
Tana´Ri