Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.com

Compare two files of txt format - Algorithms - Tips & Tricks - Greatis Delphi Pages

We will read strings from each file while each of files has a data.
And we will compare each string from the first file with corresponding string from the second file.
All differences we will write in a memo.


procedure TForm1.Button1Click(Sender: TObject);
var
  First, Second: TextFile;
  Str, Str2: string;
begin
  Memo1.Clear;
  if (Edit1.Text<>'')and(Edit2.Text<>'') then
  begin
    AssignFile(First, Edit1.Text);
    AssignFile(Second, Edit2.Text);
    Reset(First);
    Reset(Second);
    while not EOF(First) do
    begin
      if EOF(Second)=True then
      begin
        Memo1.Lines.Add('*** ATTENTION ***');
        Memo1.Lines.Add('SECOND file has finished
                         but FIRST file has had a data yet.');
        Break;
      end;
      Readln(First, Str);
      Readln(Second, Str2);
      if CompareStr(Str, Str2)<>0 then
      begin
        Memo1.Lines.Add('FIRST  - '+Str);
        Memo1.Lines.Add('SECOND - '+Str2);
        Memo1.Lines.Add(' ');
      end;
    end;
    if EOF(Second)=False then
    begin
      Memo1.Lines.Add('*** ATTENTION ***');
      Memo1.Lines.Add('FIRST file has finished
                       but SECOND file has had a data yet.');
    end;
    CloseFile(First);
    CloseFile(Second);
    if Memo1.Lines.Count=0 then
      Memo1.Lines.Add('FIRST file is identical to SECOND file');
  end;
end;
Related topics
Compare string with pattern
Comparing of two strings

For more
Delphi Help

Download source