Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to ad my class in unit

Status
Not open for further replies.

Spent

Programmer
Mar 20, 2003
100
BG
Can you tell me how to add my custom class in the project and the to create an object from that class
Thanks

Spent
mail:teknet@mail.orbitel.bg
 
Take a look at faq102-4839 which shows you how to develop a simple component and include it in the component palette of the IDE.

If you don't want your custom class to appear on the component palette then take the following steps.

1) Create a new unit for your custom class. Let's call the customer class TCustom. Let's call the unit uCustom.

2) Write your code for TCustom in the uCustom unit.

3) Add uCustom to a uses statement to the units of your project which are going to refer to TCustom.

4) When you need to create an object of TCustom you simply call the constructor:
Code:
var
  objCustom: TCustom;
  ...
begin
  ...
  objCustom := TCustom.Create;
  try
    ...  // code that uses objCustom
  finally
    objCustom.Free;
  end;
end;
It is good practice to use the try...finally construct to ensure that the resources used by your object and freed when the object comes to the end of its life.

Andrew
Hampshire, UK
 
This is part of a rain animation I wrote.
it will give you some of the basics of OOP class set up

{ This is the heart of any OOP Program here we define a Raindrop
Public and Private are more meaningful here, we could access the X,Y coord directly
if they were Public but that is not considered good OOP practise, it's called data hiding
}

type TDrops = class(Tobject) // so it Decends from a TObject (known as Inheritance)
Image: TImage;
private
Icons: array [0..4] of TIcon; // holds the different Drop icons
FallSpeed: Integer;
SplatSpeed: integer;
SplatIndex: Integer;
SplatTimer: integer;
X,Y: integer;
FloorLevel: integer;
CeilingLevel: integer;
Shown: Boolean;
Kill: boolean;
public // mostly these give external access to the Drops Private variables
Stopped: boolean;
constructor CreateDrop(ISpeed,IIndex,IX,IY: integer;
FLevel,CLevel: integer;
TParent: TWinControl); // all OOP objects must have a constructure
destructor DestroyDrop;
procedure AssignImage(I: integer);
procedure SetSpeed(NSpeed: integer);
procedure SetSplatRate(NSpeed: integer);
function GetSpeed: integer;
procedure Position(IX, IY: integer);
function GetY: integer;
function GetX: integer;
procedure Fall;
procedure ShowDrop(Hide: Boolean);
end;


var
DropModule: TDropModule;
Drip: array[0..10] of TDrops; // an array to hold the drops (we can have max 10 in fact)
number: integer;
implementation
{$R *.DFM}
{ the following functions and procedure all relate to a particular drop whichever
one we are referencing from the array they are Part of the drop object}

{ The constructers main job is to set up the variables}
constructor TDrops.CreateDrop(ISpeed, IIndex,IX,IY: integer;
FLevel,CLevel: integer;
TParent: TWincontrol);
var a: integer;
begin
inherited Create; // so we can 'create' a drop not a general TObject
FallSpeed := Ispeed;
SplatSpeed := FallSpeed;
SplatTimer := SplatSpeed;
SplatIndex := IIndex;
X := IX;
Y := IY;
FloorLevel := FLevel;
CeilingLevel := CLevel;
Shown := False;
Stopped := True;
Kill := False;
for a := 0 to 4 do
begin
Icons[a] := Ticon.create; // create the icon array and load it
DropModule.DropImages.GetIcon(a, Icons[a]);
end;

Image := TImage.Create(Image); // make somwhere for the icon to go !!
with Image do
begin
AutoSize := True;
Top := Y;
Left := X;
Picture.Icon := Icons[SplatIndex];
Visible := Shown;
parent := TParent;
end;

end;

Steve
Be excellent to each other and Party on!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top