Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-13
9
Medium Priority
?
235 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
  • 2
  • 2
  • 2
  • +1
7 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

581 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