Solved

Varibles in Delphi

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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