🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #160

D8.NET: Questions on conversion of old code

#160
From: Jeffrey A. Wormsley
Date: Mon, 26 Jan 2004 19:07
78 lines
3976 bytes
I have a unit (once converted to an object, now converted to a class) that 
I have been using since TP days.  It implements a b-tree type file storage 
system.  Most D8.NET apps I am likely to write will need to at least be 
able to read these files, and possibly write them, to maintain backwards 
compatability with older versions.  The problem is that it uses stuff 
that's been deprecated for a while in Delphi, and is apparently not allowed 
at all in .NET.  Perhaps someone here could help me figure out how to 
"udpate" it.

First of all, some background on how it works.  The main methods are as 
follows:

Create(S: String; W: Word);

    	Opens/Creates a file named S with a record length of W.  The file has 
a header that includes the record length, so all subsequent calls will not 
need the record length to be specified.  The header is also stored in the 
private variable section, so it doesn't need to be re-read.  The full heade 
er is:
  THeader = record
   RecSize : Word;
   RecsUsed : LongInt;
   RecsFree : LongInt;
   FirstRec : LongInt;
   NextRec : LongInt;
   LastRec : LongInt;
  end;

Read(L: Longing; Var P);

    	Reads record number L, returning the result in the untyped P

Write(L: Longing; Var P);

    	Writes record number L with the contents of P

GetRec: LongInt;

    	Returns first free record number, creates new record if all records 
used

DelRec(L: LongInt);

    	Marks record number L as deleted, truncates the file if last record in 
file

There are other internal methods, but these show enough of the problems I 
am facing.

The first thing is the "Var P" bits.  This is a generic engine.  Each thing 
that uses it passes it's record structure via the Var P, and each one has a 
different size.  Is this where I would use IntPtr, or TBytes?  How would I 
marshal this?  In this class, or in the classes that are derived from it 
(where the actual record size is known)?

Second is the internal routines use BlockRead and BlockWrite, again using 
the P parameter that gets passed on down to them.  How do I pass this down 
to these routines?  Do I use BinaryWriter to write?  Does StructureToPtr 
play a role here?

The way this was used in the past is that in the derived class' 
initialization routine, I would create the instance passing in the file 
name and the record size.  The create method used Assign to associate a 
file variable to the filename, but the file was only opened when accessed, 
then closed.  My first thought here was to create a Filestream in the 
Create and remark out the open and close code.  But I am worried that the 
garbage collector will reclaim my FileStream when I don't want it to.  I am 
unsure just what the scoping issues are.  The way it is now, the file 
handle would be in scope the entire life of the application, since the 
class was created in the initialization section and freed in the 
finalization section.  As far as I can tell, I shouldn't even have 
initialization/finalization sections anymore.

I would scrap the whole thing and just use a real DB engine, but I have to 
keep backwards compatability with older versions.

TIA,
  Jeff.
Technical Details
Message-ID: <Xns947C99EEA9742jwormsleyatdebitekdo@207.105.83.66>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f94dd,2aec112d28d2cf5e,start
X-Google-Attributes: gidf94dd,public
X-Google-ArrivalTime: 2004-01-26 12:10:33 PST
Newsgroups: borland.public.delphi.nativeapi
Subject: D8.NET: Questions on conversion of old code
From: "Jeffrey A. Wormsley" <jwormsley@nospam.debitek.com>
Message-ID: <Xns947C99EEA9742jwormsleyatdebitekdo@207.105.83.66>
User-Agent: Xnews/06.01.10
NNTP-Posting-Host: 68.152.88.12
Date: 26 Jan 2004 12:07:54 -0700
X-Trace: newsgroups.borland.com 1075147674 68.152.88.12 (26 Jan 2004 12:07:54 -0700)
Lines: 78
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail