Solved

Delphi 2010 AnsiString StrAlloc

Posted on 2013-06-24
2
955 Views
Last Modified: 2013-06-24
Good morning,

I'm trying to allocate memory of a given size for an AnsiString, but cannot find a method to do it because StrAlloc now only works with WideString types. What can I do to allocate an AnsiString of given size?
0
Comment
Question by:PlawCoder
  • 2
2 Comments
 
LVL 5

Expert Comment

by:truinx
ID: 39271717
var
  string1, string2 : AnsiString;
begin
  // Assign a famous sentence to the first string
  string1 := 'Hello World';

  // Assign to the second string
  // This simply points string2 at string1
  // The 'Hello World' string storage has a reference count of 2
  string2 := string1;

  // Add to the second string
  // This disassociates from string1 - new string storage is
  // created to hold the string2 value
  string2 := string2 + ', how is everyone?';

  // And finally, set the length of the first string to 5
  SetLength(string1, 5);

  // Display both strings
  ShowMessage('String1 = '+string1);
  ShowMessage('String2 = '+string2);
end;
0
 
LVL 5

Accepted Solution

by:
truinx earned 500 total points
ID: 39271718
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

759 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