Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-08-09
8
Medium Priority
?
217 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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