Registering types, please help! 
Author Message
 Registering types, please help!

Hello,

For some reason my company wants me to change the code to compile with
the 7.0 version of Pascal.  The code works correctly in version 5.5.

The changes I've made to compile with 7.0 run all the way through code,
but it's not behaving as it did before. I'm not getting any errors but
I'm 100% positive it's because I'm not registering my type correctly
because this is the only change I've made to the code.  In my code I
declare the following:

{dldlist file}

    tDldStream = object(TdosStream) { in the old code this was just
dosStream }
      procedure registerTypes; virtual;
    end;

    const
      rDldFile: TStreamRec = (
      ObjType: 1500;
      VmtLink: Ofs(TypeOf(tDldFile)^);


    );

type
    tpDldList = ^ tDldList;
    tDldList = object(tListBox)
      s: tDldStream;                                    { here is where
I'm actually using that object }
      constructor init;
      destructor done; virtual;
      procedure insertHeader; virtual;
      procedure delete;
      function  fileDescription(index: word): string;
      procedure insert(iName: str12; iTime, iSize: longint);
      procedure trim;
      function  select: boolean;
      procedure dump;
    end;

    procedure tDldStream.registerTypes;
    begin
      {dosStream.registerTypes;  this is the old 5.5 version of pascal
registering type call, the registerTypes call here belongs to the 5.5
version of the objects.pas file}

this is the 2nd line of the 5.5 version }
      {  I replaced the above lines with the const declaration of
rDldfile and the line below to register that type }
      RegisterType(rDldFile);
    end;

------------------------------

In my list file I have the following:

{list file}
type
    ListPtr = ^List;
    List = object(TObject)
    Last: NodePtr;
    procedure Append(N: NodePtr);
    procedure Clear;
    procedure Delete;
    function Empty: Boolean;
    function First: NodePtr;
    procedure Insert(N: NodePtr);
    procedure Load(var S: TStream);                   {in the old code
this was just Stream but part of the built in objects.pas file  I had to
declare this}
    function Next(N: NodePtr): NodePtr;             { because 7.0
doesn't include this anymore. }
    function Prev(N: NodePtr): NodePtr;
    procedure Remove(N: NodePtr);
    procedure Store(var S: TStream);                   { also stream not
TStream as mentioned above }
    end;

    procedure List.Load(var S: TStream);
    var
      P: NodePtr;
    begin
      Clear;
      P := NodePtr(S.Get);
      while P <> nil do
      begin
        Append(P);
        P := NodePtr(S.Get);
      end;
    end;

    procedure List.Store(var S: TStream);
    var
      P: NodePtr;
    begin
      P := First;
      while P <> nil do
      begin
        S.Put(P);
        P := Next(P);
      end;
      S.Put(nil);
    end;

The above load and store methods should call the methods below.  I've
confirmed that when the old code is run the program actually enters the
above load and store methods then calls the below load and store
methods.

    constructor tDldFile.load;
    begin
      s.read(name, sizeof(name));
      if s.status <> 0 then fail;
      s.read(time, sizeof(time));
      if s.status <> 0 then fail;
      s.read(size, sizeof(size));
      if s.status <> 0 then fail;
      s.read(podType, sizeof(podType));
      if s.status <> 0 then fail;
      s.read(podSn, sizeof(podSn));
      if s.status <> 0 then fail;
      s.read(firstTime, sizeof(firstTime));
      if s.status <> 0 then fail;
      s.read(lastTime, sizeof(lastTime));
      if s.status <> 0 then fail;
      s.read(powerUps, sizeof(powerUps));
      if s.status <> 0 then fail;
      invalid := true;
    end;

    procedure tDldFile.store;
    begin
      s.write(name, sizeof(name));
      s.write(time, sizeof(time));
      s.write(size, sizeof(size));
      s.write(podType, sizeof(podType));
      s.write(podSn, sizeof(podSn));
      s.write(firstTime, sizeof(firstTime));
      s.write(lastTime, sizeof(lastTime));
      s.write(powerUps, sizeof(powerUps));
    end;

I know I'm getting to the into the list file load and store methods with
the 7.0 version but for some reason the get and put methods don't call
the tDldFile store and load methods.  This code with some variation
works in Pascal version 5.5.  So the get and put methods do call it in
that version, but since nothing makes sense here at work and it's not
broken we must fix it.  This version of code compiles using the 7.0
Pascal version, I know big jump.  But, I must do it and I can't get it
to work properly.  The tDldFile load and store methods just don't get
called in 7.0 for some reason, please help me.

THANKS IN ADVANCE!!



Wed, 18 Jun 1902 08:00:00 GMT  
 Registering types, please help!

Quote:
>     procedure tDldStream.registerTypes;
>     begin
>       {dosStream.registerTypes;  this is the old 5.5 version of pascal
> registering type call, the registerTypes call here belongs to the 5.5
> version of the objects.pas file}

> this is the 2nd line of the 5.5 version }
>       {  I replaced the above lines with the const declaration of
> rDldfile and the line below to register that type }
>       RegisterType(rDldFile);
>     end;

Although you register your tDldFile type, I don't see a RegisterType or
TStreamRec declaration for  your "List" object, which has Load and Store
methods, so needs a corresponding TStreamRec.

Can I also suggest you use a "t" or "T" prefix to denote a type, a "p" or "P"
prefix to denote a pointer to a type, and no prefix for actual variables. Such
that:

type
  pList = ^tList;
  tList = object(tObject)
    Last: pNode;
   ....etc
 end;

var
  List: pList;

etc.

IMO, you don't need to distinguish the difference between pointer and
record/object/simple variables in their naming convention, since the compiler
will catch any silly errors you make in the code, such as trying to
dereference a non-pointer, or vice-versa.

Quote:
> I know I'm getting to the into the list file load and store methods with
> the 7.0 version but for some reason the get and put methods don't call
> the tDldFile store and load methods.  This code with some variation
> works in Pascal version 5.5.  So the get and put methods do call it in
> that version, but since nothing makes sense here at work and it's not
> broken we must fix it.  This version of code compiles using the 7.0
> Pascal version, I know big jump.  But, I must do it and I can't get it
> to work properly.  The tDldFile load and store methods just don't get
> called in 7.0 for some reason, please help me.

Without spending half an hour carefully reading your code, I think this is a
classic case of "type [name] confusion". I think you're confusing which object
is doing the storing, and which object(s) are being stored. The former don't
need Load and Store methods, or a TStreamRec, the latter do.

Below, for example, you declare P as a pointer to a Node, but I think you
expect S.Put(P) to call tDldFile.Store. This will only happen if P really
points to a pDldFile. This should only be even possible if  tDldFile is a
decendant of Node. I don't see any declaration for your tDldFile type, only
your tDldStream type, so I don't know if it is or not.

    procedure List.Store(var S: TStream);
    var
      P: NodePtr;
    begin
      P := First;
      while P <> nil do
      begin
        S.Put(P);
        P := Next(P);
      end;
      S.Put(nil);
    end;

On an entirely different note, your tDldFile.Load method is very innefficient
with all those "if S.Status <> 0 then Fail" statements. Also you don't call
the objects inherited Load method (assuming it has one):

    constructor tDldFile.load(var S: TStream);
    begin
      inherited Load(S);
      S.Read(Name, SizeOf(Name));
      S.Read(Time, SizeOf(Time));
      S.Read(etc.., SizeOf(..etc));
      if S.Status <> stOk
       then Fail;
    end;

Even more effecient is loading all the fields with just one Load, but is only
guaranteed to work in TP, and you have to declare all your load/store fields
in consecutive fields of the object:

    constructor tDldFile.load;
    begin
      S.Read(Name, SizeOf(Name) + SizeOf(Time) + SizeOf(etc..));
      if S.Status <> stOk
       then fail;
    end;

You should make a note in source file in or near the object's type declartion
that all the store/load fields must be kept consecutive, and that Name must be
the first of these declared fields.

--
Jay

Jason Burgon - Author of Graphic Vision
New version 2 now available from:
http://www.jayman.demon.co.uk



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Class not registered, Please help me

2. Need Gnu equivalent for type 'Registers'

3. Somerone, Please help me to verify a abstract data type program

4. Please help: Type missmatch

5. HELP : VGA read plane register.

6. DS, ES, FS, GS Registers in TP7.0 *HELP*

7. Help - EOleSysError - class not registered ???

8. HELP - Register ODBC Drivers in Windows

9. Please Please, help me with memo-fields, real problem

10. Please, please help me with this code.

11. please, I beg of you help me please.

12. PLEASE PLEASE HELP ME

 

 
Powered by phpBB® Forum Software