Solved

Varibles in Delphi

Posted on 2000-03-31
4
252 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
[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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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