|
<< Click to Display Table of Contents >> Navigation: Telegram > 2023 > 12 > 05 > Telegram_2023-12-05T10 |
2023-12-05T10:23:22
When we create the Fish List frame...
type: pre procedure TfrmMainForm.DoViewFishList;
begin
FreeFrame;
ShowFrame(TfrmFishList, rgnMain);
TfrmFishList(fFrame).OnViewData := ViewFishData;
TfrmFishList(fFrame).OnViewImage := ViewFishImage;
end; language:
... the ViewFishData and ViewFishImage methods are assigned to the OnView* properties on TfrmFishList, as above.
type: pre public
{ Public declarations }
constructor Create(aOwner: TComponent); override;
property OnViewData: TOnViewRecordEvent read FOnViewData write FOnViewData;
property OnViewImage: TOnViewRecordEvent read FOnViewImage write FOnViewImage;
end; language:
The goal here is to execute something external to the frame without using the Uses clause to avoid coupling.
TOnViewRecordEvent is an event type declared in unit BSApp.Types;
So, when there is a button click, if there is a method assigned to the property, we execute the external method (that was assigned on DoViewFishList)
type: pre procedure TfrmFishList.ViewImageAsyncClick(Sender: TObject; EventParams: TStringList);
begin
if Assigned(FOnViewImage) then
begin
// the SpeciesNo value is saved on the Tag property of our buttons
OnViewImage(TIWButton(Sender).Tag);
end;
end; language:
In this particular case, we execute the ViewFishImage from the main form, which will then show the Fish Image frame.
type: pre procedure TfrmMainForm.ViewFishImage(aSpeciesNo: Integer);
begin
DoViewFishImage(aSpeciesNo, CloseFishFrame);
end; language:
This is just one of many ways of avoid coupling and I've been using it since forever. May not be the best, but it works just fine and it is easy to manage.
I hope my explanation is clear enough :-)