create object, pass object as parameter and then run method of object?

I create an object and then I want to pass the object to a function which will retrieve data from a database and then call the objects fill method with the stored procedure dataset as a parameter.  I get abstract error when running the fill method.  Any ideas as to how I can do this?

main
...
var o: TItemGridObj;
o:= TItemGridObj.Create;
if GetMatGridObj(o, 1) then begin
  //do something;
end;
...
function TdtmMaterialCatalogue.GetMatGridObj(
                              AMatGridObj: TItemGridObj;
                              AItemSKey: integer): Boolean;
begin
     Result:= False;
  try
       with spGetMatGridObj do begin
               Close;
      ParamByName('@item_skey').AsInteger:= AItemSKey;
      Open;
      if not Eof then begin
        AMatGridObj.FillRow(spGetMatGridObj);
        Result:= True;
      end;
      Close;
    end;
  except
    on eDB : EDatabaseError do begin
      dtmCommon.EDatabaseErrorDlg(eDB);
    end ;
  end;
end;

LVL 1
gretzky_owns_uAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

steve_hskCommented:
Hi Gretzky ...

This is a slight guess, but when you pass a class or object as a function argument, if you pass the whole object you are making a copy of it. If the orginal should change in ANY way, then the copy does not reflect these changes.

A better method would be to pass the object by either reference, or by pointer.

By reference, you simply need to include the VAR keyword in the function declaration/defination :

function TdtmMaterialCatalogue.GetMatGridObj(
                          VAR AMatGridObj: TItemGridObj;
                          AItemSKey: integer): Boolean;

By pointer, I'd suggest declaring a pointer type firstly, and passing this as the argument :

TYPE TP_ItemGridObj = ^TItemGridObj;

// Constructor stuff ...
p_AMatGridObj: TP_ItemGridObj;
NEW(p_AMatGridObj0;
p_AMatGridObj := TP_ItemGridObj.Create;

function TdtmMaterialCatalogue.GetMatGridObj(
                           p_AMatGridObj: TP_ItemGridObj;
                          AItemSKey: integer): Boolean;

and in the Destructor : p_AMatGridObj.Free;

As a side note, this should also make the function much quicker, and it will reduce the memory used too !

Hope this helps,
Steve
0
BorlandManCommented:

good suggestion there steve, but I don't think the parameter passing is a problem.

my question is spGetMatGridObj
where does that get created and where is that coming from? Maybe that's what's throwing the error?

hth,
J
0
andrewjbCommented:
Steve,

If TItemGridObj is a class (and not just a record) then what you've said is actually wrong - Delphi deals in points to objects, not 'real' objects. You don't need to indirect to a pointer.

e.g.

var o : TItemGridObj

gives you a variable 'o' which is actually a _pointer_ to a TItemGridObj. THat's why you need to assign something to it before using i.e via

o := tItemGridObj.Create;

I suspect BorlandMan is right, or alternatively, what is the definition of TItemGridObj? Abstract method errors indicate a base class with a virtual; abstract; method in. You can't create objects of classes like this.... Maybe we need to see TItemGridObj??
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

steve_hskCommented:
Andrew ...

Good point : I'm getting my C++ and Delphi confused :-)
0
andrewjbCommented:
Tell me about it!

for ( int i = 0 ; i < count ; i++ )
begin

DAMN!!

^h^h^h^h^h

{

better!
0
BorlandManCommented:
Yeh, but you can try to create one.

I don't think delphi complains about an abstract class - like doesn't compile... but at runtime it barfs.

oh well.

J
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
gretzky_owns_u:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.