Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 6

Chapter 06 - Project NameValues

Project Structure

NameValues.dpr
program NameValues;

uses
  Forms,
  NameValForm in 'NameValForm.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
NameValForm.pas
unit NameValForm;

interface

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

type
  TForm1 = class(TForm)
    ValueListEditor1: TValueListEditor;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    btnUp: TButton;
    btnDown: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnUpClick(Sender: TObject);
    procedure btnDownClick(Sender: TObject);
    procedure ValueListEditor1StringsChange(Sender: TObject);
  private
    SharedItemProp: TItemProp;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  SharedItemProp := TItemProp.Create (ValueListEditor1);
  SharedItemProp.EditMask := '999;0; ';

  Memo1.Lines := ValueListEditor1.Strings;
  for I := 0 to ValueListEditor1.Strings.Count - 1 do
    ValueListEditor1.ItemProps [I] := SharedItemProp;
end;

procedure TForm1.btnUpClick(Sender: TObject);
begin
  ValueListEditor1.Strings := Memo1.Lines;
end;

procedure TForm1.btnDownClick(Sender: TObject);
begin
  Memo1.Lines := ValueListEditor1.Strings;
end;

procedure TForm1.ValueListEditor1StringsChange(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to ValueListEditor1.Strings.Count - 1 do
    if not Assigned (ValueListEditor1.ItemProps [I]) then
      ValueListEditor1.ItemProps [I] := SharedItemProp;
end;

end.
NameValForm.dfm
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 696
  Height = 480
  Caption = 'NameValues'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 40
    Top = 8
    Width = 76
    Height = 13
    HelpType = htKeyword
    Caption = 'Value List Editor'
  end
  object Label2: TLabel
    Left = 40
    Top = 224
    Width = 55
    Height = 13
    HelpType = htKeyword
    Caption = 'Plain Memo'
  end
  object ValueListEditor1: TValueListEditor
    Left = 40
    Top = 32
    Width = 561
    Height = 169
    Strings.Strings = (
      'one=1'
      'two=2'
      'three=3')
    TabOrder = 0
    OnStringsChange = ValueListEditor1StringsChange
    ColWidths = (
      150
      405)
  end
  object Memo1: TMemo
    Left = 40
    Top = 248
    Width = 561
    Height = 169
    Lines.Strings = (
      'Memo1')
    TabOrder = 1
  end
  object btnUp: TButton
    Left = 248
    Top = 216
    Width = 75
    Height = 25
    Caption = 'Copy Up'
    TabOrder = 2
    OnClick = btnUpClick
  end
  object btnDown: TButton
    Left = 336
    Top = 216
    Width = 75
    Height = 25
    Caption = 'Copy Down'
    TabOrder = 3
    OnClick = btnDownClick
  end
end