Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Strings, Pointers, Arrays, and .Text

Posted on 1997-03-12
7
Medium Priority
?
150 Views
Last Modified: 2010-04-04
What is the actual difference between each of these data types and how are they used, and most important, how do I convert between each of them?  Also, which type do I use for passing 'C' type strings to a dll?
0
Comment
Question by:ocurance
[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
  • 7
7 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 100 total points
ID: 1334772
Object Pascal (Delphi) implements two types of strings, String and PChar.

String is not supported in C.
PChar is.  PChar's are equivalent to char * in C.  In other words, a null-terminated string.

if you have C function like this:

  void SomeFunc(int A, int *B, char *C)

the equivalent in Delphi would be:

  procedure SomeFunc(A: Integer; var B: Integer; C: PChar);

Why use the var you may ask?  Well, in the C call, int *B is requesting that address of the integer B.  It will also let you return a value from the procedure through B.  In Delphi, a var parameter is equivalent.  In most instances, Delphi will pass the actual value to a procedure...by using a var, you are forcing Delphi to pass the address of that value.

That is all a pointer is...an address reference to that actual value.  If you have this Delphi syntax:
 
   var
     B: Integer;
     C: ^Integer;
   begin
     B := 15;
     C := @B;
   end;

B holds an actual value.  That value has to be stored in memory somewhere.  C is an address in memory.  It could be any size space, but when C is dereferenced, it will pull out a number of bytes, starting at its address, equal to the length of an Integer.  The @ symbol means the address of the variable.  Therefore C := @B, means that C now points to the address of B value, 15.  If you dereferenced C, like this:

   lblLabel1.Caption := IntToStr(C^);

the label would now show the value 15.  C^, means go to my address and get me the a value based on the type of pointer I am, in this case a pointer to an integer.

As for converting...there are specific functions to convert between string and pchar.  See the Delphi help file under String Manipulation Routines.

The .Text of most components is of type string, therefore you have to convert most other types to string before you can store a value in a .Text property.  I showed you one above, where we converted an Integer to a String via the IntToStr function.

Hopefully this clears some things up.  Feel free to send more comments.

0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334773
I mistakingly said that the .Text of MOST components is of type string.  I meant to say that the .Text of ALL components, that have a .Text property, is of type string.
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334774
Did I supply all the information you wanted?  If not, feel free to comment.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:mheacock
ID: 1334775
Did you want to grade this or reject it?
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334776
Do you think you can grade this now?  Or reject it?
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334777
Hello??  Anyone there?
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1334778
Did this help?  If you could grade this it would be appreciated.  Thanks.  If you need further assistance, just add a comment and I will answer shortly.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

705 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