salex319 wrote:When I do the following I get the error:
Syntax error: Expected "pointer to data (caption)" but "pointer to cdata (?T0)" found SsProV7_Glcd_SsTP.mpas
Code: Select all
type
TDisplayElement=record
top : byte;
left : byte;
caption : ^string[1];
end;
CONST
B1Caption = 'Test';
DisplayElement : array[0..2] of TDisplayElement =
((1,1,@B1Caption),(1,1,@B1Caption),(1,1,@B1Caption));
Is there some way to do this.
Yes, there is some way: typecast the addresses of the const strings ro the correct type:
Code: Select all
program Const_pointers_test;
{ Declarations section }
type
TDisplayElement=record
top : byte;
left : byte;
caption : ^ string[1];
end;
CONST
B1Caption = 'Test';
DisplayElement : array[0..2] of TDisplayElement =
((1,1,^string[1](@B1Caption)), // <--
(1,1,^string[1](@B1Caption)), // <--
(1,1,^string[1](@B1Caption))); // <--
var xxx: TDisplayElement;
begin
{ Main program }
xxx := DisplayElement[0];
xxx := DisplayElement[1];
xxx := DisplayElement[2];
end.
But why not do it the "Pascal"way?:
Code: Select all
program Const_pointers_test_2;
{ Declarations section }
type
TDisplayElement=record
top : byte;
left : byte;
caption : string[10]; // <-- define max string length
end;
CONST
DisplayElement : array[0..2] of TDisplayElement =
((1,1,'Test'),
(1,1,'Test1'),
(1,1,'Test2'));
var xxx: TDisplayElement;
begin
{ Main program }
xxx := DisplayElement[0];
xxx := DisplayElement[1];
xxx := DisplayElement[2];
end.
The above code is much more understandable and easy to use... Of course here all the string in the type definition has to have max length...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)