Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6552133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:25:24+00:00 2026-05-25T12:25:24+00:00

This is for Delphi Prism. Say, I have the following enum SET type that

  • 0

This is for Delphi Prism.

Say, I have the following enum SET type that I would like to save into a binary file.

Fruit = (Apple, Banana, Mango, Cherry, Grapes, BlueBerry);
Fruits = set of Fruit;

FruitBasket:Fruits;

with Fruit do
  FruitBasket := [Apple, Mango];

BinaryWriter thefile := new BinaryWriter(File.Create("test.dat"));

thefile.write(FruitBasket);   //<<< raises Error - There is no overloaded method "Write" with these parameters 

thefile.Close;

How do you read and write enum SET Type(Fruit) into a binary file using BinaryWriter? I thought I found the answer to my question in another Stackoverflow question but didn’t.

I think, I mostly have to loop through its elements, but I needed to know if there is a simpler way to do it.

UPDATE: After the first answer, I tried and came to a quick conclusion, which was a huge mistake on my part. Once I had other issues and errors in my program sorted out, my compiler raised errors on the changes I made as suggested by the first and the one and only answer by CK. I am only able to write but not read it back. Compiler keeps saying – “Type mismatch, cannot assign System.SByte to set of Groups.TFeature”

Code on the top is just a example. Below is the actual code:

Here is the Enum type:

  TFeature = (tfUnit,tfSignal,tfAlarm,tfControl,tfMaker,tfViewer,tfTrend,
              tfComm,tfSystem,tfScan,tfShutdown,tfPID,tfMagiKal);

Here is the SET OF type:

  TFeatures = set of TFeature;

Here are the classes:

  TGroup = class
    name:string;
    rwFeatures:TFeatures;
    roFeatures:TFeatures;
    levels:TLevels;
  private

  public
    constructor;
    Method ReadAGrp(bgreader:BinaryReader);
    Method ReadOld(bgreader:BinaryReader);
    Method WriteAGrp(bgwriter:BinaryWriter);
  end;

  TGroupList = class(ArrayList)
  private

  public
    Method ReadGroups(fname:string);
    Method WriteGroups(fname:string);
    Method AddGroup(group1:TGroup);
    Method DeleteGroup(group1:TGroup);
    Method FindGroup(gname:string):TGroup;
  end;

Here is how I am trying to read and write SET OF type into a binary file using Binarywriter:

procedure TGroup.ReadAGrp(bgreader:BinaryReader);
begin
  name:=bgreader.ReadString;
  rwFeatures := TFeature(bgreader.ReadSByte);
  roFeatures := TFeature(bgreader.ReadSByte);
  levels := TLevels(bgreader.readsbyte);
end;

procedure TGroup.ReadOld(bgreader:BinaryReader);
begin
  name:=bgreader.ReadString;
  rwfeatures := TFeature(bgreader.ReadSByte);
  roFeatures := TFeature(bgreader.ReadSByte);
  levels :=TLevels(bgreader.readsbyte);
end;

procedure TGroup.WriteAGrp(bgwriter:BinaryWriter);
begin
  bgwriter.Write(name);
  bgwriter.Write(rwFeatures.toarray);
  bgwriter.Write(roFeatures.ToArray);
  bgWriter.Write(levels.toarray);
end;

If you could answer with example code or actual code, I would appreciated.

In case you didn’t notice, I started a bounty for this question. I really need a working answer. Thanks,

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:25:24+00:00Added an answer on May 25, 2026 at 12:25 pm

    you can serialize it as an array of byte; call .ToArray on your FruitBasket to get it, then use new Fruits(myarrayofbyte) to get it back as a set. Something like:

      var lData := mySet.ToArray();
      bw.Write(lData.Length); // write the length
      bw.Write(lData); // write the bytes
    
      // Reading:
      var lData := bw.ReadBytes(bw.ReadInt32());
      var newSet := new Fruits(lData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have bat-file, that make some operations. How to run this file from Delphi
Using Delphi 2010, let's say I've got a class declared like this: TMyList =
I am working with Delphi Prism and creating and writing into binary file using
I have a delphi 7 form: and my code: when I run this form
I have created below simple testcase in Delphi Prism . When I run the
I'm asking for Delphi native, not Prism(net). This is my code: raise Exception.Create('some test');
Each Delphi's VCL source file has header like this: {*******************************************************} { } { CodeGear
I have a structure like below that needs to be saved and loaded from
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have written an ASP.NET web application (not site) in Delphi Prism. Everything works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.