Marco Cantù 1998, Mastering Delphi 4
Project: STRREF.DPR
Project Structure
STRREF.DPR
program StrRef;
uses
Forms,
StrRefF in 'StrRefF.pas' {FormStrRef};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TFormStrRef, FormStrRef);
Application.Run;
end.
STRREFF.PAS
unit StrRefF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TFormStrRef = class(TForm)
BtnAssign: TButton;
BtnChange: TButton;
ListBox1: TListBox;
procedure BtnAssignClick(Sender: TObject);
procedure BtnChangeClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormStrRef: TFormStrRef;
Str1, Str2: string;
implementation
{$R *.DFM}
function StringStatus (const Str: string): string;
begin
Result := 'Address: ' + IntToStr (Integer (Str)) +
', Length: ' + IntToStr (Length (Str)) +
', References: ' + IntToStr (PInteger (Integer (Str) - 8)^) +
', Value: ' + Str;
end;
procedure TFormStrRef.BtnAssignClick(Sender: TObject);
begin
Str1 := 'Hello';
Str2 := Str1;
ListBox1.Items.Add ('Str2 := Str1;');
ListBox1.Items.Add ('Str1 - ' + StringStatus (Str1));
ListBox1.Items.Add ('Str2 - ' + StringStatus (Str2));
BtnChange.Enabled := True;
end;
procedure TFormStrRef.BtnChangeClick(Sender: TObject);
begin
Str1 [2] := 'a';
ListBox1.Items.Add ('Str1 [2] := ''a''');
ListBox1.Items.Add ('Str1 - ' + StringStatus (Str1));
ListBox1.Items.Add ('Str2 - ' + StringStatus (Str2));
end;
end.
STRREFF.DFM
object FormStrRef: TFormStrRef
Left = 197
Top = 124
Width = 481
Height = 252
Caption = 'String References'
Color = clBtnFace
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
PixelsPerInch = 96
TextHeight = 13
object BtnAssign: TButton
Left = 16
Top = 24
Width = 75
Height = 25
Caption = 'Assign'
TabOrder = 0
OnClick = BtnAssignClick
end
object BtnChange: TButton
Left = 16
Top = 56
Width = 75
Height = 25
Caption = 'Change'
Enabled = False
TabOrder = 1
OnClick = BtnChangeClick
end
object ListBox1: TListBox
Left = 104
Top = 24
Width = 337
Height = 177
ItemHeight = 13
TabOrder = 2
end
end
Copyright Marco Cantù 1998