Delphi compiler evolves much faster than Delphi documentation, and some language features remain unnamed. Consider the following code snippet:
type MyPChar1 = PChar; MyPChar2 = type PChar; MyPChar3 = ^Char; procedure Test(Ch: PChar); begin end; procedure TForm1.Button4Click(Sender: TObject); var Ch1: MyPChar1; Ch2: MyPChar2; Ch3: MyPChar3; begin Test(Ch1); // Test(Ch2); Error E2008 Incompatible types // Test(Ch3); Error E2010 Incompatible types: 'Unit1.Char' and 'System.Char' end;
The documentation states that MyPChar1 and PChar are identical types, while MyPChar2 and MyPChar3 are distinct; that is why Test(Ch2); and Test(Ch3); lines does not compile. But notice – the compiler issues different error codes. Does it matter?
Consider the next snippet:
procedure Test1(Ch: MyPChar1); begin end; procedure Test2(Ch: MyPChar2); begin end; procedure Test3(Ch: MyPChar3); begin end; procedure TForm1.Button5Click(Sender: TObject); begin Test1('Foo'); Test2('Foo'); // Compiles // Test3('Foo'); Error E2010 Incompatible types: 'MyPChar3' and 'string' end;
The documentation states that PChar type is assignment compatible on input with string literal. It appears that there is a difference in type ‘distinctness’. The type PChar type is somewhat more compatible with PChar than ^Char type.