Solved

sizeof(binary file records) > 255 characters - how to display in memo box?

Posted on 2001-08-09
8
205 Views
Last Modified: 2010-04-06
Heres what I am doing:

I have a typed binary file using the following record type :

 type Tdata = string[255];

  type
    problem = record
      chapter : string[3];
      section : string[3];
      problem : string[3];
      info : Array [0..5] of Tdata;
  end;

My goal here is to have a binary file that holds some records of type problem, but each record needs to be able to store more than 255 characters of data. To do this, my idea was to have an array of string[255]'s which I did using the info part of the problem record type.

When the user types in the information into the memo box, the program checks to see if the length > 255, if it is, it splits the data up into pieces and saves each 255 size piece in one of the indexes in problem.info.  

This works, and when I view the binary file, all of the data is being properly stored there. However, when the user comes back to pull data out of the binary file, it cannot display all of it.

The text property of the memo box is of type string, so it can only store up to 255 characters.  How can I display all of the data in the file in the memo box, or do I have to use something else?

Thanks for the help.
chmod101
0
Comment
Question by:chmod101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6368873
Hi chmod101,

why do not use array of char instead of "array[0..5] of TData"?

type
  problem = record
      chapter : string[3];
      section : string[3];
      problem : string[3];
      info : Array [0..255*5] of char; // it takes the same space
  end;

var
  P: Problem;
  S: String;

begin

  // put data from Memo1 to P.Info
  S := Memo1.Lines.Text;
  move(S[1], P.Info, Length(S));
 
  // get data from P.Info and put it into Memo2
  Memo2.Lines.Text := P.Info;


-----
Igor.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6368888
Hi chmod101,

I forgot to clear P.Info before, sorry, it should be

  S := Memo1.Lines.Text;
  FillChar(P.Info, SizeOf(P.Info), #0); // clear P.Info before put string there
  move(S[1], P.Info, Length(S));

#0 character used as "end of string"

-----
Igor.
0
 
LVL 2

Expert Comment

by:egono
ID: 6368991
Igor is right - but IMHO you should declare the record as packed, because you could run in data aligning problems when you read the data from the file

type
 problem = record packed
     chapter : string[3];
     section : string[3];
     problem : string[3];
     info : Array [0..255*5] of char; // it takes the same space
 end;

in fact this record has a 4 byte aligning, so you did not really need the packed statement

good luck
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chmod101
ID: 6369062
One problem guys, at least I think it is:

The data being typed into the memo box has a length greater than 255 characters. the solution you supplied still relies on copying the data into a string variable. Strings are limited in storage to 255 characters, so everything still gets truncated.

Also, just to make sure this is clear, I dont need to know how to save the data to the binary file - that is working just fine.

I just need to know how to display more than 255 characters in the memo box.

chmod101
0
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 6369090
Hi chmod101,

there are 2 types of strings, short strings and long strings. Short strings can only hold 255 characters, but long strings can hold 2*1024*1024*1024 characters. TMemo.Text is a long string, so it has no (real) limit. Look in the Delphi help file to learn about short/long strings...

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6369890
Why can't you read store your strings as strings, but back you tmemo with a blob in a CDS? You have to convert data back and forth with a function, but it could be done.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6371404
>info : Array [0..255*5] of char; // it takes the same space

Actually this is not true.

array[0..256*5-1] of char

would take the same space.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6371406
I mean

array[0..256*6-1] of char

=)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question