0

Hi All,

I am very new to DELPHI PASCAL Programming.
I have imported the TLB file using Component->Import Component. I would like to use the class of the component and call its method.

for that i have declared class object like
type
TSam1 = class(SampleClass)
end;

and called the method of it as

TSam1.DisplayResult();

I am getting "E2076 This form of method call only allowed for class methods." Can anyone please guide me, where i am going wrong.

Thankyou,

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Terry Robinson
0

The problem is that you are referring to the TYPE TSam1 when you call your method. That is only possible if the method is a class method (and if you're a new student, you won't have heard about class methods yet). What you need to do is declare a variable of the type TSam1, create an instance of that type and assign it to the variable and then use the variable to call your method:

var
mySam :TSam1
begin
mySam := TSam1.Create;
mySam.DisplayResult;
end;

PS- why are you declaring TSam1 at all? The way your code reads, it is exactly the same as SampleClass and is unnecessary. Maybe you were attempting to create an instance of SampleClass named TSam1, in which case your syntax was incorrect.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.