Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Delphi 2009 Handbook

Project: KeyValueClassic.dproj

Project Structure

KeyValueClassic.dpr
program KeyValueClassic;

uses
  Forms,
  KeyValueForm in 'KeyValueForm.pas' {Form2},
  KeyValueCode in 'KeyValueCode.pas';

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
KeyValueForm.pas
unit KeyValueForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, KeyValueCode;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    kv: TKeyValue;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  kv.Key := 'mykey';
  kv.Value := Sender;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  kv.Value := self; // the form
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
  ShowMessage ('[' + kv.Key + ',' + kv.Value.ClassName + ']');
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  kv := TKeyValue.Create;
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  kv.Free;
end;

end.
KeyValueForm.pas.dfm
object Form2: TForm2
  Left = 0
  Top = 0
  Caption = 'KeyValue'
  ClientHeight = 273
  ClientWidth = 393
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 32
    Top = 32
    Width = 113
    Height = 25
    Caption = 'Set KeyValue'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 32
    Top = 64
    Width = 113
    Height = 25
    Caption = 'Change Value'
    TabOrder = 1
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 32
    Top = 96
    Width = 113
    Height = 25
    Caption = 'Get KeyValue'
    TabOrder = 2
    OnClick = Button3Click
  end
end
KeyValueCode.pas
unit KeyValueCode;

interface

type
  TKeyValue = class
  private
    FKey: string;
    FValue: TObject;
    procedure SetKey(const Value: string);
    procedure SetValue(const Value: TObject);
  public
    property Key: string read FKey write SetKey;
    property Value: TObject read FValue write SetValue;
  end;

implementation

{ TKeyValue }

procedure TKeyValue.SetKey(const Value: string);
begin
  FKey := Value;
end;

procedure TKeyValue.SetValue(const Value: TObject);
begin
  FValue := Value;
end;

end.
HTML file generated by PasToWeb, a tool by Marco Cantù
Copyright 2008 Marco Cantù