Solved

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

Posted on 2001-08-09
8
195 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 109
Find and Replace Stream with 0s 8 57
Delphi inherited method 6 63
I want to use librsync in my Delphi backup application. 3 30
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

15 Experts available now in Live!

Get 1:1 Help Now