home *** CD-ROM | disk | FTP | other *** search
- unit CompFile;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, Grids, DBGrids, StdCtrls, ComCtrls, FileCtrl;
-
- type
- TFrmCompareFile = class(TForm)
- Panel1: TPanel;
- BtnClose: TButton;
- BtnCompare: TButton;
- RichEdit1: TRichEdit;
- RichEdit2: TRichEdit;
- StringGrid1: TStringGrid;
- Panel2: TPanel;
- GroupBox1: TGroupBox;
- FileListBox1: TFileListBox;
- Splitter1: TSplitter;
- GroupBox2: TGroupBox;
- FileListBox2: TFileListBox;
- Panel4: TPanel;
- Panel3: TPanel;
- Edit1: TEdit;
- Button1: TButton;
- Edit2: TEdit;
- Button2: TButton;
- DirectoryListBox1: TDirectoryListBox;
- ChkIgnoreLines: TCheckBox;
- procedure BtnCloseClick(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure BtnCompareClick(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormCreate(Sender: TObject);
- procedure Edit1Change(Sender: TObject);
- procedure FileListBox1Change(Sender: TObject);
- procedure FileListBox2Change(Sender: TObject);
- procedure FileListBox1Enter(Sender: TObject);
- procedure FileListBox1Exit(Sender: TObject);
- procedure FileListBox2Enter(Sender: TObject);
- procedure FileListBox2Exit(Sender: TObject);
- procedure Edit1Enter(Sender: TObject);
- procedure Edit1Exit(Sender: TObject);
- procedure Edit1KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure Edit2KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- private
- { Private declarations }
- lTextDeleting, lFileLstChg, lEditBox : Boolean;
- procedure ResourceToText(sResFile, sOutFile : String);
- procedure SearchFile(FileListBox : TFileListBox; sFile : String; Edit : TEdit);
- public
- { Public declarations }
- end;
-
- var
- FrmCompareFile: TFrmCompareFile;
-
- implementation
-
- uses Menu, GenFunc;
-
- {$R *.DFM}
-
- procedure TFrmCompareFile.BtnCloseClick(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TFrmCompareFile.Button1Click(Sender: TObject);
- begin
- FrmMenu.OpenDialog1.Title := 'Select file';
- FrmMenu.OpenDialog1.Filter := 'Any file (*.*)|*.*';
- if FrmMenu.OpenDialog1.Execute then
- Edit1.Text := FrmMenu.OpenDialog1.FileName;
- end;
-
- procedure TFrmCompareFile.BtnCompareClick(Sender: TObject);
- const
- CF_Source = 'Source.txt';
- CF_Target = 'Target.txt';
- var
- I, nMaxLine : Integer;
- sSource, sTarget : String;
- begin
- if not FileExists(Edit1.Text) and (not FileExists(Edit2.Text)) then begin
- MessageBeep(mb_Ok);
- ShowMessage('Please select file / file does not exists');
- Abort;
- end;
- sSource := Edit1.Text;
- sTarget := Edit2.Text;
- if (UpperCase(ExtractFileExt(sSource)) = '.DFM') then begin
- sSource := sTempDrive + CF_Source;
- ResourceToText(Edit1.Text,sSource);
- end;
- if (UpperCase(ExtractFileExt(sTarget)) = '.DFM') then begin
- sTarget := sTempDrive + CF_Target;
- ResourceToText(Edit2.Text,sTarget);
- end;
- StringGrid1.SetFocus;
- RichEdit1.Lines.LoadFromFile(sSource);
- RichEdit2.Lines.LoadFromFile(sTarget);
- if (RichEdit1.Lines.Count > RichEdit2.Lines.Count) then
- nMaxLine := RichEdit1.Lines.Count
- else
- nMaxLine := RichEdit2.Lines.Count;
- StringGrid1.RowCount := nMaxLine+1;
- StringGrid1.Cells[1,0] := sSource;
- StringGrid1.Cells[2,0] := sTarget;
- for I := 0 to nMaxLine do begin
- Application.ProcessMessages;
- StringGrid1.Cells[0,I+1] := IntToStr(I+1);
- StringGrid1.Cells[1,I+1] := '';
- StringGrid1.Cells[2,I+1] := '';
- StringGrid1.Cells[3,I+1] := '';
- if ChkIgnoreLines.Checked and (RichEdit1.Lines.Strings[I] = '')
- and (RichEdit2.Lines.Strings[I] = '') then
- Continue;
- if (I <= RichEdit1.Lines.Count) then
- StringGrid1.Cells[1,I+1] := RichEdit1.Lines.Strings[I];
- if (I <= RichEdit2.Lines.Count) then
- StringGrid1.Cells[2,I+1] := RichEdit2.Lines.Strings[I];
- if (I <= RichEdit1.Lines.Count) and (I <= RichEdit2.Lines.Count) then begin
- if (RichEdit1.Lines.Strings[I] <> RichEdit2.Lines.Strings[I]) then
- StringGrid1.Cells[3,I+1] := RichEdit1.Lines.Strings[I];
- end
- else
- begin
- if (I <= RichEdit1.Lines.Count) and (I > RichEdit2.Lines.Count) then
- StringGrid1.Cells[3,I+1] := RichEdit1.Lines.Strings[I]
- else
- if (I > RichEdit1.Lines.Count) and (I <= RichEdit2.Lines.Count) then
- StringGrid1.Cells[3,I+1] := RichEdit2.Lines.Strings[I];
- end;
- end;
- end;
-
- procedure TFrmCompareFile.Button2Click(Sender: TObject);
- begin
- FrmMenu.OpenDialog1.Title := 'Select file';
- FrmMenu.OpenDialog1.Filter := 'Any file (*.*)|*.*';
- if FrmMenu.OpenDialog1.Execute then
- Edit2.Text := FrmMenu.OpenDialog1.FileName;
- end;
-
- procedure TFrmCompareFile.FormClose(Sender: TObject;
- var Action: TCloseAction);
- begin
- Action := caFree;
- end;
-
- procedure TFrmCompareFile.FormCreate(Sender: TObject);
- begin
- StringGrid1.ColWidths[1] := (StringGrid1.Width + StringGrid1.DefaultColWidth) div 3;
- StringGrid1.ColWidths[2] := (StringGrid1.Width + StringGrid1.DefaultColWidth) div 3;
- StringGrid1.ColWidths[3] := (StringGrid1.Width + StringGrid1.DefaultColWidth) div 3;
- end;
-
- procedure TFrmCompareFile.Edit1Change(Sender: TObject);
- begin
- if lFileLstChg then
- Exit;
- try
- DirectoryListBox1.Directory := ExtractFilePath(TEdit(Sender).Text);
- except
- ;
- end;
- { try
- if (UpperCase(FileListBox1.Directory) <> UpperCase(ExtractFilePath(TEdit(Sender).Text))) then
- FileListBox1.Directory := ExtractFilePath(TEdit(Sender).Text);
- except
- ;
- end;}
- // FileListBox1.Mask := '*' + ExtractFileExt(Edit1.Text);
- if (TEdit(Sender).Name = 'Edit1') then
- SearchFile(FileListBox1,ExtractFileName(TEdit(Sender).Text),TEdit(Sender))
- else
- SearchFile(FileListBox2,ExtractFileName(TEdit(Sender).Text),TEdit(Sender));
- end;
-
- procedure TFrmCompareFile.FileListBox1Change(Sender: TObject);
- begin
- if (UpperCase(Edit1.Text) <> UpperCase(FileListBox1.FileName)) and
- not lEditBox then
- Edit1.Text := FileListBox1.FileName;
- end;
-
- procedure TFrmCompareFile.FileListBox2Change(Sender: TObject);
- begin
- if (UpperCase(Edit2.Text) <> UpperCase(FileListBox2.FileName)) and
- not lEditBox then
- Edit2.Text := FileListBox2.FileName;
- end;
-
- procedure TFrmCompareFile.FileListBox1Enter(Sender: TObject);
- begin
- lFileLstChg := True;
- end;
-
- procedure TFrmCompareFile.FileListBox1Exit(Sender: TObject);
- begin
- lFileLstChg := False;
- end;
-
- procedure TFrmCompareFile.FileListBox2Enter(Sender: TObject);
- begin
- lFileLstChg := True;
- end;
-
- procedure TFrmCompareFile.FileListBox2Exit(Sender: TObject);
- begin
- lFileLstChg := False;
- end;
-
- procedure TFrmCompareFile.Edit1Enter(Sender: TObject);
- begin
- if (TEdit(Sender).Name = 'Edit1') then
- DirectoryListBox1.FileList := FileListBox1
- else
- DirectoryListBox1.FileList := FileListBox2;
- lEditBox := True;
- end;
-
- procedure TFrmCompareFile.Edit1Exit(Sender: TObject);
- begin
- lEditBox := False;
- lTextDeleting := False;
- end;
-
- procedure TFrmCompareFile.ResourceToText(sResFile, sOutFile : String);
- var
- StreamIn, Streamout : TMemoryStream;
- begin
- StreamIn := TMemoryStream.Create;
- StreamOut := TMemoryStream.Create;
- StreamIn.LoadFromFile(sResFile);
- ObjectResourceToText(StreamIn,StreamOut);
- StreamOut.SaveToFile(sOutFile);
- StreamIn.Free;
- StreamOut.Free;
- end;
-
- procedure TFrmCompareFile.SearchFile(FileListBox : TFileListBox; sFile : String; Edit : TEdit);
- var
- I, nStart : Integer;
- sDeli : String;
- begin
- if lTextDeleting then
- Exit;
- try
- for I := 1 to DirectoryListBox1.Items.Count - 1 do begin
- if (Copy(UpperCase(DirectoryListBox1.Items.Strings[I]),1,Length(sFile)) = UpperCase(sFile)) and
- (sFile <> '') then begin
- DirectoryListBox1.ItemIndex := I;
- if (Copy(DirectoryListBox1.Directory,Length(DirectoryListBox1.Directory),1) <> '\') then
- sDeli := '\'
- else
- sDeli := '';
- DirectoryListBox1.Directory := DirectoryListBox1.Directory + sDeli + DirectoryListBox1.Items.Strings[I];
- nStart := Edit.SelStart;
- Edit.Text := DirectoryListBox1.Directory;
- Edit.SelStart := nStart;
- Edit.SelLength := Length(Edit.Text);
- Break;
- end;
- end;
- except
- ;
- end;
- try
- for I := 0 to FileListBox.Items.Count - 1 do begin
- if (Copy(UpperCase(FileListBox.Items.Strings[I]),1,Length(sFile)) = UpperCase(sFile)) and
- (sFile <> '') then begin
- FileListBox.ItemIndex := I;
- nStart := Edit.SelStart;
- if (Copy(FileListBox.Directory,Length(FileListBox.Directory),1) <> '\') then
- sDeli := '\'
- else
- sDeli := '';
- Edit.Text := FileListBox.Directory + sDeli + FileListBox.Items.Strings[I];
- Edit.SelStart := nStart;
- Edit.SelLength := Length(Edit.Text);
- Break;
- end;
- end;
- except
- ;
- end;
- end;
-
- procedure TFrmCompareFile.Edit1KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- lTextDeleting := (Key = 8) or (Key = 46);
- if (Key = 38) then begin
- lEditBox := False;
- if ((FileListBox1.ItemIndex - 1) >= 0) then
- FileListBox1.ItemIndex := FileListBox1.ItemIndex - 1;
- lEditBox := True;
- end;
- if (Key = 40) then begin
- lEditBox := False;
- if ((FileListBox1.ItemIndex + 1) <= FileListBox1.Items.Count) then
- FileListBox1.ItemIndex := FileListBox1.ItemIndex + 1;
- lEditBox := True;
- end;
- end;
-
- procedure TFrmCompareFile.Edit2KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- lTextDeleting := (Key = 8) or (Key = 46);
- if (Key = 38) then begin
- lEditBox := False;
- if ((FileListBox2.ItemIndex - 1) >= 0) then
- FileListBox2.ItemIndex := FileListBox2.ItemIndex - 1;
- lEditBox := True;
- end;
- if (Key = 40) then begin
- lEditBox := False;
- if ((FileListBox2.ItemIndex + 1) <= FileListBox2.Items.Count) then
- FileListBox2.ItemIndex := FileListBox2.ItemIndex + 1;
- lEditBox := True;
- end;
- end;
-
- end.
-