Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

About pointers (basics)

Posted on 2004-04-11
1
Medium Priority
?
173 Views
Last Modified: 2010-04-16
Hi everyone,

i'm following the online tutorial that is found on http://www.geocities.com/codeteacher/ i'm at the second lesson, chapter 1. In the previous lesson we had to write a program able to store a textfile in an array and then writing it on the screen. We had also to provide some "browse" features to allow the user to read the whole text using the arrow keys and the page and page down. I did it (may sound like very usual stuff for you but for me it's more dificult).
the program looks like the following

Procedure OpenReadme;
{Procedure that read the 400 first lines of the textfile into an array}
Procedure WriteHeader;
{Procedure that made a kind of menu bar above}
Procedure PageUp;
Procedure PageDown;
Procedure LinUp;
Procedure LineDown;
Procedure DisplayText;

in the Procedure DisplayText there is somehting like this

TempChar:=Readkey
CASE Ord(TempChar) OF
 85:PageUp;
 48:PageDown;
 32:LineUp;
 25:LineDown;
End;

{Head Program}
BEGIN
 OpenReadme;
 WriteHeader;
 DisplayText;
END.

Well that is the shape of the program, it whole works.
but now in that lesson, we have to make the same program AND store the data using pointers. And that is were i'm stuck right now. I have no idea how i should store it in a pointer.

should i make a pointer-array ?

Type
 PText:^TText;
 TText:Array[1..400] Of String;
Var
 WholeText:PText;

??? no i can't do that because we have to allow the user to see the WHOLE text and not only the 400 first lines

i taught of another solution;
store line by line into a generic pointer, if i understood correctly generic pointer have no type, so it is like the 'variant' type in visual basic. i think it is possible, than we have one dynamic variable containing the whole text file, but how should i use that variable to display the text and allow browsing in it ???

CAN SOMEONE PLEASE HELP ME OUT OF THAT ???

Elvis
0
Comment
Question by:Elvis1
[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
1 Comment
 
LVL 1

Accepted Solution

by:
xtremecris earned 300 total points
ID: 10801275
You could try something like this:
Type
 TText:array[1..100] Of PText;
 PText:^TText;
 TText:Array[1..400] Of String;

That means: there is an array of pointers to a TText structure which you can access more easily with an function like this:

function GetLine(Number:Integer):string;
begin
 GetLine:=TText[((Number-1) div 400)+1]^[((Number-1) mod 400)+1];
end;

You might not understand all the indices, they are correct but harder to explain(you should try with a piece of paper to figure them out for your self).

Everything would be a lot easier to understand and a lot faster and run-time if you do it like this:

Type
 tText : array[0..16383] Of ^String;

When you acces the line N from the file it's simply:
                   tText[N]^

This way you have little modifications to do to your original program and there are 16.384 lines of file in memory.This way it's safe to assume that you can read the whole file in memory, in fact if you use TPascal or BPascal you can't actually hope to read more then this.

If you have more questions don't hesitate to ask.

Best regards,
Cris.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 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