Solved

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

Posted on 2001-08-09
8
199 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
LAN or WAN ? 11 92
Adoquery sql  left join does not work 25 91
Delphi and Access based Enumeration 9 64
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

803 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