Results 1 to 2 of 2

Thread: Saving my classes into Stream

  1. #1

    Saving my classes into Stream

    I am creating a class of TMonsters uses for my RPG game,
    and then make a component that having a property called Monsters which is a TCollection of TMonsters ...

    I am tryoig to save the whole collection into stream or file but never successfull, here's my code :

    TMonsterCollection = class(TComponent)
    private
    FMonsters : TBattleMonsters; //it is a collection of TMonsters
    public
    Constructor create(Aowner : TComponent); Override;
    procedure SaveToStream(Stream: TFileStream);
    procedure SaveToFile(AFileName: String);
    procedure LoadFromStream(Stream: TFileStream);
    procedure LoadFromFile(FileName: String);
    published
    property Monsters : TBattleMonsters read FMonsters write FMonsters;
    end;


    procedure TMOnsterCollection.SaveToStream(Stream: TFileStream);
    begin
    Stream.WriteComponentRes('ABCDE', Self);
    end;

    procedure TMOnsterCollection.SaveToFile(AFileName: String);
    var
    Stream : TFileSTream;
    begin
    Stream := TFileStream.Create(AFileName, fmCreate);
    try
    SaveToStream(Stream);
    finally
    Stream.Free;
    end;
    end;

    Any vision please .... :cry:
    -= ysundawa =-

  2. #2
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Saving my classes into Stream

    The way I do it is as follows

    TMonsterRec = Record
    Name, Type : Stirng;
    End;

    TMonster = Class
    Data : TMonster;
    End;

    Load monsters

    While not File.eof do
    Begin
    Monster := TMonster.Create;
    Read(File,Monster.TMonster);
    End;
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •