![]() |
|
البحث في ملف عن كلمة - نسخة قابلة للطباعة +- delphi4arab منتديات دلفي للعرب (https://delphi4arab.net/forum) +-- قسم : منتديات دلفي للعرب التعليمية (https://delphi4arab.net/forum/forumdisplay.php?fid=3) +--- قسم : سؤال و جواب حول دلفي (https://delphi4arab.net/forum/forumdisplay.php?fid=15) +--- الموضوع : البحث في ملف عن كلمة (/showthread.php?tid=897) |
البحث في ملف عن كلمة - deemy - 19-05-2009 أحاول انشاء برنامج يبحث في ملف معين عن كلمة مطابقة للكلمة التي أدخلها المستخدم
وشكرا البحث في ملف عن كلمة - mohfa - 20-05-2009 كود : function PosInFile(Str,FileName:string):integer;
var
Buffer : array [0..1023] of char;
BufPtr,BufEnd:integer;
F:File;
Index : integer;
Increment : integer;
c : char;
function NextChar : char;
begin
if BufPtr>=BufEnd then
begin
BlockRead(F,Buffer,1024,BufEnd);
BufPtr := 0;
Form1.ProgressBar1.Position := FilePos(F);
Application.ProcessMessages;
end;
Result := Buffer[BufPtr];
Inc(BufPtr);
end;
begin
Result := -1;
AssignFile(F,FileName);
Reset(F,1);
Form1.ProgressBar1.Max := FileSize(F);
BufPtr:=0;
BufEnd:=0;
Index := 0;
Increment := 1;
repeat
c:=NextChar;
if c=Str[Increment] then
Inc(Increment)
else
begin
Inc(Index,Increment);
Increment := 1;
end;
if Increment=(Length(Str)+1) then
begin
Result := Index;
break;
end;
until BufEnd = 0;
CloseFile(F);
Form1.ProgressBar1.Position := 0;
end; |