[fpc-pascal]Question on OOP programming...

Johan Blok johanbloK at ix.nl
Sat Nov 11 16:06:28 CET 2000

Rainer Hantsch wrote:
> 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;

class Client(oDB)
  function KeyGen ; override;

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

More information about the fpc-pascal mailing list