📄 ucomparison.pas
字号:
Compare :Boolean; //if the comparison should be done
begin
if Sender = ListBoxFiles1 then //list of first parsed data clicked?
begin
List := ListBoxFiles1; //get list boxes for first data
Other := ListBoxFiles2;
SubList := ListBoxIdentifiers1;
OtherSubList := ListBoxIdentifiers2;
end
else
begin
List := ListBoxFiles2; //get list boxes for second data
Other := ListBoxFiles1;
SubList := ListBoxIdentifiers2;
OtherSubList := ListBoxIdentifiers1;
end;
if List.ItemIndex = -1 then //no file selected?
SubList.Clear //so no identifiers available
else
begin //get the clicked file
TheFile := TPascalFile(List.Items.Objects[List.ItemIndex]);
//should be filtered and other file selected
if CheckBoxFilterIdentifiers.Checked and (Other.ItemIndex <> -1) then
//save identifiers of selected file
OtherFile := TPascalFile(Other.Items.Objects[Other.ItemIndex]).Idents
else
OtherFile := nil; //no identifiers to filter with
//show the identifiers of the selected file
ShowIdents(TheFile.Idents, SubList, assigned(OtherFile), OtherFile);
if assigned(OtherFile) then //other file selected
//update filter for identifiers of the other selected file
ShowIdents(OtherFile, OtherSubList, True, TheFile.Idents);
Compare := True; //assume a comparison should be made
//other file should automatically be selected?
if CheckBoxAutoFiles.Checked then
begin //search the file
OtherIndex := Other.Items.IndexOf(List.Items[List.ItemIndex]);
if OtherIndex <> Other.ItemIndex then //not currently selected?
begin
Other.ItemIndex := OtherIndex; //select it
//and show identifiers and do the comparison
ListBoxFilesClick(Other);
Compare := False; //comparison already done
end;
end;
//still needs compare and other file also selected?
if Compare and (Other.ItemIndex <> -1) then
begin
ListBoxMessages.Items.BeginUpdate; //begin updating the messages
try
ListBoxMessages.Clear; //clear the list
//and add the messages of the comparison
TheFile.CompareWith(TPascalFile(Other.Items.Objects[Other.ItemIndex]),
'', ListBoxMessages.Items);
finally
ListBoxMessages.Items.EndUpdate; //end updating the messages
end;
end;
end; //else List.ItemIndex = -1
ListBoxIdentifiersClick(SubList); //clear list of members
end;
{Called when the user selects an identifier of a file in one of the two lists.
~param Sender the sender of the event,
~[link ListBoxIdentifiers1] or ~[link ListBoxIdentifiers2] }
procedure TFormComparison.ListBoxIdentifiersClick(Sender: TObject);
var List, Other :TListBox; //clicked list box and the other one
SubList :TListBox; //list box for members
OtherSubList :TListBox; //list for members of the other one
Ident :TIdentifier; //the clicked identifier
OtherIdent :TIdentifierList; //list of identifiers in other data
OtherIndex :Integer; //index of the equal identifier
Compare :Boolean; //if the comparison should be done
begin
if Sender = ListBoxIdentifiers1 then //list of first parsed data clicked?
begin
List := ListBoxIdentifiers1; //get list boxes for first data
Other := ListBoxIdentifiers2;
SubList := ListBoxMembers1;
OtherSubList := ListBoxMembers2;
end
else
begin
List := ListBoxIdentifiers2; //get list boxes for second data
Other := ListBoxIdentifiers1;
SubList := ListBoxMembers2;
OtherSubList := ListBoxMembers1;
end;
if List.ItemIndex = -1 then //no identifier selected?
SubList.Clear //so no members available
else
begin
OtherIdent := nil; //assume no member for other identifier
//other identifier selected?
if CheckBoxFilterMembers.Checked and (Other.ItemIndex <> -1) then
begin
Ident := TIdentifier(Other.Items.Objects[Other.ItemIndex]);
if Ident is TRecordType then //identifier is a record-like type?
OtherIdent := TRecordType(Ident).IdentList; //save its members
end;
//get the clicked identifier
Ident := TIdentifier(List.Items.Objects[List.ItemIndex]);
if Ident is TRecordType then //identifier is a record-like type?
ShowIdents(TRecordType(Ident).IdentList, SubList, //show its members
assigned(OtherIdent), OtherIdent)
else
SubList.Clear; //no members available
if assigned(OtherIdent) then //other list has members?
if Ident is TRecordType then //update its filter
ShowIdents(OtherIdent, OtherSubList, True, TRecordType(Ident).IdentList)
else
ShowIdents(OtherIdent, OtherSubList, False, nil);
Compare := True; //assume a comparison should be made
//other identifier should automatically be selected?
if CheckBoxAutoIdentifiers.Checked then
begin
//get the (first) identifier in the other file
OtherIndex := Other.Items.IndexOf(List.Items[List.ItemIndex]);
if OtherIndex <> -1 then //an identifier found?
//check whether there is a better matching identifier with
while (OtherIndex < Other.Items.Count - 1) and //the same name
(Other.Items[OtherIndex + 1] = List.Items[List.ItemIndex]) and
not Ident.CompareWith(TIdentifier(Other.Items.Objects[OtherIndex]),
'', IgnoreStringList) do
inc(OtherIndex);
if OtherIndex <> Other.ItemIndex then //new identifier selected?
begin
Other.ItemIndex := OtherIndex; //select the identifier
//and updates the list of members and do the comparison
ListBoxIdentifiersClick(Other);
Compare := False; //comparison already done
end;
end;
//still needs compare and other file also selected?
if Compare and (Other.ItemIndex <> -1) then
begin
ListBoxMessages.Items.BeginUpdate; //begin updating the messages
try
ListBoxMessages.Clear; //clear the list
//and add the messages of the comparison
Ident.CompareWith(TIdentifier(Other.Items.Objects[Other.ItemIndex]),
'', ListBoxMessages.Items);
finally
ListBoxMessages.Items.EndUpdate; //end updating the messages
end;
end;
end; //else List.ItemIndex = -1
end;
{Called when the user selects a member in one of the two lists.
~param Sender the sender of the event,
~[link ListBoxMembers1] or ~[link ListBoxMembers2] }
procedure TFormComparison.ListBoxMembersClick(Sender: TObject);
var List, Other :TListBox; //clicked list box and the other one
Ident :TIdentifier; //the clicked member
OtherIndex :Integer; //index of the equal member
Compare :Boolean; //if the comparison should be done
begin
if Sender = ListBoxMembers1 then //list of first parsed data clicked?
begin
List := ListBoxMembers1; //get list boxes for first data
Other := ListBoxMembers2;
end
else
begin
List := ListBoxMembers2; //get list boxes for second data
Other := ListBoxMembers1;
end;
if List.ItemIndex <> -1 then //a member selected?
begin
Ident := TIdentifier(List.Items.Objects[List.ItemIndex]);
Compare := True; //assume a comparison should be made
//other member should automatically be selected?
if CheckBoxAutoMembers.Checked then
begin
//get the (first) member in the other record-like type
OtherIndex := Other.Items.IndexOf(List.Items[List.ItemIndex]);
if OtherIndex <> -1 then //a member found?
//check whether there is a better matching member with the same name
while (OtherIndex < Other.Items.Count - 1) and
(Other.Items[OtherIndex + 1] = List.Items[List.ItemIndex]) and
not Ident.CompareWith(TIdentifier(Other.Items.Objects[OtherIndex]),
'', IgnoreStringList) do
inc(OtherIndex);
if OtherIndex <> Other.ItemIndex then //new member selected?
begin
Other.ItemIndex := OtherIndex; //select the identifier
//and updates the list of members and do the comparison
ListBoxMembersClick(Other);
Compare := False; //comparison already done
end;
end;
//still needs compare and other file also selected?
if Compare and (Other.ItemIndex <> -1) then
begin
ListBoxMessages.Items.BeginUpdate; //begin updating the messages
try
ListBoxMessages.Clear; //clear the list
//and add the messages of the comparison
Ident.CompareWith(TIdentifier(Other.Items.Objects[Other.ItemIndex]),
'', ListBoxMessages.Items);
finally
ListBoxMessages.Items.EndUpdate; //end updating the messages
end;
end;
end; //if List.ItemIndex <> -1
end;
{Called when the state of the check box to filter the files is changed.
~param Sender the sender of the event, ~[link CheckBoxFilterFiles] }
procedure TFormComparison.CheckBoxFilterFilesClick(Sender: TObject);
begin
ListBoxFiles1.Clear; //clear lists so far
ListBoxFiles2.Clear;
ListBoxFilesClick(ListBoxFiles1); //also clear sub-lists
ListBoxFilesClick(ListBoxFiles2);
ShowFiles(FFirstData, ListBoxFiles1, FSecondData); //and show the files again
ShowFiles(FSecondData, ListBoxFiles2, FFirstData);
end;
{Called when the state of the check box to filter the identifiers is changed.
~param Sender the sender of the event, ~[link CheckBoxFilterIdentifiers] }
procedure TFormComparison.CheckBoxFilterIdentifiersClick(Sender: TObject);
var L1, L2 :TIdentifierList; //current lists of identifiers
begin
ListBoxIdentifiers1.Clear; //clear lists so far
ListBoxIdentifiers2.Clear;
ListBoxIdentifiersClick(ListBoxIdentifiers1); //also clear sub-lists
ListBoxIdentifiersClick(ListBoxIdentifiers2);
if ListBoxFiles1.ItemIndex = -1 then //get current lists
L1 := nil
else
L1 := TPascalFile(ListBoxFiles1.Items.Objects[
ListBoxFiles1.ItemIndex]).Idents;
if ListBoxFiles2.ItemIndex = -1 then
L2 := nil
else
L2 := TPascalFile(ListBoxFiles2.Items.Objects[
ListBoxFiles2.ItemIndex]).Idents;
//and show the identifiers again
ShowIdents(L1, ListBoxIdentifiers1,
assigned(L2) and CheckBoxFilterIdentifiers.Checked, L2);
ShowIdents(L2, ListBoxIdentifiers2,
assigned(L1) and CheckBoxFilterIdentifiers.Checked, L1);
end;
{Called when the state of the check box to filter the members is changed.
~param Sender the sender of the event, ~[link CheckBoxFilterMembers] }
procedure TFormComparison.CheckBoxFilterMembersClick(Sender: TObject);
var Ident :TIdentifier; //currently selected identifiers
L1, L2 :TIdentifierList; //current lists of identifiers
begin
ListBoxMembers1.Clear; //clear lists so far
ListBoxMembers2.Clear;
ListBoxMembersClick(ListBoxMembers1); //also clear sub-lists
ListBoxMembersClick(ListBoxMembers2);
L1 := nil; //get current lists
if ListBoxIdentifiers1.ItemIndex <> -1 then
begin
Ident := TIdentifier(ListBoxIdentifiers1.Items.Objects[
ListBoxIdentifiers1.ItemIndex]);
if Ident is TRecordType then
L1 := TRecordType(Ident).IdentList;
end;
L2 := nil; //get current lists
if ListBoxIdentifiers2.ItemIndex <> -1 then
begin
Ident := TIdentifier(ListBoxIdentifiers2.Items.Objects[
ListBoxIdentifiers2.ItemIndex]);
if Ident is TRecordType then
L2 := TRecordType(Ident).IdentList;
end;
//and show the members again
ShowIdents(L1, ListBoxMembers1,
assigned(L2) and CheckBoxFilterMembers.Checked, L2);
ShowIdents(L2, ListBoxMembers2,
assigned(L1) and CheckBoxFilterMembers.Checked, L1);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -