Einzelnen Beitrag anzeigen

Benutzerbild von ste_ett
ste_ett

Registriert seit: 10. Sep 2004
Ort: Dülmen
464 Beiträge
 
Delphi 7 Professional
 
#4

Re: Events zuweisen [Delphi und C++]

  Alt 12. Dez 2007, 20:27
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    ImageArray: array of TImage;
    procedure OnImageClick(Sender: TObject);
    procedure CreateAnTImageInstance;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormDestroy(Sender: TObject);
var
  i: Integer;
begin
  for i := Low(ImageArray) to High(ImageArray) do
    ImageArray[i].Free;

  Finalize(ImageArray);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CreateAnTImageInstance;
end;

procedure TForm1.CreateAnTImageInstance;
begin
  SetLength(ImageArray, Length(ImageArray) +1);

  ImageArray[High(ImageArray)] := TImage.Create(nil);

  ImageArray[High(ImageArray)].ShowHint := True;
  ImageArray[High(ImageArray)].Hint := Format('Hint %d', [Length(ImageArray)]);

  ImageArray[High(ImageArray)].Top := Random(Height);
  ImageArray[High(ImageArray)].Left := Random(Width);

  ImageArray[High(ImageArray)].Parent := Self;

  ImageArray[High(ImageArray)].OnClick := OnImageClick;

  ImageArray[High(ImageArray)].Picture.LoadFromFile('C:\Windows\Angler.bmp');
end;

procedure TForm1.OnImageClick(Sender: TObject);
begin
  if (Sender is TImage) then
    ShowMessage((Sender as TImage).Hint);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
end;

end.
Stefan
"Geht nicht!" ist keine Fehlerbeschreibung und "Hab ich schon versucht!" keine Antwort!

Hey, it compiles! Ship it!
  Mit Zitat antworten Zitat