Solved

Varibles in Delphi

Posted on 2000-03-31
4
247 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
Comment Utility
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
Comment Utility
What kind of class is "Text" ?
0
 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
Comment Utility
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
Comment Utility
Thanks guys you both helped heaps!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

16 Experts available now in Live!

Get 1:1 Help Now