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
Solved

Varibles in Delphi

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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