Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
unit Unit2;
interface
uses
Classes, Windows, SysUtils;
type
TMyObject = class;
TMyOtherObject = class;
TSomeType = (stOne, stTwo, stThree);
TSomeTypes = set of TSomeType;
TMyObject = class(TObject)
private
FSomeData: String;
FSomeTypes: TSomeTypes;
FMyOtherObject: TMyOtherObject;
procedure SetSomeData(const Value: String);
procedure SetSomeTypes(const Value: TSomeTypes);
protected
{ This is for another lesson }
public
constructor Create(SomeParam: String);
destructor Destroy; override;
property MyOtherObject: TMyOtherObject read FMyOtherObject;
published
property SomeData: String read FSomeData write SetSomeData;
property SomeTypes: TSomeTypes read FSomeTypes write SetSomeTypes;
end;
TMyOtherObject = class(TObject)
public
SomeString: String;
SomeInteger: Integer;
end;
implementation
constructor TMyObject.Create(SomeParam: String);
begin
//Create my other object
FMyOtherObject:= TMyOtherObject.Create;
//Set some param data
FSomeData:= SomeParam;
//Set some default values
FSomeTypes:= [stOne, stTwo, stThree];
end;
destructor TMyObject.Destroy;
begin
//Free my other object
FMyOtherObject.Free;
end;
procedure TMyObject.SetSomeData(const Value: String);
begin
FSomeData:= Value;
end;
procedure TMyObject.SetSomeTypes(const Value: TSomeTypes);
begin
FSomeTypes:= Value;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
//Declare object in form's class if it goes hand-in-hand with the form
FMyObject: TMyObject;
public
property MyObject: TMyObject read FMyObject;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
O: TMyOtherObject;
begin
//Next 3 lines are just a trick to show the form before anything is done...
Show;
BringToFront;
Application.ProcessMessages;
//Temporarily create/free an object to save memory...
O:= TMyOtherObject.Create;
try
//Do something with 'O'
O.SomeString:= 'This is some string';
O.SomeInteger:= 2011;
finally
O.Free;
end;
//Create our new object...
FMyObject:= TMyObject.Create('This is some sample parameter');
//Set some default values...
FMyObject.SomeTypes:= FMyObject.SomeTypes - [stThree];
//Get something from our new object
ShowMessage(MyObject.SomeData);
Edit1.Text:= MyObject.SomeData;
if stThree in MyObject.SomeTypes then begin
ShowMessage('Three is selected!');
end else begin
ShowMessage('Three is NOT selected!');
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//Now we have to free our new object
FMyObject.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
end.
object Form1: TForm1
Left = 444
Top = 444
Width = 313
Height = 221
Caption = 'My New Object Sample'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
DesignSize = (
297
183)
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 24
Top = 40
Width = 249
Height = 21
Anchors = [akLeft, akTop, akRight]
TabOrder = 0
end
object Button1: TButton
Left = 80
Top = 88
Width = 121
Height = 33
Anchors = [akLeft, akTop, akRight]
Caption = 'Close'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
OnClick = Button1Click
end
end