Delphi displays frame by tag number in page control

I have a unique question. I am using Delphi 2007 for Windows XP. I have a form with a TPageControl component. I created a frame that I want to display in this PageControl. I will create many other frames that will be displayed based on button click events. In any case, you should use the tag property for the frame, so that when you click the button, the tag number can be transferred to a common function or procedure, so that the functions or procedures can be reused for all buttons. Another idea was to use the table index property and match it with the frame tag number. Any suggestions would be great. Thanks in advance.

+4
source share
1 answer

You need a function that maps the tag number to the frame class, for example:

type TFrameClass = class of TFrame; function GetFrameClass(const aClassID: Integer): TFrameClass; begin case aClassID of 1 : Result := TFrameFoo; 2 : Result := TFrameBar; else Result := nil; end; end; 

and then you can create frames:

 var FrClass: TFrameClass; Frame: TFrame; begin FrClass := GetFrameClass(btn.Tag); if(FrClass <> nil)then begin Frame := FrClass.Create(tabsheet); Frame.Parent := tabsheet; end; 
+2
source

All Articles