?
Solved

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

Posted on 2003-03-13
9
Medium Priority
?
234 Views
Last Modified: 2010-04-04
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;

0
Comment
Question by:gretzky_owns_u
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:steve_hsk
ID: 8129403
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
 
LVL 2

Expert Comment

by:BorlandMan
ID: 8133963

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
 
LVL 12

Expert Comment

by:andrewjb
ID: 8135447
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:steve_hsk
ID: 8137719
Andrew ...

Good point : I'm getting my C++ and Delphi confused :-)
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 8137809
Tell me about it!

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

DAMN!!

^h^h^h^h^h

{

better!
0
 
LVL 2

Accepted Solution

by:
BorlandMan earned 120 total points
ID: 8139172
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
 

Expert Comment

by:CleanupPing
ID: 9316796
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question