Solved

File Comparison

Posted on 2000-04-27
4
208 Views
Last Modified: 2012-05-04
How do I perform a binary file comparison (like the one in DOS [FC]) and direct the output to a file using delphi 5.
0
Comment
Question by:eldraco
4 Comments
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
Hi
The working sample is bellow.

-----
uses ... , ShellApi, ...

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
   ShellExecute(handle,'open','command','/c fc c:\autoexec.bat c:\autoexec.dos > c:\result.txt',nil,SW_HIDE);
end;

-----
Igor.
0
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
But there is one problem. How did you know that the compression is finished!

Motaz
0
 
LVL 1

Expert Comment

by:new_x
Comment Utility
Listening
0
 
LVL 7

Accepted Solution

by:
God_Ares earned 100 total points
Comment Utility
I think this is what you need...
code could be optimized..

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    OpenDialog1: TOpenDialog;
    OpenDialog2: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    fname1,fname2:string;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if opendialog1.execute then fname1:=opendialog1.filename;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if opendialog2.execute then fname2:=opendialog2.filename;
end;

procedure TForm1.Button3Click(Sender: TObject);
var s1,s2:Tfilestream;
    i,j:integer;
    a,b:byte;
begin
  s1:=tfilestream.Create(fname1,fmOpenRead);
  s2:=tfilestream.Create(fname2,fmOpenRead);

  if s1.Size > s2.size then i:=s2.size else i:=s1.size;

  For j:=1 to i-1 do
  Begin
    s1.Read(a,1);
    s2.Read(b,1);
    if a<>b then memo1.lines.add(inttohex(j,6)+'  '+inttohex(a,2)+' '+inttohex(b,2));
  End;

  if s1.Size > s2.size then memo1.Lines.add(fname1+' is lager than '+fname2);
  if s1.Size < s2.size then memo1.Lines.add(fname2+' is lager than '+fname1);

  s1.free;
  s2.free;
end;

end.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now