Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could someone PLEASE help me with this really simple request...

Status
Not open for further replies.

TerryK

Technical User
Nov 11, 2001
5
GB
Could someone please give me 4 sample lines of code for the following...

1) Input/output
2) Iteration
2) Rules for constructing identifiers and literals
4) Recursion

If you could explain the lines or link to a site where I can get more info I'd REALLY appreciate it. I need this info to start me off for a college assignment on Delphi programming. I just need someone to start me off, that's all!!! ;o)

Thanks so much guys!

Terry
 
Dephi is object pascal, with lots of fancy features.

The first thing is to read up on pascal.

next look in


they have lots of components for delphi (like plug ins) which enhance delphi, also documentation, help files, sample code and lots more.

I learnt a lot from that site.
 
Like Schu said, start with reading on Turbo Pascal.
The questions you asked are the basics in programming:

input/output (read, write)
iteration (for)

If it is for a college assignment, check out your library.

If you do not have access to a library, spend some money to buy some books, can also be second hand.

Some titles are:

Mastering Turbo Pascal by Douglas Hergert, or look for the books from Steve Wood. I think you could buy these very cheap second hand. They are out of print.
These books are classics and are more then just describing the commands and functions.


A starters book for Delphi would be Sams teach yourself Delphi in 21 days.

Also there are lots of publications in pdf format which come with the Delphi Installation disks, also the Help file has lot of information.


Programming doesn't start with sitting behind the computer and punching on the keyboard. It starts with reading.

Regards



S. van Els
SAvanEls@cq-link.sr
 
Guys, first of all, thanks SO much for replying!!! ;o)

Now, I do have some experience in programming in Turbo Pascal and a (very) basic knowledge in creating programs in Delphi.. however, the part that confuses me is the actual code used in Delphi.

I mean, I know about read line and write line, but when I look at a program from Delphi I can't see anything like that at all, it doesn't look like Pascal to me!?

If somebody could clear me up here, I'd REALLY appreciate it. I've just got out the Sam's Teach Yourself Delphi In 21 Days and downloaded the Delphi help files, so that's a start. Basically, I just need a hand to get me into the basics of all this. You say Delphi programs are written in Object Pascal, so why is it I can't see any similar read and write commands in the Delphi programs for input and output? Am I looking at the wrong thing here??

Anyway, please reply ASAP, I've only got a few more hours to do all this research before turning it all into a presentation that has to be understandable by a novice to programming!!!! :(

Thanks,

Terry
 
Windows is not a console app - so you're not going to readln to read in values and writeln to write out values. Instead you can put an edit box on a form and a button and when they click a button you can get the Edit1.text value out of the edit box.

It seems like maybe the confusion you're having is between console/dos and windows more than the changes in delphi. :)

The other big difference is "objects". Your form is an object, you can add stuff to it (edit boxes, combo boxes, buttons, etc) which become properties of that form. You can handle events like OnClick when the user clicks a button, and do stuff then. Windows is event-driven, and you have lots of events like onKeyPress, onClick, etc. that can give control back to your program. Otherwise windows is in control, letting the user type or click like they can in any windows app. With a console app you basically say readln which gets some input and then write some answers back out.

Hope that helps some. Good luck - baptism by fire is always the best. :)

TealWren
 
Thanks again for replying, though it's cleared up the confusion a bit, I'm still a bit lost to what the actual codes I need are! :(

Let me clarify what it is I have to do..

My class has been given an assignment which we are to do in pairs. Basically, each pair has a certain programming language to do a presentation on - I have to do Delphi.

Now first of all, we have to explain the origins of delphi, that's just research, so no problems there.. but THEN we have to do the following task:

2. Show, and explain in detail, typical simple lines of code for:
a. Input/output
b. Iteration
g. Rules for constructing identifiers and literals
h. Recursion


Now, I've found some GREAT sites to help me out, but first of all I want to confirm something with you...

Am I correct assuming that the following is the correct syntax for input and output?

write ('Type in the input: ');
readln (input);
writeln (Thank you!);


Is that correct? It just seems too easy to be right! :)

Thanks again!

Terry
 
Only for a console application. For a normal delphi app that would give you an error because it doesn't have a "standard out". Do you have a copy of Delphi????

You could use that code after doing File|New Console App. Also, you for got your quotes on thank you. :)


TealWren
 
TealWren, I think this is what I SHOULD be referring to, as it is the delphi (which is the same as Pascal?) code behind all the fancy apps and everything.. so I think it's what's expected.

What would the code be for a delphi app though? Then I'd have to use text boxes to input data and stuff, so that would be really long.. I don't think we'd have to do that.

We do have a copy of Delphi on our college computer but I'm at home atm, so I'm just struggling on my own. But thanks though, you've been very helpful! ;o)
 
Write/Writeln, Read/Readln is still used in Delphi for writing and reading text from files.

However, as for typical lines for input/output I don't think there's such a thing. This question would probably be more relevant to other languages. What you would do in other languages is get all you input/output via the command line which is basically just one big component. However, with Delphi you can do your i/o with a variety of components, such as EditBoxes, ComboBoxes and basically whatever else you got in your typical Windows application.

The concept of properties is pretty important but you can read that up in your Sams book. Basically though, an editbox has a text property which stores a string so you will read the text property for input and assign some text to the text property for output.

Eg.

output
EditBox1.Text := 'Hi';

input
userName := EditBox2.Text;
 
Hi TerryK I also started delphi with sams, there is a paragraph about console applications in which the use of writeln('blabla') is discussed.
A console application is a formless application, and all the checkboxes and other fancy stuff are not available, just plain pascal coding, no drag and drop.

I mentioned the pascal books because as you progress in delphi you will need to write pascal code.

Try to make an application to which ask for 3 numbers, compare them and find out which is the biggest and the smallest .

The editbox you have to convert to a number variable, make to comparison and write the reusult back to your form. This can be done with a tcaption. The examples of bearsite4 can be usefull


Rules for constructing identifiers follow the pascal rules:

This is straight from the Help file, just plain cut and paste
An identifier can be of any length, but only the first 255 characters are significant. An identifier must begin with a letter or an underscore (_) and cannot contain spaces; letters, digits, and underscores are allowed after the first character. Reserved words cannot be used as identifiers.
Since Object Pascal is case-insensitive, an identifier like CalculateValue could be written in any of these ways:

CalculateValue

calculateValue
calculatevalue
CALCULATEVALUE

end of section

Regards

S. van Els
SAvanEls@cq-link.sr
 
Since you have some pascal experience:

Problem : determine the biggest of 2 numbers

In pascal:

begin
//input
write('A = ');
readln(A);
write( B = ');
readln(B);
//comparison & output
if A > B then writeln('A > B')
else
if A = B then writeln('A = B')
else writeln('A < B');
end;


above program can be made with a console application in Delphi, just plain top down processing with no fancy windows stuff.

The big difference in a windows application is that there is no straight forward process flow, the application is waiting for messages or events to happen.

You start with a form, drop 2 editboxes for input, a button for start the processing, and a label for output.


var
Form1: TForm1;
a,b : integer;
You must define your variables A & B

if you double click on the button you have to key in:

procedure TForm1.Button1Click(Sender: TObject);
begin
//input
A:= StrToInt(Edit1.text);
B:= StrToInt(Edit2.text);
//comparison & output
if A > B then Label1.Caption := 'A > B'
else
if A = B then Label1.Caption := 'A = B'
else Label1.Caption := 'A < B' ;
end;

Notice you have to make a conversion StrToInt() string to an integer, since the input of the editbox is a string.

The output writeln is replaced by Label1.caption

The button is necessary to tell the application when to compare.
I hope that this clarify the confusion

S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top