Q: if I write "Font := Canvas.Font" Font is not a pointer to Canvas.Font, Font takes on the properties of Canvas.Font. I want to know how I can make a variable that is a "pointer" to Canvas.Font.
In pointers it would have been:
procedure X( T : TType );
var
vP : ^TType
begin
vP := @T;
{both of the following make changes to T}
T.Size := 10;
vP^.Size := 12;
end;
what I want is:
procedure X( canvas : TCanvas );
var
F : TFont
begin
F := canvas.Font; {<-- ?? assigns copy instead of reference}
{I need both of the following to affect canvas' Font property}
F.Size := 10;
canvas.Size := 12;
end;
Sorry if it isn't clear ... does anyone remember what a pointer is now that Delphi is here?
A: The problem you are seeing is that in your context the variable Font is not a variable of a class, or an instance of a class. It is a property, and the assignment operator (:=) is being translated by the compiler into an Assign type operation by the declaration of that property.
For example this code:
var
MyFontPtr : TFont;
begin
...
MyFontPtr := SomeCanvas.Font;
does result in an address being copied. Whereas this code:
begin
...
with Form1.Canvas do
Font := SomeCanvas.Font;
results in the following code:
Form1.Canvas.SetFont(SomeCanvas.Font);
which 'copies' the data in SomeCanvas.Font to Form1.Canvas.Font.
See also pointers and dynamic memory