delphi4arab منتديات دلفي للعرب

نسخة كاملة : التعامل مع اللست فيو
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم اخوتي لدي مشكل بسيط ان شاء الله  اولا عملت الكود بلغة السي شارب يعمل عادي لكن عندما انتقلت الى الدلفي واجهتني مشكلة في تحويله والتعامل معه حيث عند اضافة الزيادة لمتغير الاتيجر يعطي خطا فما الحل او تصحيح للكود

كود الدلفي به خطا [صورة: IajpA.jpg]

انا احاول جلب نصوص من موقع باستخدام التعابير القياسية المشكل عندي في loop

جزاكم الله خيرا
من الافضل ان ترفق لنا صورة للمشكل
و ايضا جرب الزيادة بطريقة اخرى مثل
i := i +1
شكرا لردك اخي رحيش اولا انا افلتر نصوص من موقع عن طريق التعابير القياسية النصوص تكون مثلا في العمود الاول من اللست فيو الاسماء وفي الحقل الثاني التاريخ وفي الحقل الثالث الرابط وهكذا في السي شارب ليس لدي مشكلة في عمله لكني انتقلت الى الدلفي مؤخرا لانها شيسهة بالسي شارب فواجهتني هذه المشكلة جربت كود اخر لكن عند استعمال الحلقة يتم اعادة السطر الاول نفسه وبخصوص i := i +1
او inc(i) لا تعمل داخل الحلقة في الدلفي ليس مثل السي شارب هذه هي المشكلة هذه صورة

http://up.dev-point.com/uploads1/d8df9036cfd91.jpg

هذا هو الكود الثاني
for I := 0 to MatchCollection.Count-1 do

begin
listv:=ListView1.Items.Add();
listv.Caption:= Submatches[0];
listv.SubItems.Add(Submatches[1]);

listv.SubItems.Add(Submatches[2]);
listv.SubItems.Add(Submatches[3]);
انت في السي شارب تستخدم الحلقة التكرارية for each اما في الدلفي فانت تستخدم for العادية
شاهد هذا الفيديو و استخدم الحلقة التكرارية for in
https://www.youtube.com/watch?v=6nURyiQFkLk
(23-12-2016, 10:00 PM)rahiche كتب : [ -> ]انت في السي شارب تستخدم الحلقة التكرارية for each اما في الدلفي فانت تستخدم for العادية
شاهد هذا الفيديو و استخدم الحلقة التكرارية for in
https://www.youtube.com/watch?v=6nURyiQFkLk
جزاك الله خيرا اول مرة اسمع بها كنت اظن انه لا يوجد مكافئ لها في الدلفي حقيقة ساشاهد الفيديو واردلك خبر بارك الله فيك

عجزت عنها للاسف ممكن تصحح لي الكود بارك الله فيك

جربت هكذا ولم تنجح

for Submatches in MatchCollection do

begin
ListView1.Items.Item[i].Caption := Submatches[0];
ListView1.Items[i].SubItems.Add(submatches[1]);
ListView1.Items[i].SubItems.Add(submatches[2]);
ListView1.Items[i].SubItems.Add(submatches[3]);
i:=i+1;

end;
هذا الكود كامل

procedure TForm1.Button1Click(Sender: TObject);
var
http :TIdHTTP;
reg: IRegExp2;
MatchCollection: IMatchCollection2;
Match1: IMatch2;
match: ISubMatches;
txt Confusedtring;
i : integer;
begin
reg := CoRegExp.Create;
reg.Global := True;
reg.IgnoreCase:=true;
reg.Pattern := '<a class="internal-link" href="http://filehippo.com.*?title="([a-z0-9\s!.]+)">[\S\s]+?<img src="(.*?.png)"/>';
http:=TIdHTTP.Create(nil);
txt:= http.Get ('http://filehippo.com/fr/software/antimalware/');
http.Request.UserAgent:='Mozilla/5.0 (Windows NT 6.1; rv:48.0) Gecko/20100101 Firefox/48.0';
MatchCollection := reg.Execute(txt) as IMatchCollection2;

if MatchCollection.Count = 0 then exit;
Match1 := MatchCollection.Item[0] as IMatch2;
match := Match1.SubMatches as ISubMatches;
begin
for match in MatchCollection do
begin
ListView1.Items.Item[i].Caption := match [0];//program names
ListView1.Items[i].SubItems.Add(match [1]);//link
inc(i)
end;
IdHTTP1.Free;
end;
end;


الخطا هو

dcc32 Error] Unit1.pas(58): E2431 for-in statement cannot operate on collection type 'IMatchCollection2' because 'IMatchCollection2' does not contain a member for 'GetEnumerator', or it is inaccessible
السلام عليكم ورحمة الله

كود :
procedure test; var  Lst : TListItem; begin   for i:=0 to Matchcollection.count-1 do    begin   lst:=listview1.Items.Add;;   lst.Caption:=submatches[0];   lst.SubItems.Add(submatches[1]);   lst.SubItems.Add(submatches[2]);   lst.SubItems.Add(submatches[3]);    end; end;
للاسف انا مجربه قبل هذا لكن يعطيني نفس السطر الاول مكرر لذلك استعملت
for in loop المكافئة ل foreach ولكن لا جدوى انظر الصورة
http://up.dev-point.com/uploads1/f20026c975621.jpg

هذا الكود كامل

procedure TForm1.Button1Click(Sender: TObject);
var
Lst : TListItem;
http :TIdHTTP;
reg: IRegExp2;
MatchCollection: IMatchCollection2;
Match1: IMatch2;
match: ISubMatches;
txt Confusedtring;
i : integer;
begin
reg := CoRegExp.Create;
reg.Global := True;
reg.IgnoreCase:=true;
reg.Pattern := '<a class="internal-link" href="http://filehippo.com.*?title="([a-z0-9\s!.]+)">[\S\s]+?<img src="(.*?.png)"/>';
http:=TIdHTTP.Create(nil);
txt:= http.Get ('http://filehippo.com/fr/software/antimalware/');
http.Request.UserAgent:='Mozilla/5.0 (Windows NT 6.1; rv:48.0) Gecko/20100101 Firefox/48.0';
MatchCollection := reg.Execute(txt) as IMatchCollection2;

if MatchCollection.Count = 0 then exit;
Match1 := MatchCollection.Item[0] as IMatch2;
match := Match1.SubMatches as ISubMatches;
begin
begin
for i:=0 to Matchcollection.count-1 do
begin
lst:=listview1.Items.Add;;
lst.Caption:=match[0];
lst.SubItems.Add(match[1]);
end;
IdHTTP1.Free;
end;
end;
end;

end.
في حلقة FOR في الدلفي i يزداد أوتوماتيكيا...
ما عليك يا صديقي إلا حذف التعليمة inc(i)  من داخل الحلقة For