Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco



Home: Code Repository: Mastering Delphi 5

Project RUNPROP

Project Structure


RUNPROP.DPR

program RunProp;

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

{$R *.RES}

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

RUNPROPF.PAS

unit RunPropF;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Spin;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Button1: TButton;
    ListBox1: TListBox;
    RadioButton1: TRadioButton;
    CheckBox1: TCheckBox;
    ScrollBar1: TScrollBar;
    SpinEdit1: TSpinEdit;
    ComboBox1: TComboBox;
    Bevel1: TBevel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  TypInfo;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
//  PropInfo: PPropInfo;
  Value: Variant;
begin
  ListBox1.Clear;
  for I := 0 to ComponentCount -1 do
  begin
    // Delphi 5 version
    Value := GetPropValue (Components[I], Edit1.Text);
    if Value <> NULL then
      ListBox1.Items.Add (Components[I].Name + '.' +
        Edit1.Text + ' = ' + string (Value))
    else
      ListBox1.Items.Add ('No ' + Components[I].Name + '.' +
        Edit1.Text);

    // pre-Delphi 5 version, limited to strings
{
    // get property RTTI
    PropInfo := GetPropInfo (
      Components[I].ClassInfo, Edit1.Text);
    if PropInfo = nil then
      // if not found output a message
      ListBox1.Items.Add (Descr + ' doesn''t exist')
    else if PropInfo.PropType^.Kind <> tkLString then
      // if not a strign output a message
      ListBox1.Items.Add (Descr + ' is not a string')
    else
      // show the value
      ListBox1.Items.Add (Descr + ' = [' +
        GetStrProp (Components[I], PropInfo) + ']');
}
  end;
end;

end.

RUNPROPF.DFM

object Form1: TForm1
  Left = 200
  Top = 107
  Width = 391
  Height = 280
  Caption = 'RunProp'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 42
    Height = 13
    Caption = '&Property:'
    FocusControl = Edit1
  end
  object Bevel1: TBevel
    Left = 8
    Top = 104
    Width = 145
    Height = 143
  end
  object Edit1: TEdit
    Left = 16
    Top = 32
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Caption'
  end
  object Button1: TButton
    Left = 16
    Top = 64
    Width = 121
    Height = 25
    Caption = '&Fill List'
    TabOrder = 1
    OnClick = Button1Click
  end
  object ListBox1: TListBox
    Left = 160
    Top = 16
    Width = 209
    Height = 225
    ItemHeight = 13
    TabOrder = 2
  end
  object RadioButton1: TRadioButton
    Left = 16
    Top = 112
    Width = 113
    Height = 17
    Caption = 'RadioButton1'
    TabOrder = 3
  end
  object CheckBox1: TCheckBox
    Left = 16
    Top = 136
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 4
  end
  object ScrollBar1: TScrollBar
    Left = 16
    Top = 160
    Width = 121
    Height = 16
    PageSize = 0
    TabOrder = 5
  end
  object SpinEdit1: TSpinEdit
    Left = 16
    Top = 184
    Width = 121
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 6
    Value = 0
  end
  object ComboBox1: TComboBox
    Left = 16
    Top = 216
    Width = 121
    Height = 21
    ItemHeight = 13
    TabOrder = 7
    Text = 'ComboBox1'
    Items.Strings = (
      'one'
      'two'
      'three'
      'four'
      'five')
  end
end