Solved

Varibles in Delphi

Posted on 2000-03-31
4
248 Views
Last Modified: 2010-04-04
Hellofrom java i have started learning delphi.
In java i use varibles like this :
t = Text.getText();

so then i could do things like text.setText(t);

How do i do this in delphi?
0
Comment
Question by:dvd99
4 Comments
 
LVL 2

Expert Comment

by:rene100
ID: 2674759
hi..

I'm not sure what you want to do:

if you want to assign a value to a variable, then use:

number:=12345 (if number is an integer)
or
text:='hello' (if text is a string)

if you want to get the value of a variable, then you simple use something like this: showmessage('your text is:'+text);...that gives you a messagebox with the value of the text-variable.

hope this helps

rene
0
 
LVL 4

Expert Comment

by:Radler
ID: 2674760
What kind of class is "Text" ?
0
 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
ID: 2675132
dvd99,

In Java, strings (aka TEXT) are wrapped in a class, and everytime you want to handle a string, you have to resort to that class.

In Delphi, things are a bit different. There's no class STRING or TEXT. String, in Delphi, is a TYPE, just like an integer, real/float, etc. Therefore, functions can handle it directly, and operators also apply to handling string.

Below are some example of applying functions and operators to a string type variable:

in Java:
t = Text.getText();

in Delphi:
simply declare the variable of type strig in the VAR section of the unit/function:

var
  s : string;

-----

in Java:
text.setText(t);

in Delphi:
use direct assignment:

t := 'any text you want';
or
t := s; { s is another string variable }

Other examples (using string-handling procedures/functions):

t := 'Hello world!';
S := Copy(t, 7, 2);  { copies 2 chars from T into S, starting at pos 7 }

SetLength(T, 5); { truncates T to 5 chars ('Hello' in this case) }



The Delphi help files cover this issue thouroughly, and I strongly advise you to read some of it (the topic is called "String handling routines").

I also would like to suggest a couple books:
"Delphi 5 Unleashed", by Charlie Calvert
"Delphi 5 Developers Guide", by Steve Texeira and Xavier Pacheco

both books are published by Sams Publishing.

There aren't many similarities between Delphi and Java when string varibles are concerned. You can, however, use all the knowledge you've acquired with Java on OOP, and apply that knowledge to Delphi.

Yours,

Alex


0
 
LVL 1

Author Comment

by:dvd99
ID: 2676776
Thanks guys you both helped heaps!!
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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

17 Experts available now in Live!

Get 1:1 Help Now