Solved

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

Posted on 2001-08-09
8
193 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
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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now