Dave,

Robert Martin is right in that you probably shouldn't be doing this. If
DatabaseUtils accesses MainForm then it isn't really generic database
utilities at all. I think you should probably pass parameters you need, such
as UV, into the procedure instead.

To answer your question tho... there isn't really any way that you can get
the code in DatabaseUtils.pas to directly access properties declared in
TMainForm without having MainForm.pas in your uses clause (which obviously
you don't want for generic database utilities). Having said that there are
various options. You could define a generic form class which has the UV
property and then descend TMainForm from it. eg,

DaveJollieForm.pas:

type
  TDaveJollieForm = class(TForm)
    UV: TUVObjects;
    etc...

MainForm.pas:

type
  TMainForm = class(TDaveJollieForm)
    etc...

Then you could have your DatabaseUtils.pas file use DaveJollieForm.pas and
have your function written as:

function WriteNewCorrRecord(Sender: TDaveJollieForm; CORR, CORI: integer;
PolNum: string): string;
begin
  if  Sender.UV.ReadRecord(CORI,PolNum) then...

This has the advantage that WriteNewCorrRecord will work with any
TDaveJollieForm descendent (btw feel free to use a different class name!)
and is no longer tightly bound to a particular implementation (ie
TMainForm).

There are other ways around it. For example TMainForm could implement an
Interface which exposes the UV object (and anything else you need). Then the
WriteNewCorrRecord function would have it's first parameter defined as this
interface.

eg,
DaveJollieInterfaces.pas:
type
  IUVImplementer = Interface
    function GetUV : TUVObjects;
  end

MainForm.pas (uses DaveJollieInterfaces.pas):
type
  TMainForm = class(TForm, IUVImplementer)
  protected
    FUV: TUVObjects;
    function GetUV : TUVObjects; // for IUVImplementer
    etc...

DatabaseUtils.pas (also uses DaveJollieInterfaces.pas)

function WriteNewCorrRecord(Sender: IUVImplementer; CORR, CORI: integer;
PolNum: string): string;
begin
  if  Sender.GetUV.ReadRecord(CORI,PolNum) then...



Another possible option would be to make UV a published property of
TMainForm and access it using RTTI but that would be the messiest option and
I wouldn't recommend it.

Hope that helps,
David.




> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of [EMAIL PROTECTED]
> Sent: Wednesday, 26 February 2003 10:38 AM
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: How do I refer back to a calling form?
>
>
> Hi Paul
>
> Yes I thought it was that basic, but it doesn't work for me. :-(
>
> Some code snippets from MainForm.pas:
>
> type
>   TMainForm = class(TForm)
>     UV: TUVObjects;
> ...
> procedure TMainForm.UpdateWMS(PolNum: string);
> ...
>   NewCorrKey := WriteNewCorrRecord(Sender,CORR,CORI,PolNum);   //
> this calls
> DatabaseUtils.pas
>
> Code from DatabaseUtils.pas:
>
> function WriteNewCorrRecord(Sender: TObject; CORR, CORI: integer; PolNum:
> string): string;
> begin
>   if  Sender.UV.ReadRecord(CORI,PolNum) then...
>
> When doing a syntax check, it doesn't recognise UV in this unit. If I type
> "Sender." and look at the list that comes up, it's not the same
> as if I type
> "MainForm." when in the originating form.
>
> I know I'm displaying my complete ignorance, but I want to learn. Should I
> pass MainForm in the place of Sender (that didn't seem to work either).
> Please note that the calling form may have some completely different name.
>
> Thanks for any ideas.
>
> Dave
>
>
> -----Original Message-----
> From: Paul Mckenzie [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 26 February 2003 10:24
> To: Multiple recipients of list delphi
> Subject: Re: [DUG]: How do I refer back to a calling form?
>
>
> pass a "Sender" parameter
>
> Regards
> Paul McKenzie
> Analyst Programmer
> SMSS ltd.
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
> Sent: Wednesday, February 26, 2003 10:07 AM
> Subject: [DUG]: How do I refer back to a calling form?
>
>
> > Hi everyone
> >
> > I have a form (MainForm) which calls a function in a unit I'm creating,
> > called DatabaseUtils. I want this unit to be able to have access to the
> > public variables etc. of the calling form, without needing to hardcode
> into
> > the DatabaseUtils unit, "uses MainForm". Any form could have
> called my new
> > unit. So how do I give my unit, access to the calling form?
> >
> > Thanks for any advice.
> >
> > Dave Jollie
> > Software Developer BOA IT
> > 09 368 4259 ext 6231
> >
> > The information contained in this mail message is confidential and may
> also
> > be legally privileged. If you are not the intended recipient,
> please note
> > that any use, dissemination, further distribution, or
> reproduction of this
> > message in any form what so ever, is strictly prohibited.  If
> the mail is
> in
> > error, please notify me by return E-mail, delete your copy of
> the message,
> > and accept my apologies for any inconvenience caused.
> >
> >
> --------------------------------------------------------------------------
> -
> >     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED]
> > with body of "unsubscribe delphi"
> > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
>
>
> ------------------------------------------------------------------
> ---------
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> ------------------------------------------------------------------
> ---------
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to