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

نسخة كاملة : الدالة pos و البحث بمجموعة ملفات
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
سلام الله عليكم

كيف إستعمل الدالة pos في البحث في حالة: ملف نصي.

شكرا.
وعليكم السلام
http://www.delphi4arab.net/forum/showthr...p?tid=2584
غير ذلك، وضح أكثر
بالتوفيق.
بارك الله فيك أخي kachwahed

مادام قلت التوضيح سأوضح
كيف إنشاء برنامج بحث بسيط يقوم ببحث عن كلمة أو رقم أو....في مجموعة من ملفات txt
ما هي أحسن إعاز لذلك ؟

شكرا
الإيعاز يختلف بحسب الطريقة التي تود أن يقوم بها البرنامج...
اطلع الموضوع السابق
يمكنك استخدام الأنماط TStringList... أو الإجراءات التتابعية AssignFile...
PHP كود :
if MyStringList.Find('TextToSearch', FromIndex) then 
أرفق محاولة للتوضيح أكثر
بالتوفيق.
سلام الله عليكم

أخي kachwahed

أنا أحاول تركيب برنامج بسيط يبحث عم مطيات داخل ملفات نصية موضوعة على شبكة محلية فقمت بإستعمال مدر أحد برامج البحث و أنا بصدد تعديلها على حسب حاجتي
أرفق محاولتي لكن غير مكتملة
كود :
unit U_TextSearch2; {Copyright © 2004, 2007 Gary Darby, www.DelphiForFun.org This program may be used or modified for any non-commercial purpose so long as this original notice remains in place. All other rights are reserved } interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, shellapi; type TForm1 = class(TForm) WholeWords: TCheckBox; CaseSensitive: TCheckBox; SearchString: TEdit; Label1: TLabel; GoBtn: TButton; Memo1: TMemo; RichEdit1: TRichEdit; ShowHits: TCheckBox; StaticText1: TStaticText; Label2: TLabel; L: TMemo; Button1: TButton; procedure GoBtnClick(Sender: TObject); procedure StaticText1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } filename:string; end; var Form1: TForm1; i:integer; implementation {$R *.DFM} {************* FileBtnClick *********} var delims:set of char=[' ',',','.',';',':','(',')']; {************* Isword **********} function isword(start,stop:integer; s:string):boolean; begin if ( ((start>=1) and (s[start]in delims)) or (start<1) ) and ( ((stop<=length(s)) and (s[stop]in delims)) or (stop>length(s)) ) then result:=true else result:=false; end; {********** GoBtnClick **********} procedure TForm1.GoBtnClick(Sender: TObject); var I,n:integer; f:textfile; line,line2:string; search:string; count:integer; hitfound:boolean; begin if filename<>'' then begin richedit1.clear; assignfile(f,filename); reset(f); if not casesensitive.checked then search:=uppercase(searchstring.text) else search:=searchstring.text; count:=0; while not eof(f) do begin readln(f,line); inc(count); hitfound:=false; if not casesensitive.checked then line2:=uppercase(line) else line2:=line; n:=pos(search,line2); if (n=0) and (not showHits.checked) then richedit1.lines.add(line) else while n>0 do begin if (not wholewords.checked) or ({(wholewords.checked) and }(isword(n-1,n+length(search),line))) then with richedit1 do begin if not hitfound then begin {this is the first occurrence of search word in this sentence} If showhits.checked then Lines.add('Line #'+inttostr(count)); hitfound:=true; lines.add(line); end; selstart:=length(text)-length(line)+n-3; {lines end with CR LF, so subtract} selLength:=length(search); selattributes.style:=[fsbold]; end; {erase that hit in line2 copy so that we can check for more occurences} for i:=n to n+length(search)-1 do line2[i]:=CHAR($01); n:=pos(search,line2); end; end; if richedit1.lines.count=0 then richedit1.lines.add('No matches found'); closefile(f); end; end; procedure TForm1.StaticText1Click(Sender: TObject); begin ShellExecute(Handle, 'open', 'http://www.delphiforfun.org/', nil, nil, SW_SHOWNORMAL); end; procedure TForm1.FormCreate(Sender: TObject); begin i:=0; L.lines.LoadFromfile('C:\1.txt'); filename:=L.lines[I]; if i < L.Lines.Count-1 then i:=i+1; end; procedure TForm1.Button1Click(Sender: TObject); begin form1.close; end; end.
السلام عليكم ورحمة الله
قم بانشاء حلقة حسب عدد الملفات
بها تغير اسم الملف filename وتستدعي البحث GoBtnClick
هذه محاولتي
السورس مع ملفاته

تعديل بسيط باضافة حلقة كما ذكرت سابقا
كود :
begin s:=0; richedit1.clear; L.lines.LoadFromfile('1.txt'); Repeat filename:=L.lines[s]; richedit1.Lines.add('Search result for file "'+filename+'"'); GoBtnClick(Sender); s:=s+1 Until s =L.Lines.Count; end;
المثال مرفق، بالتوفيق