Autor Beitrag
fabi65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: So 17.04.05 11:42 
also ich möchte eine Zufallszahl erzeugen, dessen große nach oben, auseinem Wert von einer ini begrennzt ist....

nun habe ich das prob, das man für die Zufallszahl eine integer vari brauch, ich aber bei der ini abfrage einen string erhalte.... Wie kann ich das lösen?

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:
var
datei,zahl :string;
k :integer;
begin
if opendialog1.execute then begin
datei:=opendialog1.filename;

ini: TIniFile;

ini := TIniFile.Create(datei);

    // INI-Datei initialisieren
try
 //daten abfragen
zahl:= ini.ReadString('a', 'zahl', '');


finally
  ini.Free;
k := random(1) + zahl;

    // Variable ini wieder freigeben
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: So 17.04.05 12:02 
Hallo!

Hast du dir mal die Hilfe zu TIni angeschaut?

Benutze statt ReadString die Funktion ReadInteger.

Gruß
Tino
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: So 17.04.05 12:09 
Du musst auch noch irgendwo vor Random, randomize erwähnen, sonst kann es sein ,dass immer nur die gleiche Zahl erhältst.

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
fabi65 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: So 17.04.05 18:20 
wenn ich ReadInteger benutze kommt:
[Fehler] Haupt.pas(72): E2010 Inkompatible Typen: 'Integer' und 'string'
OneOfTen
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 17.04.05 18:24 
user profile iconfabi65 hat folgendes geschrieben:
wenn ich ReadInteger benutze kommt:
[Fehler] Haupt.pas(72): E2010 Inkompatible Typen: 'Integer' und 'string'


weil deine variable "Zahl" vom Typ String deklariert hast..
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 17.04.05 18:25 
schlaule. die variable, in die du das speicherst muss natürlich auch integer sein:
ausblenden Delphi-Quelltext
1:
2:
3:
aIntegerVariable:=ini.ReadInteger('asd','asdasd',0);
{oder was umständlicher ist}
aIntegerVariable:=StrToInt(ini.ReadString(...));

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
fabi65 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: So 17.04.05 18:26 
habe nätürlich auch ne integer vari genommen, jedoch nicht die 0 als Parameter :D gehts jetzt aber^^ Also Danke :wink: