Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to concatenate strings in new Delphi (old way no longer works) E2008 Incompatible types

Status
Not open for further replies.

cupboy2013

Programmer
Mar 21, 2013
27
US
Any explanation of why these lines of code are bad? Is something totally different about strings in the new Delphi as compared to Delphi 7?

{ lbx.Items.Add(Dest + '[' + Dest2 + ']'); }
{ TODO: So plus signs are illegal now? How do you concatenate strings?}
lbx.Items.Add(Concat(Dest,'[',Dest2,']')); // this doesn't work either

Here's how the two variables are defined:
Dest: array[0..254] of char;
Dest2: array[0..254] of char;
 
Totally different, in some ways yes. Its the ANSI char thing I guess.



Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
That's just perfectly normal Paranoia everyone in the universe has that: Slartibartfast
 
You can convert each array to a string, then concatenate them
Code:
function CharArrayToString(const Ch: Array of Char): String
begin
   Result := '';
   if Length(Ch) > 0 then
      SetString(Result, PChar(@Ch[0]), Length(Ch));
end;

lbx.items.add(CharArrayToString(Dest)+'['+CharArrayToString(Dest2)+']');
 
Why are you using char arrays instead of the default string type? The listbox.items will accept them, and concatenation should be availble with + operator.
 
This was a Delphi 7 program. Maybe char arrays were the only way it worked back then. Not quite sure. Anyone know?
 
Now I know why. It's because the char arrays are needed to call the Windows API functions this program uses.
 
This is the solution:

lbx.Items.Add(StrPas(Dest) + '[' + StrPas(Dest2) + ']');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top