Autor Beitrag
Jack Falworth
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 222

Win XP Pro, Slackware 10.0
D5 Enterprise, C++, ABAP
BeitragVerfasst: Di 26.11.02 16:23 
hier mein Problem:

ausblenden 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:
type 
         TSymbol = (Haus_s, Garten_s, Tisch_s); 
    
         TX = record 
         name: string[200]; 
         sym: TSymbol; 

procedure TForm1.Button1Click(Sender: TObject); 
var f: file of TX; buffer: array [0..anz_max] of TX; i: integer; 
begin 
try 
try 
assignfile (F, 'test.dat'); 
if fileexists ('test.dat') then reset (F) else rewrite (F); 
except 
exit; 
end; 

for i:= 0 to anz_max -1 do 
begin 
buffer[i].name:= RichEdit1.Lines[i]; 
buffer[i].sym:=  RichEdit1.Lines[i] (??); (* <- hier ist das Problem *) 
write (initscan, Buffer[i]); 
end; 
finally 
closefile (f); 
end;


In meinem RichEdit stehen namen und symbole. Da diese im Richedit aber automatisch strings sind, kann ich sie nicht in Buffer.sym einlesen.
Daher meine Frage kann ich irgendwie ne Procedure oder Funktion schreiben, mit der ich meinen Typ in einen String konvertieren kann und andersherum?

Danke schon mal im Voraus

Jack Falworth
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Mi 27.11.02 00:17 
nö, aber du kannst es doch so machen:
ausblenden Quelltext
1:
2:
3:
if RichEdit1.Lines[i] = 'Haus_s' then
 buffer[i].sym:=  Haus_s;
{ ... }
Jack Falworth Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 222

Win XP Pro, Slackware 10.0
D5 Enterprise, C++, ABAP
BeitragVerfasst: Mi 27.11.02 13:42 
ja das hab ich mir auch schon gedacht, aber da ich in meinem Program 30 Symbole hab ist das viel Schreibarbeit und nicht sehr elegant.
trotzdem danke.

MfG

Jack Falworth
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mi 27.11.02 14:34 
Es gibt noch eine andere Möglichkeit, die aber anfänglich auch mit ein wenig Arbeit verbunden ist.

Die Funktion Ord liefert dir den sogenannten Ordinalwert einer Typenvariablen. So hat z.B. Haus_S den Wert 0.

Wenn du nun eine Stringliste mit den Bezeichnungen hast, geht eine Auflösung leicht:

ausblenden Quelltext
1:
ShowMessage(Bezeichnungen[Ord(MyValue)]);					


Cu,
Udontknow
Jack Falworth Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 222

Win XP Pro, Slackware 10.0
D5 Enterprise, C++, ABAP
BeitragVerfasst: Mi 27.11.02 18:30 
ich habs jetzt so gemacht, dass im RichEdit und im Aufzählungstyp die Symbole in gleicher Reihenfolge stehen. Dann kann ich nämlich folgendes machen:

ausblenden Quelltext
1:
2:
3:
4:
for i:= 0 to anz_max -1 do 
begin 
...
buffer[i].sym:=  TSymbol(i);


Das funktioniert jetzt.

MfG

Jack Falworth