[英]Delphi problems inserting a string, Incompatible types error
procedure TTelephoneNumberConverter.btnConvertClick(Sender: TObject);
var
number: string;
dupe: string;
converted: string;
begin
number := edtInput.Text ;
dupe := Copy(number, 4, 1) ;
converted := Insert(dupe , number , 4 ) ;
pnlOutput.Caption := converted;
end;
Ok guys I just have a quick question regarding Delphi 2010 and inserting strings into other strings. 好的,我只是对Delphi 2010以及将字符串插入其他字符串有一个简单的问题。 The purpose of this small piece of code is to take the 4th character in a specific string and to duplicate it and add it next to the specific character eg 12345 -> 123445 这小段代码的目的是将第四个字符放在特定字符串中,并将其复制并添加到该特定字符旁边,例如12345-> 123445
The only problem is I keep getting an error : 唯一的问题是我不断收到错误消息:
Incompatible types 'string' and 'procedure, untyped pointer or untyped parameter'. 不兼容的类型“字符串”和“过程,无类型的指针或无类型的参数”。
I am probably missing something small and stupid but would appreciate if someone could maybe answer my question. 我可能缺少一些小而愚蠢的东西,但是如果有人可以回答我的问题,我将不胜感激。
Insert
is a procedure that modifies its second argument. Insert
是修改其第二个参数的过程。
Its signature is: 它的签名是:
procedure Insert(Source: string; var Dest: string; Index: Integer);
The compiler error you see occurs because Insert
does not return anything and thus cannot be the rhs of an assignment. 您看到的编译器错误是因为Insert
不返回任何内容,因此不能是赋值的rhs。
Your code should therefore be: 因此,您的代码应为:
converted := number;
Insert(dupe, converted, 4);
Copy
is overkill for a single character. Copy
对于单个角色来说是多余的。 Use []
instead: 使用[]
代替:
dupe := number[4];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.