Autor Beitrag
the-kecks
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Fr 06.03.09 22:29 
hi,
ich möchte mit meinem programm eine .ini datei auslesen und nach einem wert durchsuchen...ich kriege nur immer einen fehler.
hier mein code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var
i3 : Integer;
fileini: TIniFile;
str : String;
tstr : TStrings;
str2 : String;
//...
try
     for i3:=0 to Length(str) do //um den eintrag zu suchen braucht man ja section und value. str ist beides also str=section, value
       tstr[1]:=Copy(str[i3],Pos(', ',str[i3])+1,MaxInt); //value wird aus string herausgefiltert
       str2:=Copy(str[i3],Pos(', ',str[i3])-1,1); // section wird aus string herausgefiltert
        antwort:=fileini.ReadSectionValues(str2, tstr); //hier liegt wohl der fehler 
       fileini.free;
    except
    antwort:='Nicht gefunden!'; //wenn eintrag nicht gefunden wurde dann antwort='nicht gefunden'
    fileini.free;

hier der genaue fehler:
[Fehler] Unit1.pas(270): Inkompatible Typen: 'String' und 'procedure, untyped pointer or untyped parameter'

mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 06.03.09 22:44 
Deine Formatierung ist ja... :puke:

Bei der for-Schleife fehlt wohl ein begin..end. Im Moment wäre die Zuordnung (da sollte bei str2:=... auch eine Warnung wegen i3 kommen):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  i3: Integer;
  fileini: TIniFile;
  str: String;
  tstr: TStrings;
  str2: String;
//...
  try
    for i3:=0 to Length(str) do //um den eintrag zu suchen braucht man ja section und value. str ist beides also str=section, value
      tstr[1]:=Copy(str[i3],Pos(', ',str[i3])+1,MaxInt); //value wird aus string herausgefiltert

    str2:=Copy(str[i3],Pos(', ',str[i3])-1,1); // section wird aus string herausgefiltert
    antwort:=fileini.ReadSectionValues(str2, tstr); //hier liegt wohl der fehler 
    fileini.free;
  except
    antwort:='Nicht gefunden!'; //wenn eintrag nicht gefunden wurde dann antwort='nicht gefunden'
    fileini.free;


Und zu dem Fehler: Schau mal in die Hilfe zu ReadSectionValues, das ist keine Funktion...
docs.codegear.com/do...adSectionValues.html
the-kecks Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Fr 06.03.09 22:53 
der link den du beigefügt hast funktioniert nicht...
ich hab mal bei google gesucht und da gibts einen de machts genauso wie ich:
www.delphipraxis.net/topic21827.html

mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 06.03.09 23:01 
user profile iconthe-kecks hat folgendes geschrieben Zum zitierten Posting springen:
der link den du beigefügt hast funktioniert nicht...
Arg, der Codegear Server ist down...

Aber das ist auch nur der Link zur Online-Hilfe, ich habe doch geschrieben, dass du in die Hilfe schauen sollst...
Zitat:
Syntax
ausblenden Delphi-Quelltext
1:
procedure ReadSectionValues(const Section: string; Strings: TStrings); override;					

Description
Call ReadSectionValues to read the keys, and the values from all keys, within a specified section of an INI file into a string list object (TStrings descendant). The key names and values are added to the string list as strings of the form KeyName=ValueName.

Section identifies the section in the file from which to read key values.
Strings is the string list object into which to read the values. Strings can point to a TStrings object, or to a component property, such as Items for a TListBox component, that is a TStrings object itself.


user profile iconthe-kecks hat folgendes geschrieben Zum zitierten Posting springen:
ich hab mal bei google gesucht und da gibts einen de machts genauso wie ich:
www.delphipraxis.net/topic21827.html
Ja, da steht auch ungetestet dabei. Es ist nämlich falsch.

Schau mal etwas weiter unten, da steht wie es richtig geht. Wie gesagt, es ist eine Prozedur, hat also keinen Rückgabewert.
the-kecks Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Fr 06.03.09 23:33 
jetzt funktioniert es aber jetzt bekomme ich einen anderen fehler:
Erste Zufalls-Exception bei $769FF35F. Exception-Klasse EAbstractError mit Meldung 'Abstrakter Fehler'. Prozess Project1.exe (3804)
der neue code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
fileini:=TIniFile.create(Dateipfad);
    try
     for i3:=0 to Length(str) do
      begin
       tstr[1]:=Copy(str[i3],Pos(', ',str[i3])+1,MaxInt);
       str2:=Copy(str[i3],Pos(', ',str[i3])-1,1);
      end;
        fileini.ReadSectionValues(str2, tstr);
        antwort:=str;
       fileini.free;
    except
    antwort:='Nicht gefunden!';
    fileini.free;


mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 06.03.09 23:38 
Ich rate einmal, dass du tstr so erstellst:
ausblenden Delphi-Quelltext
1:
tstr := TStrings.Create;					
Du kannst aber TStrings so nicht benutzen, du musst eine davon abgeleitete Klasse benutzen, z.B. TStringList:
ausblenden Delphi-Quelltext
1:
 tstr := TStringList.Create;					
Denn in TStrings sind einige Teile der Funktionalität nur definiert, aber nicht implementiert.


Zuletzt bearbeitet von jaenicke am Fr 06.03.09 23:39, insgesamt 1-mal bearbeitet
LexXis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 170
Erhaltene Danke: 3



BeitragVerfasst: Fr 06.03.09 23:38 
Delphi Hilfe hat folgendes geschrieben:

TStrings contains abstract or, in C++ terminology, pure virtual methods and should not be directly instantiated.


Daher lieber TStringList verwenden!
Btw: Wird tstr auch irgendwo per Create erzeugt?

//EDIT: Ok, Ok.. siehe oben
the-kecks Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Fr 06.03.09 23:47 
ok jetz krieg ich noch nen anderen fehler^^
Erste Zufalls-Exception bei $769FF35F. Exception-Klasse EStringListError mit Meldung 'Listenindex überschreitet das Maximum (1)'. Prozess Project1.exe (4652)
code:
ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
procedure TForm1.Button1Click(Sender: TObject);
var
filetxt : Tstringlist;
i2 : Integer;
i : Integer;
i3 : Integer;
fileini: TIniFile;
str : String;
Dateipfad : String;
tstr : TStrings;
str2 : String;
begin
Dateipfad:=edit1.Text;
str:=edit2.Text;
filetxt:=TStringList.Create;
filetxt.LoadFromFile(Dateipfad);
tstr:=TStringList.Create;
for i:=0 to Length(Dateipfad) do
if pos('.txt', Dateipfad[i]) >0 then
   for i2:=0 to filetxt.count -1 do
    if pos(str, filetxt[i2]) >0 then
     begin
       antwort:=str;
       filetxt.free;
     end
       else
       begin
        filetxt.free;
        antwort:='Nicht gefunden!';
       end;
if pos('.ini', Dateipfad[i]) >0 then
    fileini:=TIniFile.create(Dateipfad);
    try
     for i3:=0 to Length(str) do
      begin
       tstr[1]:=Copy(str[i3],Pos(', ',str[i3])+1,MaxInt);
       str2:=Copy(str[i3],Pos(', ',str[i3])-1,1);
      end;
        fileini.ReadSectionValues(str2, tstr);
        antwort:=str;
       fileini.free;
    except
    antwort:='Nicht gefunden!';
    fileini.free;
    end;


mfg
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Fr 06.03.09 23:59 
Äh, die Fehlermeldugn sagt doch schon alles..?

ausblenden Delphi-Quelltext
1:
       tstr[1]:=Copy(str[i3],Pos(', ',str[i3])+1,MaxInt);					

Du versuchst hier, in die zweite Zeile zu schreiben, diese scheint aber noch nich zu geben.. also entweder tstr.text oder du fügst vorher einige Leerzeilen ein.

_________________
PROGRAMMER: A device for converting coffee into software.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 07.03.09 00:11 
Was soll das eigentlich?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Dateipfad : String;
...
for i:=0 to Length(Dateipfad) do
if pos('.txt', Dateipfad[i]) >0 then
Du gehst jeden Buchstaben durch und suchst 4 Buchstaben ('.txt') in einem einzigen Buchstaben (Dateipfad[i]).

Meinst du im Ernst, dass jemals diese 4 Buchstaben in dem einzelnen sein können?!?

Zudem ist i bei dem zweiten if gar nicht mehr definiert, weil da die Schleife zu Ende war vorher. Mit einer richtigen Einrückung passiert sowas nicht...
the-kecks Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Sa 07.03.09 00:58 
es war wohl schon etwas spät...naja habs jetz geschafft. danke!

mfg