AnimateWindow Slide - delphi

I want my form slide down and back to position with slide animation, how to make correct AnimateWinows, if it real for sure ...
void __fastcall TUsers::BitBtn1Click(TObject *Sender)
{
if (!pressed)
{
Height=700;
//AnimateWindow(Handle, 500, AW_CENTER | AW_SLIDE | AW_VER_POSITIVE);
pressed=true;
}
else
{
pressed=false;
//AnimateWindow(Handle, 500, AW_CENTER | AW_SLIDE | AW_VER_NEGATIVE);
Height=425;
}
}
to moderators : here is no mutters Builder or Delphi :)

If you are interested in controlling the animation yourself, here is a sample of code we wrote to accomplish that. It looks and works great. We are sliding Tform1 from the right to the left within a TPanel control on the main form. We ensure that Self.Parent and DoubleBuffered gets set correctly in MyCreate. ShiftLeft and then ShiftRight do the work. We ran into a problem for certain users where the Self.Top was being shifted so we are making sure that Self.Top := 0 with each iteration and when fully shifted. That solved all of the weird issues we were seeing.
Hope this helps!
{
TForm1.MyCreate
---------------------------------------------------------------------------
}
constructor TForm1.MyCreate(AOwner: TComponent);
var
OwnerControl: TWinControl;
begin
inherited Create(AOwner);
if Owner is TWinControl then
begin
OwnerControl := Owner as TWinControl;
Self.Parent := OwnerControl;
end;
Self.Visible := false;
Self.DoubleBuffered := true;
Self.BorderStyle := bsNone;
end;
{
TForm1.ShiftLeft
---------------------------------------------------------------------------
}
procedure TForm1.ShiftLeft;
var
TicksStart: int64;
InitLeftValue: integer;
StartLeftValue: integer;
NewLeftValue: integer;
LeftValueDif: integer;
RemainingTicks: int64;
begin
Self.Top := 0;
Self.Height := Self.Parent.ClientHeight;
Self.Width := Self.Parent.ClientWidth;
InitLeftValue := Self.Parent.Left;
StartLeftValue := Self.Parent.Left + Self.Parent.ClientWidth;
LeftValueDif := StartLeftValue - InitLeftValue;
Self.Left := StartLeftValue;
Self.Visible := true;
TicksStart := GetTickCount();
RemainingTicks := FadeTime;
while RemainingTicks > 0 do
begin
NewLeftValue := (LeftValueDif * RemainingTicks) div FadeTime;
Self.Left := Max(InitLeftValue, NewLeftValue);
Self.Parent.Repaint;
Self.Top := 0;
Self.Repaint;
RemainingTicks := FadeTime - int64(GetTickCount - TicksStart);
end;
if Self.Left > InitLeftValue then
Self.Left := InitLeftValue;
Self.Parent.Repaint;
Self.Top := 0;
Self.Repaint;
end;
{
TForm1.ShiftRight
---------------------------------------------------------------------------
}
procedure TForm1.ShiftRight;
var
TicksStart: int64;
StartLeftValue: integer;
EndLeftValue: integer;
NewLeftValue: integer;
LeftValueDif: integer;
RemainingTicks: int64;
begin
Self.Top := 0;
StartLeftValue := Self.Left;
EndLeftValue := Self.Left + Self.Width;
LeftValueDif := EndLeftValue - StartLeftValue;
TicksStart := GetTickCount();
RemainingTicks := FadeTime;
while RemainingTicks > 0 do
begin
NewLeftValue := (LeftValueDif * (FadeTime - RemainingTicks)) div FadeTime;
Self.Left := Max(StartLeftValue, NewLeftValue);
Self.Parent.Repaint;
Self.Top := 0;
Self.Repaint;
RemainingTicks := FadeTime - int64(GetTickCount - TicksStart);
end;
if Self.Left < EndLeftValue then
Self.Left := EndLeftValue;
Self.Parent.Repaint;
Self.Top := 0;
Self.Repaint;
end;

That's not what AnimateWindow is for. That function hides or shows a window using some animation. Your window is already visible, and you want it to stay visible, so AnimateWindow is not for you.
What you should do instead is make your window successively taller or shorter in a loop until you reach the new desired height.

Check the following link for an answer and a cool demo program.
http://delphi.about.com/od/delphi-tips-2011/qt/hide-slide-fade-away-controls-delphi-form.htm

Related

creating a pause menu in delphi

Background: I have created a maze game that is playable, however when the maze gets bigger there are more chances to go wrong and takes ages to reach the start of the maze again, I've been told that's really annoying.
Question: I want to create a pause game function that when the user presses the button key a menu pops up that allows the user to be able to either return to main menu or restart the maze.
I have very little knowledge on where to start this in the code as I don't want to mess up anything that has already been added.
I've added the draw maze //creates the maze,
initialise visited and walk // removes the walls of the maze,
Form key down//moves the player
and Timer//collision detection procedures below.
hopefully someone can help?
Many Thanks.
`procedure TfrmMazeDesign.draw_maze(square_size: integer);
var
row, col : integer;
begin
// setup default walls as "WWWW" wall on all four sides.
SetLength(Shapes,height+3, width+3, 2 ) ;
for row := 1 to height do
begin
for col := 1 to width+2 do
begin
Shapes[row,col,0]:= TShape.Create(Self);
Shapes[row,col,0].Parent := Self;
with Shapes[row,col,0] do
begin
Width := 5;
Height := square_size;
Left := 100+ ((col-1) * square_size);
Top := 50+ ((row-1) * square_size);
Brush.Color := RGB(255, 255,25);
Shape := stRectangle;
end;
end;
end;
for row := 1 to height+1 do
begin
for col := 1 to width+1 do
begin
Shapes[row,col,1]:= TShape.Create(Self);
Shapes[row,col,1].Parent := Self;
with Shapes[row,col,1] do
begin
Width := square_size;
Height := 5;
Left := 100+ ((col-1) * square_size);
Top := 50+ ((row-1) * square_size);
Brush.Color := RGB(255, 255,25);
Shape := stRectangle;
end;
end;
end;
end;
procedure TfrmMazeDesign.initialise_visited(var visited: Tvisited);
var
row, col: integer;
begin
for row := 0 to height+2 do
for col := 0 to width+2 do
if (col = 0) or (row = 0) or (row = height+1) or (col= width+2) then
visited[row,col] := True
else
visited[row,col] := False;
end;
procedure TFrmMazeDesign.walk(visited: Tvisited; x: integer; y:integer);
var
xx,yy, counter, ran_direction: integer;
direction: Tstringlist; // 1= Up, 2= right, 3 = down, 4 = left
text: string;
begin
visited[x,y] := True;
direction := TStringlist.Create;
direction.Add('1');
direction.Add('2');
direction.Add('3');
direction.Add('4');
for counter := direction.Count - 1 downto 0 do
direction.Exchange(counter, Random(counter+1));
for counter := 0 to direction.Count-1 do
begin
ran_direction := StrtoInt(direction[counter]);
if ran_direction= 1 then
begin
xx := x-1;
yy := y
end;
if ran_direction = 2 then
begin
xx := x+1;
yy := y
end;
if ran_direction = 3 then
begin
xx := x;
yy := y-1
end;
if ran_direction= 4 then
begin
xx := x;
yy := y+1
end;
if visited[xx,yy] = False then
begin
if xx = x then
shapes[x,Max(yy,y),0].visible := False;
if yy = y then
shapes[Max(xx,x),y,1].visible := False;
walk (visited, xx,yy)
end;
end;
end;
procedure TfrmMazeDesign.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_UP:
direction := 1;
VK_DOWN:
direction := 2;
VK_LEFT:
direction := 3;
VK_RIGHT:
direction := 4;
end;
end;
procedure TfrmMazeDesign.FormOpen(Sender: TObject);
var
block_height: integer;
xx,yy: integer;
visited: Tvisited;
monster, monster2: TMonster;
Shape_height : integer;
Shape_Width : integer;
imgfinish_height : integer;
maze_width : integer;
begin
width := frmdifficulty.ScrollBar1.Position;
height := frmdifficulty.ScrollBar1.Position;
maze_width := 650;
block_height := maze_width div width;
Shape_height := round( block_height * 0.5);
imgfinish_height := round(block_height * 0.5);
draw_maze(block_height);
SetLength(visited, height+10, width+10) ;
initialise_visited(visited);
walk(visited,3,3);
ShpUser.height := Shape_height;
ShpUser.Width := Shape_height;
imgfinish.width := Shape_height;
imgfinish.height := shape_height;
ShpUser.Shape := UShapeEditor.frmShape.shpShape.Shape;
ShpUser.Brush.color := UShapeEditor.frmShape.shpShape.Brush.color;
FDateTimeTo := StrToDateTime(FormatDateTime('dd' + FormatSettings.DateSeparator + 'mm' +
FormatSettings.DateSeparator + 'yyyy', Now)); Incsecond(time,120);
Timer1.Enabled := True;
monster := TMonster.Create(Self);
monster.Parent := Self;
monster.SetSizes(width, height, shape_height, 55+ maze_width + 10,665);
monster.start;
monster2 := TMonster.Create(Self);
monster2.Parent := Self;
monster2.SetSizes(width, height, shape_height, 50+ maze_width + 10,565);
monster2.start;
end;
procedure TfrmMazeDesign.Timer1Timer(Sender: TObject);
var IntersectionRect: TRect;
collision, test_collision : boolean;
up : boolean;
right : boolean;
max_width, max_height : integer;
xx, yy : integer ;
aRect1: TRect;
buttonSelected : Integer;
collisionend: boolean;
frmMazeDesign: TfrmMazeDesign;
row, col, hoz_vert : integer;
begin
hoz_vert := 0;
xx := 0;
yy := 0;
case direction of
1:begin //Up
yy := -3;
end;
2: begin //down
yy := + 3;
end;
3: begin //left
xx := -3;
end;
4: begin //right
xx := + 3;
end;
end;
repeat
if hoz_Vert = 0 then begin
max_width := width +3;
max_height := Height+1;
end else begin
max_width := width+2;
max_height := Height+2;
end;
row := 1;
repeat
col := 1;
repeat
aRect1 := Rect(ShpUser.Left+xx, ShpUser.Top+yy, ShpUser.Left+ShpUser.width+xx, ShpUser.top+ ShpUser.Height+yy);
if Shapes[row,col,hoz_vert].visible = True then
collision := IntersectRect(IntersectionRect, aRect1, Shapes[row,col,hoz_vert].BoundsRect) ;
col := col + 1;
until (collision) or (col = max_width);
row := row + 1 ;
until (collision) or (row = max_height);
hoz_vert := hoz_vert +1;
until (collision) or (hoz_vert = 2);
if (collision = False) and (direction <> 0) then begin
ShpUser.Top := ShpUser.Top + yy;
ShpUser.Left := ShpUser.Left + xx;
end;
if IntersectRect(IntersectionRect, imgfinish.BoundsRect, Shpuser.BoundsRect) then
begin
Collisionend := true;
if collisionend = true then
frmfinish.Show;
direction:= 0;
end;`
This is relatively straightforward to add to your program, which is already event driven. In summary you need to do the following:
Add a Boolean flag, perhaps named Paused, set to False when the game starts.
When the user presses the pause button, set the Paused flag to True.
When the user presses the resume button, set the Paused flag to False.
In the time event handler, check the Paused flag before updating the positions. If the Paused flag is True, then simply exit from the timer event handler before doing anything else.

TTreeView custom draw item width

I use the OnCustomDrawItem event to draw a TTreeView like this :
Here is my code :
procedure Tform1.trvArbreCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
vRect : TRect;
vBmp : TBitmap;
vBmpRect : TRect;
vTreeView : TTreeView;
vBarreInfo : TScrollInfo;
vDeltaX : Integer;
begin
DefaultDraw := False;
vTreeView := TTreeView(Sender);
vRect := Node.DisplayRect(False);
vBmp := TBitmap.Create();
FillChar(vBarreInfo, SizeOF(vBarreInfo), 0);
vBarreInfo.cbSize := SizeOf(vBarreInfo);
vBarreInfo.fMask := SIF_RANGE or SIF_POS;
if GetScrollInfo(trvArbre.Handle, SB_HORZ, vBarreInfo) then
begin
if vBarreInfo.nMax > vRect.Right - vRect.Left then
begin
vBmp.Width := vBarreInfo.nMax + 1;
vBmp.Height := vRect.Bottom - vRect.Top;
vDeltaX := vBarreInfo.nPos;
end
else
begin
vBmp.Width := vRect.Right - vRect.Left;
vBmp.Height := vRect.Bottom - vRect.Top;
vDeltaX := 0;
end;
end
else
begin
vBmp.Width := vRect.Right - vRect.Left;
vBmp.Height := vRect.Bottom - vRect.Top;
vDeltaX := 0;
end;
vBmpRect := Rect(0, 0, vBmp.Width, vBmp.Height);
if cdsSelected in State then
begin
vBmp.Canvas.Brush.Color := cMenuDownFond;
vBmp.Canvas.Pen .Color := cMenuDownBordure;
end
else if cdsHot in State then
begin
vBmp.Canvas.Brush.Color := cMenuSurvolFond;
vBmp.Canvas.Pen .Color := cMenuSurvolBordure;
end
else
begin
vBmp.Canvas.Brush.Color := clWhite;
vBmp.Canvas.Pen .Color := clwhite;
end;
vBmp.Canvas.Rectangle(vBmpRect);
vBmpRect.Left := vBmpRect.Left + 3;
vBmpRect.Left := vBmpRect.Left + (Node.Level * vTreeView.Indent);
if Node.StateIndex >= 0 then
begin
vTreeView.StateImages.Draw(vBmp.Canvas, vBmpRect.Left, vBmpRect.Top, Node.StateIndex);
end;
vBmpRect.Left := vBmpRect.Left + 18;
vTreeView.Images.Draw(vBmp.Canvas, vBmpRect.Left, vBmpRect.Top, Node.ImageIndex);
vBmpRect.Left := vBmpRect.Left + 18 + 3;
vBmp.Canvas.Font := vTreeView.Font;
DrawText
(
vBmp.Canvas.Handle,
PChar(Node.Text),
Length(Node.Text),
vBmpRect,
DT_SINGLELINE or DT_LEFT or DT_VCENTER or DT_NOPREFIX or DT_END_ELLIPSIS
);
BitBlt
(
Sender.Canvas.Handle,
vRect.Left,
vRect.Top,
vRect.Right - vRect.Left,
vRect.Bottom - vRect.Top,
vBmp.Canvas.Handle,
vDeltaX,
0,
SRCCOPY
);
FreeAndNil(vBmp);
end;
My problem is that the node "My last node wich is not too long" is not too long to justify the presence of the horizontal scrollbar.
When I set DefaultDraw to true I obtain :
It seems that the width of the node is computed with a font I don't use.
I tried to change the font of the canvas, to use Windows API, to use the OnAdvancedCustomDrawItem with no result.
Thanks.
I use Delphi 7. I copied ComCtrls.pas in the folder of my application. I changed procedure TCustomTreeView.CNNotify(var Message: TWMNotify);. Line 8979 from Result := Result or CDRF_SKIPDEFAULT to Result := Result or CDRF_SKIPDEFAULT; and I commented line 8980 else if FCanvasChanged then in order to simulate DefaultDraw=True and FCanvasChanged even if I set DefaultDraw to False in event et don't change font. After a lot of tests, I don't see any caveats.

TImage Not Showing up

When dropping this component onto the form, The TImage is not showing the map image (hexagons) Until i drag the component around on the form , Then it will show it until i stop dragging it around on the form. (this is all in desgin mode). How do i make it show all the time? not when just dragging it.
type
THexMap = Class(TScrollingWinControl)
Constructor
Constructor THexMap.Create(AOwner: Tcomponent);
begin
inherited Create(AOwner);
Width := DEFAULT_MAP_WIDTH;
Height := DEFAULT_MAP_HEIGHT;
FCanvas := timage.Create(self);
tempMap := timage.Create(self);
fcanvas.Parent := self;
tempmap.Parent := self;
fCanvas.Width := DEFAULT_MAP_WIDTH;
fCAnvas.Height := DEFAULT_MAP_WIDTH;
{ Set intial property values for component }
//create map
MakeSolidMap;
end;
MakeSolidMap
Procedure THexMap.MakeSolidMap;
var
p0 : TPoint;
looprow,Loopcol : integer;
begin
TempMap.width := ((HexColumns-1) * round((1.5 * HexRadius))) + (2 * hexRadius);
TempMap.height := ((HexRows) * (2 * rise)) + rise;
With TempMap.Canvas do
begin
{set Background color}
brush.Color := BackColor;
fillrect(rect(0,0,TempMap.Width,TempMap.Height));
{draw Hex's left to right / top to bottom}
for looprow := 1 to HexRows do
begin
for loopcol := 1 to HexColumns do
begin
{compute center coords}
p0 := ConvertCoords(Point(LoopCol,LoopRow),ptROWCOL);
{draw the hex}
DrawSolidHex(Tempmap,bsSolid,hexColor,psSolid,LineColor,P0.X,p0.Y,hexRadius,hex3d);
end;
end;
end;
end;
DrawSoildHex
procedure THexMap.DrawSolidHex(Target: timage;
FillStyle: TBrushStyle;
FillColor: TColor;
LineStyle: TPenStyle;
LineColor: TColor;
x: Integer;
y: Integer;
Radius: Integer;
button: Boolean);
var
p0,p1,p2,p3,p4,p5,p6:TPoint;
begin
p0 := Point(x,y);
{compute each point based on hex center}
p1.X := p0.X - round(Radius /2);
p1.Y := p0.Y - rise;
p2.X := p0.X + round(Radius/2);
p2.Y := p1.Y;
p3.X := p0.X + Radius;
p3.Y := p0.Y;
p4.X := p2.X;
p4.Y := p0.Y + rise;
p5.X := p1.X;
p5.Y := p4.Y;
p6.X := p0.X - Radius;
p6.Y := p0.Y;
{set color / style of lines}
target.canvas.Pen.Color := LineColor;
target.canvas.Pen.Style := LineStyle;
{set color / style of hex}
target.canvas.Brush.Color := FillColor;
Target.canvas.Brush.Style := FillStyle;
{draw the hex}
target.canvas.Polygon([p1,p2,p3,p4,p5,p6]);
{if desired, draw the boarder for the hex}
if button = true then
begin
with target.canvas do
begin
pen.Mode :=pmCopy;
pen.Color :=clWhite;
moveto(p5.X+1,p5.Y-1);
lineto(p6.X+1,p6.Y);
lineto(p1.X+1,p1.Y+1);
lineto(p2.X-1,p2.Y+1);
pen.Color :=clBlack;
lineto(p3.X-1,p3.Y);
lineto(p4.X-1,p4.Y-1);
lineto(p5.X+1,p5.Y-1);
end;
end;
invalidate;
end;
WndProc
procedure THexMap.WndProc(var Message: TMessage);
const
DISCARD_CURRENT_ORIGIN = nil;
var
R : TRect;
PS : PAINTSTRUCT;
begin
if Message.Msg = WM_PAINT then
begin
if GetUpdateRect( Handle, nil, false ) then
begin
BeginPaint( Handle, PS );
try
R := PS.rcPaint;
bitblt(fCanvas.Canvas.Handle, R.Left, R.Top, R.Width, R.Height, TempMap.Canvas.Handle, R.Left+FOffset.X, R.Top+FOffset.Y, SRCCOPY);
finally
EndPaint( Handle, PS );
end;
end
else
inherited;
end
else
inherited;
end;
Nothing shows because you have taken over painting the control by handing WM_PAINT. And in your handling of WM_PAINT you do not paint anything to the device context returned by BeginPaint. You do not call the inherited handler which would call Paint and then paint children. Hence nothing appears in your control.
It seems to me that you need to decide to either use visual controls and let the VCL paint them, or paint your control yourself. You are currently attempting to do both but achieving neither!
I cannot suggest a fix because I've really no idea what you are doing. I don't understand why you have visual controls and override the paint message handler. To go forward you'll need to pick one approach or the other.

Left aligned Tabsheets on JvgPageControl Delphi + Vcl Styles Enabled Issue

On Windows default appearance the tabsheet caption are showed in horizontal (left to right 1) and with the VCL styles enabled they are displayed in vertical (down to top[2]). How I can fix this on Delphi XE5?
Detail: I'm using the JvgPageControl component, from JEDI-VCL 3.58.
I want to create an similar interface of DisplayFusion welcome screen [3]. Suggestions are welcome!
Images:
Thanks in advance!
The TJvgPageControl uses the same vcl style hook (TTabControlStyleHook) of the TPageControl control, so you must create a new style hook inherited from the TTabControlStyleHook and override the DrawTab method.
Check this basic implementation for the new style hook
type
TTabControlStyleHookExt = class(TTabControlStyleHook)
protected
procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
end;
TCustomTabControlClass = class(TCustomTabControl);
{ TTabControlStyleHookExt }
procedure TTabControlStyleHookExt.DrawTab(Canvas: TCanvas; Index: Integer);
var
R, LayoutR, GlyphR: TRect;
ImageWidth, ImageHeight, ImageStep : Integer;
LDrawState: TThemedTab;
LDetails: TThemedElementDetails;
ThemeTextColor: TColor;
FImageIndex: Integer;
begin
if TabPosition <> tpLeft then
begin
inherited ;
exit;
end;
if (Images <> nil) and (Index < Images.Count) then
begin
ImageWidth := Images.Width;
ImageHeight := Images.Height;
ImageStep := 3;
end
else
begin
ImageWidth := 0;
ImageHeight := 0;
ImageStep := 0;
end;
R := TabRect[Index];
if R.Left < 0 then Exit;
if Index = TabIndex then
Dec(R.Left, 2)
else
Dec(R.Right, 2);
Canvas.Font.Assign(TCustomTabControlClass(Control).Font);
LayoutR := R;
if Index = TabIndex then
LDrawState := ttTabItemLeftEdgeSelected
else if (Index = HotTabIndex) and MouseInControl then
LDrawState := ttTabItemLeftEdgeHot
else
LDrawState := ttTabItemLeftEdgeNormal;
LDetails := StyleServices.GetElementDetails(LDrawState);
StyleServices.DrawElement(Canvas.Handle, LDetails, R);
{ Image }
if Control is TCustomTabControl then
FImageIndex := TCustomTabControlClass(Control).GetImageIndex(Index)
else
FImageIndex := Index;
if (Images <> nil) and (FImageIndex >= 0) and (FImageIndex < Images.Count) then
begin
GlyphR := LayoutR;
GlyphR.Bottom := GlyphR.Bottom - ImageStep;
GlyphR.Top := GlyphR.Bottom - ImageHeight;
LayoutR.Bottom := GlyphR.Top;
GlyphR.Left := GlyphR.Left + (GlyphR.Right - GlyphR.Left) div 2 - ImageWidth div 2;
if StyleServices.Available then
StyleServices.DrawIcon(Canvas.Handle, LDetails, GlyphR, Images.Handle, FImageIndex);
end;
{ Text }
if StyleServices.GetElementColor(LDetails, ecTextColor, ThemeTextColor) then
Canvas.Font.Color := ThemeTextColor;
//use the top tab style to draw the text
if Index = TabIndex then
LDetails := StyleServices.GetElementDetails(ttTabItemSelected)
else
if (Index = HotTabIndex) and MouseInControl then
LDetails := StyleServices.GetElementDetails(ttTabItemHot)
else
LDetails := StyleServices.GetElementDetails(ttTabItemNormal);
DrawControlText(Canvas, LDetails, Tabs[Index], LayoutR, DT_VCENTER or DT_CENTER or DT_SINGLELINE or DT_NOCLIP);
end;
Then register the new style hook like this
initialization
TStyleEngine.RegisterStyleHook(TJvgPageControl, TTabControlStyleHookExt);

Send OnClick command to all Dynamic TColorButtons on TabSheet

I'm working on a PingTool and I've got a TabSheet of dynamically created buttons(anywhere from 1-150 based on user input) and I would like to be able to pass the OnClick command to all buttons on the given TabSheet. My individual button clicks successfully run my ping code, but I get a EStackOverflow message when clicking my PingAll button. Any help would be greatly appreciated. Code Excerpt below:
Code used for button creation:
begin
For x := 0 to CheckListBox1.Items.Count -1 Do
Begin
If CheckListBox1.Checked[x]=true then
begin
GLCount := (GLCount +1);
theIP :=(CheckListBox1.Items.Strings[x]);
if GLcount < 10 then begin
B := TColorButton.Create(Self);
B.Name:= ('BTN'+intToStr(GLCount+1));
B.Caption := theIP;
B.Parent := TabSheet2;
B.Height := 25;
B.Width := 97;
B.Left := 0 + GLCount * 96;
B.Top := 8;
B.BackColor := clBtnFace;
B.ForeColor := clBtnText;
B.OnClick := CustomButtonClick;
end;
CustomButtonClick Code:
Procedure TForm1.CustomButtonClick(Sender: TObject);
begin
GlobalIP:=TColorButton(Sender).caption;
IdIcmpClient1.Host := GlobalIP;
IdIcmpClient1.ReceiveTimeout := 500;
IdIcmpClient1.Ping();
case IdIcmpClient1.ReplyStatus.ReplyStatusType of
rsEcho:
TColorButton(Sender).BackColor := clGreen;
rsTimeOut:
TColorButton(Sender).BackColor := clRed;
end;
end;
PingAll Code(not working):
procedure TForm1.PingAllClick(Sender: TObject);
var
i: integer;
begin
For i := 0 to TabSheet2.ControlCount -1 do
if TabSheet2.Controls[i] is TColorButton then
begin
TColorButton(Sender).Click;
end;
end;
You are calling recurcive the method PingAllClick... look that you call TColorButton(Sender).Click instead
....
Control := tabSheet2.Controls[i]
if Control is TColorButton then
TColorButton(Control ).Click()
....

Resources