Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-11

Question on OOP programming...

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Hantsch

Hello, everybody!

I have a very interesting problem with my programming and I hope there is somebody here who knows a solution.

I wrote a "Database Unit", which offers a basic oDB object for a special form of text-based databases. This oDB includes currently everything I need for ReadOnly operation. It is kept absolutely neutral, reads the whole database file into a list of string on the heap, and allows to access the fields by name (so I can add as many fields as I want with the same oDB) and moving within this list.

Now I must add editing, and this includes Sorting. Sorting must be split into Sort() which does the basic/physical sorting and KeyGen(), a function which creates a sort string out of the currently selected data record.

To stay neutral at this level, I can only implement Sort() into oDB and (possibly) a dummy version of KeyGen(), which must be overloaded later in any way inside the client instance.

It is simple to overload a function from the client view by defining it "virtual". From outside access this is ok, but I must access this client version of KeyGen() from the parent!!!

Haw can I do that or something similar? I know that I can fix that with workarounds, but this is not my target. I want to keep the internal list of records "private" and to offer only methods for accessing it.

Please, if you know a solution, let me know!

Thanks in advance,

Ing. Rainer Hantsch

\\|// Ing. Rainer HANTSCH - Hardware + Software (o o) Your Partner - Your Supplier - Your Friend! --oOOo-(_)-oOOo-------------------------------------------------- Ing. Rainer HANTSCH | e-Mail:
Khunngasse 21/20 | www : http://www.hantsch.co.at A-1030 Vienna | Tel. : ++43 - 1 - 7988538 0 ---------------------| Fax : ++43 - 1 - 7988538 18 ** AUSTRIA ** | Mobile: ++43 - 663 - 9194382 -----------------------------------------------------------------

Reply by email

md
to Rainer Hantsch

Somehow, use function pointers to let your parent access the specific child version of the Key( ) function.

Let's say your child overrides your parent, So you child has the function and your parent does not. Put
a pointer to a function inside the parent and assign that pointer after override, assigning the address of the child function to the pointer in the parent. This would allow the parent to test the nil value of the function pointer
and call it if not nil.

Hope that gives you a way out!

Unfortunately, you would have to provide a pointer for every function you want to do this with.

Mark

Rainer Hantsch wrote 48 lines
Hello, everybody! I have a very interesting problem with my programming and I hope there is somebody here who knows a solution. I wrote a "Database Unit", which offers a basic oDB object for a special form of text-based databases. This oDB includes currently everything I need for ReadOnly operation. It is kept absolutely neutral, reads the whole database file into a list of string on the heap, and allows to access the fields by name (so I can add as many fields as I want with the same oDB) and moving within this list. Now I must add editing, and this includes Sorting. Sorting must be split into Sort() which does the basic/physical sorting and KeyGen(), a function which creates a sort string out of the currently selected data record. To stay neutral at this level, I can only implement Sort() into oDB and (possibly) a dummy version of KeyGen(), which must be overloaded later in any way inside the client instance. It is simple to overload a function from the client view by defining it "virtual". From outside access this is ok, but I must access this client version of KeyGen() from the parent!!! Haw can I do that or something similar? I know that I can fix that with workarounds, but this is not my target. I want to keep the internal list of records "private" and to offer only methods for accessing it. Please, if you know a solution, let me know! Thanks in advance, Ing. Rainer Hantsch \\|// Ing. Rainer HANTSCH - Hardware + Software (o o) Your Partner - Your Supplier - Your Friend! --oOOo-(_)-oOOo-------------------------------------------------- Ing. Rainer HANTSCH | e-Mail: Khunngasse 21/20 | www : http://www.hantsch.co.at A-1030 Vienna | Tel. : ++43 - 1 - 7988538 0 ---------------------| Fax : ++43 - 1 - 7988538 18 ** AUSTRIA ** | Mobile: ++43 - 663 - 9194382 ----------------------------------------------------------------- _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Ingmar Tulva
to Rainer Hantsch: Hello, everybody! I have a very interesting problem with my programming and I hope there…
Rainer Hantsch wrote 7 lines
It is simple to overload a function from the client view by defining it "virtual". From outside access this is ok, but I must access this client version of KeyGen() from the parent!!! Haw can I do that or something similar? I know that I can fix that with workarounds, but this is not my target. I want to keep the internal list of records "private" and to offer only methods for accessing it.

Either:
1. Make the internal list "protected" instead of "private" (you use classes, do you?).
2. Pass the record from whitch you are extracting the key to KeyGen() as a parameter.
3. I got something wrong (c:

Ingmar Tulva,

Reply by email

Johan Blok
to Rainer Hantsch: Hello, everybody! I have a very interesting problem with my programming and I hope there…
Rainer Hantsch wrote 29 lines
Hello, everybody! I have a very interesting problem with my programming and I hope there is somebody here who knows a solution. I wrote a "Database Unit", which offers a basic oDB object for a special form of text-based databases. This oDB includes currently everything I need for ReadOnly operation. It is kept absolutely neutral, reads the whole database file into a list of string on the heap, and allows to access the fields by name (so I can add as many fields as I want with the same oDB) and moving within this list. Now I must add editing, and this includes Sorting. Sorting must be split into Sort() which does the basic/physical sorting and KeyGen(), a function which creates a sort string out of the currently selected data record. To stay neutral at this level, I can only implement Sort() into oDB and (possibly) a dummy version of KeyGen(), which must be overloaded later in any way inside the client instance. It is simple to overload a function from the client view by defining it "virtual". From outside access this is ok, but I must access this client version of KeyGen() from the parent!!! Haw can I do that or something similar? I know that I can fix that with workarounds, but this is not my target. I want to keep the internal list of records "private" and to offer only methods for accessing it.

I don't know if I understand your problem right, but you have:

class oDB
  function KeyGen ; virtual;
end;
class Client(oDB)
  function KeyGen ; override;
end;

If you know call the function KeyGen within a method of oDB and an instance of Client is used, then Client.KeyGen is called.

Johan Blok

Reply by email