2015/04/21

Delphi XE Regular Expressions 單元中的 Bug

Report #: 87752 TRegEx frees FRegEx while TMatch et al still have a reference to it 這篇中有提到。

在 RegularExpressions 單元有個潛在的bug。 重現的方式也很簡單:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Caption := TRegEx.Match('one two', '\w+').NextMatch.Value;
end;

會發現Button1.Caption變成空白,而不是預期的"one"。

詳細的解說在:
Bug in Delphi XE RegularExpressions Unit.

解決方式如下:
To fix this bug, delete or rename the two RegularExpressions.dcu files and copy RegularExpressions.pas into your source code folder. Make these changes to both the TMatch and TGroupCollection records in this unit:

  1. Declare FNotifier: IInterface; in the private section.
  2. Add the parameter ANotifier: IInterface; to the Create constructor.
  3. Assign FNotifier := ANotifier; in the constructor’s implementation.

You also need to add the ANotifier: IInterface; parameter to the TMatchCollection.Create constructor.

修改完成後,把Debug和Release後的dcu,覆蓋($BDS)\lib\debug(release)目錄同名檔案即可。

附帶說明,在Delphi XE2以後已經修正了這個Bug,如果你有需要,請再留言索取。

參考資料:

沒有留言:

張貼留言