Solved

Saving Records

Posted on 2001-07-15
6
169 Views
Last Modified: 2010-04-06
I am not a programmer and am working with Delphi 2 to put together a small program for myself as a learning process.

In the program i am using a record structure to keep information together such as:

Type TRList = Record
               LMark   : String[100];
               LText   : array[0..3071] of char;
               LMark2  : String[100];
               LString : String [255]
               LTrue   : Boolean;
               LNum    : Integer;
             end;

LRec:TRList;


Various input within the program is transferred to the record structure via usual means such as:

LRec.LMark:=A;

and so forth.

However with the RichEdit in the program, the text is gathered with a richedit1.lines.text command so that any line formatting is retained.  

it is then transferred to the LText array via the strpcopy(LRec.LText, richedit1.lines.text);

The record is then saved to file with the normal Write command.

Problem:

Only the first 255 characters of the richedit1.lines.text are saved to LText yet the space for the 3072 chars are allocated in the file.

Anyone know how i can solve this?  I shall give more points if required.
0
Comment
Question by:winuser2000
6 Comments
 
LVL 3

Expert Comment

by:Stefaan
Comment Utility
Hi,

Why don't you simply use the YourRichEdit.Lines.SaveToFile and YourRich.Lines.LoadFromFile method.  They should allow you to save the contents of the RichEdit to a file and read them back in from a file.

Best regards,


Stefaan
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Hello

  why you don't change the array of char to string,like :
  LText   : string;
  instead of              
  LText   : array[0..3071] of char;

 it will handle that size and more, or u want fix size to ur project?, can you plz post some of ur code that write to file, or send me ur project at nasman@mogaza.org, and i will looking for ur project

Mohammed Nasman

 
               
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
Comment Utility
Hi,
As far as I remember Delphi 2 has a string type up to 255 chars length. That's why you have got 255 chars copied only. Try the following replacement for strpcopy(LRec.LText, richedit1.lines.text); :

strmove(LRec.LText, PChar(richedit1.lines.text),Length(richedit1.lines.text));

Regards, Geo
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:winuser2000
Comment Utility
Thanks Stefaan but i am using the record structure so i can keep all of the data in one file instead of saving several files.

Mnasman, The record structure does not allow me to change LText to string and it is not a set length by which each record can be set within the file.  I am using the normal Write (f,LRec) command to write the record to the file.
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
I have Delphi 5, and I test that and it works with me
mmm, can you send me a copy of ur project, i will find machine that has delphi2 and will test ur project there, there are many changes happen to delphi from 2 to 5
0
 

Author Comment

by:winuser2000
Comment Utility
Thanks Geo - that answer was short but oh so sweet and it did the trick.

thanks to everyone else that made a comment
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

11 Experts available now in Live!

Get 1:1 Help Now