TurboPower B-Tree Filer and Delphi XE2 - Anyone done it?

穿精又带淫゛_ 提交于 2020-01-05 07:27:47

问题


I might be the last guy on the planet relying on B-Tree Filer but I made the jump from Delphi 2007 to XE2.

After getting over all the AnsiChar and PAnsiChar issues, the code now crashes with a Range Check with zero items on a page.

Is anyone successfully running B-Tree Filer under Delphi XE2? If so, how'd ya do it? :)

Update Range check error here:

procedure IsamUnPack(var Page : IsamPage; KeyL : Word); 
var 
  I, K, S : Word; 
  P : Array [0..0] Of Byte absolute Page; {Real bounds [0..65535]} 
begin 
 K := KeyL + 9; 
 S := Pred (Page.ItemsOnPage) * K + 6; 
 if KeyL <> MaxKeyLen then begin 
    for I := Page.ItemsOnPage downto 2 do begin 
     Move(P[S], Page.ItemArray[I], K); // Range Check error in Warren P's suggestion 
     S := S - K;  
     end; 
 end; 
end; 

While Page.ItemsOnPage should never be zero (the Range Check error is valid here) it may have been caused by data alignment issues. This code, added to BTDEFINE.INC seems to be doing the trick...

{$IFDEF VER230}
{$DEFINE UsingDelphi}
{$ENDIF}

{$IFDEF VER230} {Delphi XE2}
{$A-} {align data on byte boundaries}
{$B-} {short circuit boolean evaluation}
{$H+} {long string support}
{$I-} {suppress I/O checking}
{$J+} {writeable typed constants}
{$P-} {do not allow open string parameters}
{$Q-} {overflow checking off}
{$R-} {range checking off}
{$T-} {no type checked pointers with @}
{$V-} {no var string checking}
{$X+} {extended syntax on}
{$DEFINE Delphi2006}
{$DEFINE Delphi1Plus}
{$DEFINE Delphi2Plus}
{$DEFINE Delphi3Plus}
{$DEFINE Delphi4Plus}
{$DEFINE Delphi5Plus}
{$DEFINE Delphi6Plus}
{$DEFINE Delphi7Plus}
{$DEFINE Delphi2005Plus}
{$DEFINE Delphi2006Plus}
{$ENDIF}

回答1:


I did a quick port, and I currently have it basically working, well enough for the included Delphi demo to work. My first try failed when I overlooked some string -> ansistring changes in the DEMO CODE, which caused the demo code function PadCH to malfunction. After I fixed that, the demo, and underlying library appears functional, at least for reading, but I did not test writing, modifying, and creating files yet. The above file in the demo was created in an earlier version, so at least it's binary-read compatible. I wouldn't be surprised if there were lots of bugs, data corruption issues, and so on, so please do not use this code in production, or if you do, you do so at your own risk.

My work is here: hosted at microsoft skydrive (4.3 megs, ZIP) (filename tpbtreefiler_xe2_v2.zip)

Update Function IsamUnpack is in ISAMWORK.INC.

Update2 It appears that the OP has discovered now that adding some ifdef-version-constant support causes the {$R-} and some alignment flags to be switched on which are also required, for the library to work properly. May I suggest the following different way of declaring in BTDEFINE.INC, that gets around a classic Delphi "break every time we change Delphi compiler versions" by using a comparison that won't break on the next delphi release:

{$IF CompilerVersion > 20.0 } 
{ Keep working from Delphi 2009 UP}
{$DEFINE UsingDelphi}
{$A-} {align data on byte boundaries}
{$B-} {short circuit boolean evaluation}
{$H+} {long string support}
{$I-} {suppress I/O checking}
{$J+} {writeable typed constants}
{$P-} {do not allow open string parameters}
{$Q-} {overflow checking off}
{$R-} {range checking off}
{$T-} {no type checked pointers with @}
{$V-} {no var string checking}
{$X+} {extended syntax on}
{$DEFINE Delphi2006}
{$DEFINE Delphi1Plus}
{$DEFINE Delphi2Plus}
{$DEFINE Delphi3Plus}
{$DEFINE Delphi4Plus}
{$DEFINE Delphi5Plus}
{$DEFINE Delphi6Plus}
{$DEFINE Delphi7Plus}
{$DEFINE Delphi2005Plus}
{$DEFINE Delphi2006Plus}
{$ENDIF}

Update 3 I suspect there are still porting issues in the code, that could cause data loss and data file corruption. Here's an example where the number of records (which should be a number in the range around 50 in my demo app) is being reported as a number > 1 million, which is clearly invalid.




回答2:


Two more items to check

  1. change "string" to "AnsiString"
  2. If target build is 64 bits, your changes won't make it ready yet

Cheers




回答3:


After I had it all working, I found that re-indexing from a XE2 app broke the B-TreeFiler (BTreeFiler) tables with a isam error #10122 ("The page size for the file block is greater then the MaxPageSize"). Here is the fix:

This one needs to be changed in Filer.pas for reindexing to work:

IsamInfoRec = packed Record
    InfoRec : IsamSmallInfoRec;
    DummyFill : AnsiChar; <<<<<<<< Here!
    KeysUsed : LongInt;{Must start on an even offset for C-compatibility}
    PageSizeUsed : Word; {!!.42}
End;

I hope Warren (above) updated his work with this additional fix. I have also posted this one on the TurboPower BTreeFiler SourceForge location.



来源:https://stackoverflow.com/questions/8837159/turbopower-b-tree-filer-and-delphi-xe2-anyone-done-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!