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. 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
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.
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.
Your code should therefore be:
converted := number;
Insert(dupe, converted, 4);
Copy
is overkill for a single character. Use []
instead:
dupe := number[4];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.