v delphi jsem naprostý začátečník tak mě omluvte za případně uvedené nepřesnosti.
1. Za běhu programu jsem si vytvořil objekt Image pomocí TObjectList a potřebuju reagovat na událost najetí myši na tento objekt v události onMouseMove, ale nevim jak to mam přesně napsat
Patch.OnMouseMove := PatchMouseMove;
procedure TForm1.PatchMouseMove(Sender: TObject);
begin
TImage(Sender).Picture := PatchPic3.Picture;
end;
2. vytvořil jsem těchto objektů 15 x 15, jak můžu zjistit o který konkrétní objekt se jedná(potřebuju znát index nebo aspon nazev tohoto objektu)?
děkuji
Fórum › Delphi
Image a OnMouseMove

od včerejška jsem to trochu upravil, vše funguje jak ma ale si nevim rady s onMouse Move
Patchs: array[1..20, 1..20] of TImage;
...
Patchs[j, i] := TImage.Create(Self);
Patchs[j, i].Parent := Form1;
Patchs[j, i].AutoSize := True;
Patchs[j, i].Top := 30 + i * 20;
Patchs[j, i].Left := 30 + j * 20;
Patchs[j, i].Tag := index;
//metody
Patchs[i, j].OnMouseMove := PatchMouseMove; //error
Patchs[j, i].OnClick := PatchClick;
...
procedure TForm1.PatchMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
TImage(Sender).Picture := PatchPic3.Picture;
end;
když to spustím naskočí chybová hláška: Debbuger exception notification: project raised exception class EAccessViolation with message
'Access violation at address...' problém bude s těma parametrama, protože metoda onclick funguje bezproblému,
Patchs[i, j].OnMouseMove := PatchMouseMove(parametry); myslím že tu musí být parametry té procedury když jsou nadeklarovány, ale nevím co tam napsat
ještě vložim funkční kód vyextrahovaný z mého programu, takže tu nejspíš možná zbyly příkazy, bez zjevného smyslu
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Contnrs, StdCtrls, jpeg, ExtCtrls, ComCtrls; // TObjectList
type
TForm1 = class(TForm)
PatchPic0: TImage;// 4 objekty Image vložene ve formuláři
PatchPic1: TImage;
PatchPic2: TImage;
PatchPic3: TImage;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure inicializace();
procedure PatchMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Patchs: array[1..20, 1..20] of TImage;
patchData : array [1..20,1..20] of integer;{hrací pole, kde ve vlastnosti TAG:
0 - prazdne pole, 1 - zaskrtly pole hracem 1, 2 - zaskrtly pole hracem 2}
index, player: integer;
createPatchs: boolean;
implementation
{$R *.dfm}
procedure TForm1.inicializace();
var
i,j : integer;
begin
index := 1;
player := 1;
//inicializace pole dat a vytvoření hracího pole
for i := 1 to 20 do
begin
for j := 1 to 20 do
begin
// nastavení políček
if createPatchs = False then
begin
Patchs[j, i] := TImage.Create(Self);
Patchs[j, i].Parent := Form1;
Patchs[j, i].AutoSize := True;
Patchs[j, i].Top := 30 + i * 20;
Patchs[j, i].Left := 30 + j * 20;
Patchs[j, i].Tag := index;
//metody
Patchs[i, j].OnMouseMove := PatchMouseMove;
end;
Patchs[j, i].Picture := PatchPic0.Picture;
patchData[j, i] := 0; // vynulování dat
index := index + 1;
end;
end;
end;
procedure TForm1.PatchMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
TImage(Sender).Picture := PatchPic3.Picture;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
inicializace;
createPatchs := True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree; // vsechno uvolni
end;
end.

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 34 hostů
Podobná vlákna
Event onmousemove ve Firefoxu — založil Arthurk
Image swap — založil Me2D
Pohyblivý image — založil stanke
Image map — založil Jockie
Image slider — založil jordi1811