Mike,
I am stabbing in the dark because I do not fully understand your
requirements, but consider these two approaches:
1. If FormX is a modal form called from forms FormA and FormB:
Create a public class method in FormX that opens the form, and returns the
changed property, eg:
class function TFormX.ShowMe (AOwner: TComponent);
begin
with TFormX.Create (AOwner) do
try
ShowModal;
Result := SomePropertyValue;
finally
Free;
end;
end;
2. If FormX is a single instance form, shared by other forms in the
application:
Create a registry of events where each form can hook into. Eg:
TFormX = class (TForm)
private
colOnChangeHandlers: TCollection;
procedure Change;
public
procedure RegisterOnChange (Event: TNotifyEvent);
procedure UnRegisterOnChange (Event: TNotifyEvent);
end;
THandlerItem = class (TCollectionItem)
public
Event: TNotifyEvent;
end;
In the form create event:
colOnChangeHandlers := TCollection.Create (THandlerItem);
and remember to free it in form destroy
procedure TFormX.RegisterOnChange (Event: TNotifyEvent);
begin
THandlerItem(colOnChangeHandlers.Add).Event := Event;
end;
procedure TFormX.Change;
var
f: Integer;
begin
for f := 0 to colOnChangeHandlers.Count-1 do
THandlerItem(colOnChangeHandlers.Items[f]).Event (Self);
end;
Unregister procedure left as an exercise to the reader. (I'm too lazy to
write it <g>)
Whenever the property changes, call the Change procedure.
The other forms can register an interest in the change by calling
RegisterChange:
TFormA = class (TForm)
private
procedure OnFormXChange (Sender: TObject);
end;
procedure TFormA.OnFormXChange (Sender: TObject);
begin
// Code to update label caption, etc, in FormA
end;
In the form create event:
FormX.RegisterOnChange (OnFormXChange);
HTH,
Dennis.
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, 24 April 2001 11:33
> To: Multiple recipients of list delphi
> Subject: [DUG]: Basic OO/Delphi Question
>
>
> I have a form FormX that I want to use in a number of projects.
>
> In, say, Project A I have a form FormA with a label and caption.
> When a change is made to some list or variable on FormX I want to
> modify the
> FormA.label.caption
>
> I don't want to do this by writing FormA.label.caption := 'Foo';
> in my FormX
> unit
>
> because that won't work when I want to do a similar thing from FormX to
> FormB in ProjectB.
>
> I know that being able to do this is the benefit of OO but I'm stuck in my
> procedural mindset.
>
> I can make the value I change a property of FormX - but how does FormA or
> FormB know the property has changed?
>
> I'm sure it's simple - just can't see it.
>
> Ideas please.
>
> TIA
> Mike
---------------------------------------------------------------------------
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"