Solved

File access.

Posted on 2000-03-15
16
165 Views
Last Modified: 2010-04-04
Hi,
For example, strings are being continuously input from keyboard.  Is there a way which can store the strings into memory, and only save it into a file, say, strings.txt when the memory has accumulated 10 kbytes?  The strings being entered may contain all ASCII codes, ie. from 0 to 255.  Please don't suggest me to use TMemo or any other components.
Thanks in advance.
0
Comment
Question by:nyt
[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
  • 5
  • 3
  • 2
  • +3
16 Comments
 

Expert Comment

by:johnwa
ID: 2618995
you can use TStream to do it.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2619006
TStringlist?

StringList1[0] := StringList1[0] + NewKey;
IF Length(StringList1[0]) > 10240
THEN
  //Save data

The Neil
0
 

Expert Comment

by:johnwa
ID: 2619012
you can just set all the items's Visible property of the popmenu  to false.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:mike_tipping
ID: 2619023
Sounds like using a string list would be fun (but since that's the underlying part of a TMemo it might not be what you want to do).

You can check the length of the entered struings by using length(tStringlist.text) or some such thing then when it exceeds you limit use TStringList.savetofile.

 
0
 

Author Comment

by:nyt
ID: 2619149
I prefer methods using TStream.  But can I have any sample codes?
0
 
LVL 9

Accepted Solution

by:
ITugay earned 50 total points
ID: 2619157
You can use TFileStream.

var F : TFileStream;
begin
   F := TFileStream.Create('filename.ext',fmCreate);

   ....
   F.Write(YourKey,1);    
   ....

   F.Free;
end;

 You dont need care about buffering. It will buffering your input automatically. And you can append data to exsisting file:

......
   F := TFileStream.Create('filename.ext',fmOpenWrite);
   F.Seek(0,2); // go to the end of file

   ....
   F.Write(YourKey,1);    
   ....

   F.Free;
end;


Best regards,
Igor.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2619178
In the OnCreate method:

stlBuffer := TStringList.Create

In the KeyPress/Up/Down method:

stlBuffer[0] := stlBuffer[0] + <YourKey>;
IF Length(stlBuffer[0]) > 10240
THEN
BEGIN
  AssignFile(data_out);
  ReWrite(data_out);
  WRITELN(data_out, stlBuffer[0]);
  CloseFile(data_out);
  stlBuffer[0] := '';
END;

In the OnDestroy method:

stlBuffer.Free

You can also add a check to the OnDestroy method to save any outstanding key presses

The Neil
0
 

Expert Comment

by:mike_tipping
ID: 2619224
Wouldn't the problem with the FileStream be that it is saving the strings to disk all the time and not bothering about how full the memory part is.

I would do it as per TheNeil but append rather than rewrite.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2619379
I used ReWrite as I read it as meaning that NYT wanted to just output 10Kb to each file. It's swings and roundabouts though

The Neil =:)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2622468
Why using a stringlist? Why not simply using a string?

var stlBuffer : string;

In the KeyPress/Up/Down method:

stlBuffer := stlBuffer + <YourKey>;
IF Length(stlBuffer) > 10240
THEN
BEGIN
  with TFileStream.Create(data_out, fmCreate) do
    try
      Write(pointer(stlBuffer)^, length(stlBuffer));
    finally Free end;
  stlBuffer := '';
END;

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2622812
Madshi is right (as always). Why the hell did I think about using a stringlist? It's just a load of strings when you only need one - d'oh (you idiot Neil)

The Neil
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2622870
:-))
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2622875
All right, all right - don't start gloating

The Neil =;)
0
 

Author Comment

by:nyt
ID: 2635728
This question has a deletion request Pending
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2635775
This question no longer is pending deletion
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2635776
Any answer you has not satisfied?

Igor;)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…
Suggested Courses
Course of the Month8 days, left to enroll

617 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