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

x
?
Solved

Long strings

Posted on 1999-06-28
9
Medium Priority
?
152 Views
Last Modified: 2010-04-06
How do I use long strings? I want to assign a sting that is more than 255 chars long to a variable. I have tried AnsiString and WideString. I also added the {$H+} parameter under implementation, but it always says “[Error] : String literals may have at most 255 elements”.
0
Comment
Question by:volavy
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1384879
Which Delphi version do you have? You need at least Delphi2. Then you should simply use this:

var test : string;
begin
  setLength(test,1000);

Regards, Madshi.
0
 

Author Comment

by:volavy
ID: 1384880
It doesn't work (Delphi 4). I am completely confused.

Even
  var s : string[1000]
begin...

doesn't work. Is there an option in the menus I've missed?
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1384881
In D3, {$H+} is the default setting. No problem even for the following code:
procedure TForm1.Button1Click(Sender: TObject);
var s, x: string;  i: Integer;
begin
  s:= '';
  for i:= 1 to 255 do
    s := s + char(i);
  s := s + #13 +'999';
  x := s;
  Showmessage(s);
end;

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
viktornet earned 90 total points
ID: 1384882
volvay, in D4, the strings are actually long...

var
  str : string; //this is a long string
begin
  str := 'whatever you want that is longer than 255 chars in length.....................';
  ShowMessage(str);
end;

i guess you're coming from Pascal or somethin ;)

..-=ViKtOr=-..
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1384883
i should've said by default...
0
 

Author Comment

by:volavy
ID: 1384884
It seems that it's no problem using long strings in the way above, but when I use it like

var s :string;
Begin
 s := ‘asfdafasdfasdfdsafsdaff    …. more than 255  char ’

It doesn’t work. Why?

0
 
LVL 15

Expert Comment

by:simonet
ID: 1384885
>Even
>  var s : string[1000]
>begin...

Try this instead:

type
  TString1000 = string[1000];
var
  s : TString1000;
begin
...

(untested)

Alex

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1384886
oh, the thing is that in the editor you cannot have a line longer than 255 chars or something.... that's with the editor... you can change that by doing this...

var
  str : string;
begin
  str := 'a very long line...........'+
            'but it continues here, you know what im saying?'+
            'wow, there is some more... do you see what i''m saying?';
end;

..-=ViKtOR=-..
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1384887
Now I see your problem ....but that is the problem of the editor, not pascal.

Break the literal string into several part of less then 255 characters. It should work.

s := '1234567890123456789012345678901234567890'+
'1234567890123456789012345678901234567890'+
'1234567890123456789012345678901234567890'+
'1234567890123456789012345678901234567890';
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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