看来很简单的问题,就是如何给一个字符串变量赋值。200分(200分)

  • 主题发起人 主题发起人 火龙真人
  • 开始时间 开始时间
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
a, b: String;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
I: integer;
begin
for i := 1 to 2999 do
a := a + 'A';
a:= a + 'B';
b := a;
Edit1.Text := b;
end;

end.
 
to zhoufujin
$H+我在提文之前就已经试过了,他只是把申明为STRING变量都默认为长字符串
变量是可以承受3000个字符没问题。但是对于常量超过255个元素 与$h+是没有关系的
哎,如之奈何,如之奈何。



 
const
Str1='sdsdf';//大于255可能不行
Str2:String='sdlfklsdfl';//大于30000行不行?试试
 
delphi帮助中的解释如下:
This error message occurs when you declare a string type with more than 255 elements,
if you assign a string literal of more than 255 characters to a variable of type
ShortString, or when you have more than 255 characters in a single character string.

Note that you can construct long string literals spanning more than one line by using
the '+' operator to concatenate several string literals.

program Produce;
var
LongString : string[256]
(*<-- Error message here*)
begin
end.

In the example above, the length of the string is just one beyond the limit.

program Solve;
var
LongString : AnsiString
[red]//仍然不能在一行中超过255个字符,所以要想使用超长字符串,一是用资源文[/red]
[red]//件,二是用运算符+连接,其它没有什么办法[/red]
begin
end.

The most convenient solution is to use the new long strings - then you don't even have
to spend any time thinking about what a reasonable maximum length would be.
 
帮助里说的是2GB都行 不过写成常量却。。。。。那么
就以这句
you don't even have to spend any time thinking about what a reasonable maximum length would be.
结束吧。
不过帖子再留几天看看大家评论
 
对于太长的常量,建议用字符数组来解决
 
字符串不就是字符数组么
 
奇怪,你把它定义成widestring应该就没问题了,怎么会出错
 
看来真是回天无力了,确认是编译器限制了。
 
Const
s='dssssssssssssssssssssssssssssssssdsdsds'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd'
+'sdddddddddddddddddddddddddd';
 
我都试过了,LuJuhe说的是对的,和DELPHI编辑器有关系!
aizb这样做可以!
 
问这个问题其实是为了解决这个问题
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1599989
已经解决了呵呵 结果应以aizb分为最多
呵呵这个写法我也知道的.最后却证明确实是编译器的问题
 
火龙真人:

是3000 or 30000 ?
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
606
import
I
后退
顶部