Project TESTPROP
Project Structure
TESTPROP.DPR
program TestProp;
uses
Forms,
TestProF in 'TestProF.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
TESTPROF.PAS
unit TestProF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Spin, NumIntf;
// redeclare the interface
const
Class_NumPropServer: TGUID =
'{B165F7A1-DDF9-11D1-B9F1-004845400FAA}';
type
TForm1 = class(TForm)
SpinEdit1: TSpinEdit;
Button1: TButton;
Button2: TButton;
SpinEdit2: TSpinEdit;
Button3: TButton;
Button4: TButton;
Label1: TLabel;
Label2: TLabel;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
Num1, Num2: INumberProp;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
ComObj;
procedure TForm1.FormCreate(Sender: TObject);
begin
// create first object
Num1 := CreateComObject (Class_NumPropServer)
as INumberProp;
Num1.Value := SpinEdit1.Value;
Label1.Caption := 'Num1: ' + IntToStr (Num1.Value);
Button1.Enabled := True;
Button2.Enabled := True;
// create second object
Num2 := CreateComObject (Class_NumPropServer)
as INumberProp;
Label2.Caption := 'Num2: ' + IntToStr (Num2.Value);
Button3.Enabled := True;
Button4.Enabled := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// change
Num1.Value := SpinEdit1.Value;
Label1.Caption := 'Num1: ' + IntToStr (Num1.Value);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// increase
Num1.Increase;
Label1.Caption := 'Num1: ' + IntToStr (Num1.Value);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Num2.Value := SpinEdit2.Value;
Label2.Caption := 'Num2: ' + IntToStr (Num2.Value);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Num2.Increase;
Label2.Caption := 'Num2: ' + IntToStr (Num2.Value);
end;
procedure TForm1.Button5Click(Sender: TObject);
var
Num3: INumberProp;
begin
// create a new temporary COM object
Num3 := CreateComObject (Class_NumPropServer)
as INumberProp;
Num3.Value := 100;
Num3.Increase;
ShowMessage ('Num3: ' + IntToStr (Num3.Value));
end;
end.
TESTPROF.DFM
object Form1: TForm1
Left = 42
Top = 149
Width = 294
Height = 244
Caption = 'TestPrj'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 40
Top = 24
Width = 28
Height = 13
Caption = 'Num1'
end
object Label2: TLabel
Left = 168
Top = 24
Width = 28
Height = 13
Caption = 'Num2'
end
object SpinEdit1: TSpinEdit
Left = 40
Top = 48
Width = 73
Height = 22
MaxValue = 0
MinValue = 0
TabOrder = 0
Value = 22
end
object Button1: TButton
Left = 40
Top = 88
Width = 75
Height = 25
Caption = '&Change'
Enabled = False
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 40
Top = 128
Width = 75
Height = 25
Caption = '&Next'
Enabled = False
TabOrder = 2
OnClick = Button2Click
end
object SpinEdit2: TSpinEdit
Left = 168
Top = 48
Width = 73
Height = 22
MaxValue = 0
MinValue = 0
TabOrder = 3
Value = 22
end
object Button3: TButton
Left = 168
Top = 88
Width = 75
Height = 25
Caption = 'C&hange'
Enabled = False
TabOrder = 4
OnClick = Button3Click
end
object Button4: TButton
Left = 168
Top = 128
Width = 75
Height = 25
Caption = 'N&ext'
Enabled = False
TabOrder = 5
OnClick = Button4Click
end
object Button5: TButton
Left = 88
Top = 176
Width = 105
Height = 25
Caption = 'Compute (Num3)'
TabOrder = 6
OnClick = Button5Click
end
end
|