Mason Wheeler编写了一个非常好的程序来比较字符串列表,但我不明白如何编写回调程序TStringCompareProc。有人可以帮我把它编译好吗?
type
TStringCompareProc = procedure(const value: string; const data: TObject) of object;
procedure StringListCompare(List1, List2: TStringList; matchProc: TStringEqualProc;
list1Proc, list2Proc: TStringCompareProc; presorted: boolean = false);
Usage:
procedure TForm1.MatchProc(const value: string; const data: TObject);
// match is found between the two lists
begin
//
end;
procedure TForm1.List1Proc(const value: string; const data: TObject);
// when the first list contains a string not in the second list
begin
//
end;
procedure TForm1.List2Proc(const value: string; const data: TObject);
// when the second list contains a string not in the first list
begin
//
end;
procedure TForm1.Compare1Click(Sender: TObject);
var
MatchProc: TStringEqualProc;
List1Proc: TStringCompareProc;
List2Proc: TStringCompareProc;
iValue: string;
iData: ^PString;
begin
iFinalStringList := StringListCompare(iNewFilesStringList, iExistingFilesStringList,
nil, nil, List1Proc(iValue, @iData), List2Proc(iValue, @iData), False); <- [DCC Error] Unit1.pas(1336): E2010 Incompatible types: 'TStringCompareProc' and 'procedure, untyped pointer or untyped parameter'
end;
答案 0 :(得分:2)
您应该只将List1Proc
和List2Proc
作为StringListCompare
的参数。也就是说,写
iFinalStringList := StringListCompare(iNewFilesStringList,
iExistingFilesStringList, nil, nil, List1Proc, List2Proc, False);
而不是
iFinalStringList := StringListCompare(iNewFilesStringList,
iExistingFilesStringList, nil, nil, List1Proc(iValue, @iData),
List2Proc(iValue, @iData), False);