This is the frame which appeares on the left side of every form, and allows navigation
to different categories of products.
What You See:
This is what you see in Delphi's designer:
What You Get :
This is what you have at runtime:
The Source Code
unit frProductTree;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IWBaseControl, IWControl, IWCompLabel,
IWHTMLControls, IWVCLBaseControl, IWExtCtrls, IWHTMLTag, IWCompRectangle,
IWVCLBaseContainer, IWContainer, IWRegion;
type
TISFProductTree = class(TFrame)
//Every frame used in IntraWeb must have a frame region on it
IWFrameRegion: TIWRegion;
//The Die, Fly! Die logo
imgLogo: TIWImageFile;
//Link to documentation page
lnkSource: TIWLink;
rectRight: TIWRectangle;
procedure lnkSourceClick(Sender: TObject);
private
{ Private declarations }
procedure DoClick(Sender : TObject);
procedure DoLinkHTMLTag(ASender: TObject; ATag: TIWHTMLTag);
public
{ Public declarations }
procedure LoadTree;
end;
implementation
{$R *.dfm}
uses
dmDieFlyDie,
IWColor, IWAppForm, IWForm, IWInit,
uDBInterface,
uDisplayCategory,
ServerController, IWApplication;
//This is the event which is triggered when a link is clicked
//Release the current form, and open the one which displays the chosen category
procedure TISFProductTree.DoClick(Sender: TObject);
begin
if not (Sender is TIWLink) then
Exit;
// Keep the category ID in the User Session
UserSession.CurrentCategoryID := TIWLink(Sender).Tag;
TIWAppForm(WebApplication.ActiveForm).Release;
TISFDisplayCategory.Create(WebApplication).Show;
end;
//This procedure queries the database
//for existing categories, and then programaticaly builds a TIWLink for each one.
//It is called by the form who owns the frame.
procedure TISFProductTree.LoadTree;
var
f : integer;
LTop : integer;
LLink : TIWLink;
begin
for f := Pred(ControlCount) downto 1 do
if Controls[f] is TIWControl then
TIWControl(Controls[f]).Free;
LTop := 160;
with dmFly.qrCategories do
begin
Close;
SQL.Clear;
SQL.Add('SELECT ID, Name FROM Categories');
Open;
while not Eof do
begin
LLink := TIWLink.Create(Self);
LLink.Parent := Self.IWFrameRegion;
with LLink do
begin
Caption := FieldByName('Name').AsString;
// Keep the category's ID in the Tag property.
Tag := FieldByName('ID').AsInteger;
Name := Format('CategoryLink%d', [Tag]);
Left := 10;
Top := LTop;
OnClick := DoClick;
OnHTMLTag := DoLinkHTMLTag;
Font.FontName := 'Verdana';
Font.Color := clWebGOLDENROD;
Font.Size := 10;
Font.Style := [fsBold];
Font.CSSStyle := 'body';
LTop := LTop + Height + 2;
end;
Next;
end;
Close;
end;
end;
procedure TISFProductTree.lnkSourceClick(Sender: TObject);
begin
UserSession.LastVisitedForm := TIWAppFormClass(WebApplication.ActiveForm.ClassType);
TIWAppForm(WebApplication.ActiveForm).Release;
TDocumentation.Create(WebApplication).Show;
end;
end.