serenska wrote:
> I have created a TFrame which I would like to share among several
> forms within my application. Each of the forms will have a few
> identically named public variables. Each of these public variables
> will have the same purpose.
Then it sounds like those forms should all have a common ancestor, where
those common fields are introduced just once.
> My question is, how can I access these variables within the logic
> within the TFrame?
>
> I know that I can explicitly reference them by using a syntax like:
>
> FrameVariable := TfrmParent.VariableName;
>
> However, doing this defeats the purpose of sharing the frame's code
> among many forms.
>
> I tried various syntaxes such as FrameVariable := parent.VariableName,
> but nothing seemed to work. Is there a way to do this?
That doesn't work because Parent is of type TWinControl.
I don't think you should use Parent specifically. If you do that, then
your program will break if you even move the frame onto a panel (or for
whatever reason you re-arrange the layout of the form). One thing you
can do is call the GetParentForm procedure, which will go up the list of
children until it finds a form. Then type-cast the result to the base
form class where you introduced the special fields.
Something else you can do instead is introduce a property to the frame
class. The property can refer directly to the proper form.
type
TSpecialForm = class(TForm)
private
FVariableName: string;
public
property VariableName: string read FVariableName;
end;
TSerenskaFrame = class(TFrame)
private
FForm: TSpecialForm;
public
property Form: TSpecialForm read FForm write FForm;
end;
TFirstForm = class(TSpecialForm)
end;
TSecondForm = class(TSpecialForm)
end;
--
Rob
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/