Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.06.07 22:30 
Hi,
ich hab mal wieder ein Problem: Der folgende code soll einen quelltext laden und dann in ihm was suchen, aber immer wenn ich auf den Button klick, kommt ne access violation und es passiert nix. Wisst ihr vielleicht was falsch is?
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:
25:
26:
procedure TForm2.Button3Click(Sender: TObject);
var htmlcode, Url2:string;
    s:integer;
    Quellcodepfad: string;
    Dateiendung: String;
begin
Dateiendung:='.7z';
Quellcodepfad:=ExtractFilePath(ParamStr(0))+'temp.html';

LoadStringfromFile(quellcodepfad,htmlcode);

s:=pos('action=',htmlcode); //htmlcode ist der string in dem der queltext geladen wurde

url2:='';
if s>0 then begin

repeat
url2:=url2+htmlcode[s+8]; // s liefert die stelle von dem 'a' von 'action' wieder deswegen s+8
s:=s+1;
until (htmlcode[s+4]+htmlcode[s+5]+htmlcode[s+6]+htmlcode[s+7]=Dateiendung);
label6.caption:=url2;
end else begin
showmessage('Bekomme keinen Link!');
end; 

end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 21.06.07 22:43 
Moin!

Dein Code ist nicht eingerückt... :( das kann man ja kaum lesen :?
user profile iconHendi48 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
repeat
url2:=url2+htmlcode[s+8]; // s liefert die stelle von dem 'a' von 'action' wieder deswegen s+8
s:=s+1;
until (htmlcode[s+4]+htmlcode[s+5]+htmlcode[s+6]+htmlcode[s+7]=Dateiendung);

Du prüfst nicht, ob der Index s überhaupt noch im String drin ist :arrow: wenn´s nicht mehr drin ist, gibt´s ne Zugriffsverletzung, korrekterweise. :idea: :mahn:

Schau mal nach Suche in: Delphi-Forum, Delphi-Library TREGEXPR, damit sollte das besser gehen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.06.07 23:16 
wie würde das denn dann mit meiner sache oben funken?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 21.06.07 23:18 
Moin!

So etwa. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Do 21.06.07 23:34 
ok, und was is dann das hier (\d{1,3}\.){3}\d{1,3} ? Und wo krieg ich diese TRegExpr her? (ich hab delphi 2007)
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Fr 22.06.07 05:25 
Hallo,

www.regexpstudio.com...p/RegExp_Syntax.html zeigt dir die Syntax, Narses Beispiel sucht nach IP-4 Adressen also genau 3 ein bis drei 3 stelligen Ziffernfolgen die von einem Punkt gefolgt werden,denen eine ein bis dreistellige Ziffernfolge folgt.

Was mir bei denem Programmschnipsel auffällt:
Du vergleichst bei until die Dateieindeunf '.7z' (drei Zeichen) mit einer vierstelligen Endung. Das kann ja nicht funktionieren. Du suchst immer weiter ohne Rücksicht darauf, ob s schon größer als length(htmlcode) ist-> das führt natürlich zu einem Zugriff auf Speicher, der Dir nicht zugewiesen ist.
Das mußt auch davon ausgehen das '.7z' auch mal nicht vorkommt, oder 'action=' am Ende steht, weil die Datei falsch übertragen wurde und und und.

Suche mittels PosEx (bei uses strutils einfügen ) die Dateiendung.
Wenn S gefunden dann
ausblenden Delphi-Quelltext
1:
DateiPosDateiendung := PosEX(DateiEndung,htmlcode,s+8);					

Falls DateiPosDateiendung > 0 dann ist die Positin gefunden und fertig.

Gruß Horst
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Fr 22.06.07 22:02 
ich habs schon:
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:
25:
26:
27:
var
url2,dateiendung,htmlcode : string;
url: string;
s,i :integer;
quellcodepfad: String;
begin
url2:=' ';
url:='http://rapidshare.com/files/15123761/79-80.rar';
Quellcodepfad:=ExtractFilePath(ParamStr(0))+'temp.html';
i:=length(url);
dateiendung:=url[i-3]+url[i-2]+url[i-1]+url[i];
LoadStringfromFile(quellcodepfad,htmlcode);
s:=pos('action=',htmlcode);


if s>0 then begin
repeat
url2:=url2+htmlcode[s+8];
s:=s+1;


until (htmlcode[s+4]+htmlcode[s+5]+htmlcode[s+6]+htmlcode[s+7]=dateiendung);
Form2.label6.caption:=url2;
end else begin
showmessage('Fehler');
end;
end;