Hi,
I put frame-objects into a tflowpanel.
procedure TfrmMain.Button1Click(Sender: TObject);
var
aFrame : TMyFrame;
begin
LastID := LastID + 1;
aFrame := TMyFrame.Create(FlowPanel1);
aFrame.Parent := FlowPanel1;
aFrame.AutoSize := True;
aFrame.Align := alNone;
aFrame.Name := 'MyFrame'+IntToStr(LastID);
end;
After this I want to call a method for all of these frames of the flowpanel.controllist.
procedure TfrmMain.Button2Click(Sender: TObject);
var i : integer;
t : TFlowPanelControl;
begin
for i := 0 to FlowPanel1.ControlList.Count-1 do
begin
t := TFlowPanelControl(FlowPanel1.ControlList.Items[i]);
TMyFrame(t).SetShapeColor(clYellow); <<<<<<<<<<<<<<<<<<<<<<<<<<< here the program crashes!!!!!!
end;
end;
MyFrame is defined here:
unit uFrame;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Graphics, Controls, BCLabel, BGRAShape,
DTAnalogClock;
type
{ TMyFrame }
TMyFrame = class(TFrame)
BCLabel1: TBCLabel;
BCLabel2: TBCLabel;
BGRAShape1: TBGRAShape;
DTAnalogClock1: TDTAnalogClock;
procedure BGRAShape1Click(Sender: TObject);
private
public
procedure SetShapeColor(aColor : TColor);
end;
implementation
{$R *.lfm}
{ TMyFrame }
procedure TMyFrame.BGRAShape1Click(Sender: TObject);
begin
SetShapeColor(clBlue);
end;
procedure TMyFrame.SetShapeColor(aColor: TColor);
begin
Self.BGRAShape1.FillColor := aColor;
end;
end.
Unfortunately the program crashes, because the typecast from TFlowPanelControl to TMyFrame doesnt work.
Can anybody help me?
You will find my sourcode in appendix
Kind regards
Fritz