如何修复不兼容的类型

时间:2012-11-21 12:47:43

标签: delphi delphi-2010

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;

1 个答案:

答案 0 :(得分:2)

您应该只将List1ProcList2Proc作为StringListCompare的参数。也就是说,写

iFinalStringList := StringListCompare(iNewFilesStringList,
  iExistingFilesStringList, nil, nil, List1Proc, List2Proc, False);

而不是

iFinalStringList := StringListCompare(iNewFilesStringList,
  iExistingFilesStringList, nil, nil, List1Proc(iValue, @iData),
  List2Proc(iValue, @iData), False);