Selamat pagi mastah mastah.. ane mau tanya nih hehe
jadi kan ane buat thread untuk buat kotak yang pindah tiap detik di map pake library mapxLib_thb (activeX). Nah ternyata muncul error seperti ini gan.
kalo tanpa thread muncul normal, cuman klo kotaknya lebih dari 1 hasilnya bakal lag banget gan.
ini kodingannya gan
Spoiler for Thread:
ini procedure untuk men trigger thread nya..
Spoiler for Procedure Trigger:
procedure TACGroup.TheInitiation;
begin
ThreadRectangle := ThreadRect.Create(False);
end;
Dimana ThreadRectangle adalah
TACGroup = class
public
arrACGroup : Array [0..1000] of TAGroup;
arrACGroupIdx :Integer;
ThreadRectangle : ThreadRect; <---- TThread.
ini untuk menghitung posisi kotaknya gan..
Spoiler for Rectangle:
procedure TACGroup.MagicRectangle;
var
i, j, k, l : Integer;
FX, FY, dist : Double;
koorX : array [0..4] of Double;
koorY : array [0..4] of Double;
begin
dist := (3 * 1852) / 111321;
l := 1;
for i := 0 to arrACGroupIdx do
begin
if (arrACGroup[i].GroupID <> '') and (arrACGroup[i].Establish) then
begin
for j := 0 to arrACGroup[i].PlanesCount -1 do
begin
case arrACGroup[i].Formation of
1, 2, 3 : begin
if j > 0 then
begin
// Cari titik tengah dari formasi
FX := ((arrACGroup[i].Planes[j].PosX + arrACGroup[i].Planes[j-1].PosX)/2);
FY := ((arrACGroup[i].Planes[j].PosY + arrACGroup[i].Planes[j-1].PosY)/2);
// Titik Pertama
KoorX[0] := FX - (dist * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[0] := FY - (dist * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Kedua
KoorX[1] := FX + (dist * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[1] := FY + (dist * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Label
KoorX[2] := KoorX[0] - (((0.5 * 1852) / 111321) * Cos((270 - arrACGroup[i].Heading)* PI/180));
KoorY[2] := KoorY[0] - (((0.5 * 1852) / 111321) * Sin((270 - arrACGroup[i].Heading)* PI/180));
end;
end;
4 : begin
// Cari titik tengah pertama dari formasi
FX := ((arrACGroup[i].Planes[0].PosX + arrACGroup[i].Planes[2].PosX)/2);
FY := ((arrACGroup[i].Planes[0].PosY + arrACGroup[i].Planes[2].PosY)/2) - (1 * 1852) / 111321;
//arrACGroup[i].Planes[2].SetPosition(FX, FY, 0);
// Titik Pertama
KoorX[0] := FX - (dist * 1.5 * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[0] := FY - (dist * 1.5 * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Kedua
KoorX[1] := FX + (dist * 1.5 * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[1] := FY + (dist * 1.5 * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Label
KoorX[2] := KoorX[0] - (((0.5 * 1852) / 111321) * Cos((270 - arrACGroup[i].Heading)* PI/180));
KoorY[2] := KoorY[0] - (((0.5 * 1852) / 111321) * Sin((270 - arrACGroup[i].Heading)* PI/180));
end;
5 : begin
if j > 1 then
begin
// Cari titik tengah pertama dari formasi
FX := ((arrACGroup[i].Planes[j].PosX + arrACGroup[i].Planes[j-1].PosX)/2);
FY := ((arrACGroup[i].Planes[j].PosY + arrACGroup[i].Planes[j-1].PosY)/2);
// Cari titik tengah kedua dari formasi
FX := ((FX + arrACGroup[i].Planes[0].PosX)/2);
FY := ((FY + arrACGroup[i].Planes[0].PosY)/2);
// Titik Pertama
KoorX[0] := FX - (dist * 1.5 * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[0] := FY - (dist * 1.5 * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Kedua
KoorX[1] := FX + (dist * 1.5 * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[1] := FY + (dist * 1.5 * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Label
KoorX[2] := KoorX[0] - (((0.5 * 1852) / 111321) * Cos((270 - arrACGroup[i].Heading)* PI/180));
KoorY[2] := KoorY[0] - (((0.5 * 1852) / 111321) * Sin((270 - arrACGroup[i].Heading)* PI/180));
end;
end;
6: begin
// Cari titik tengah pertama dari formasi
FX := ((arrACGroup[i].Planes[1].PosX + arrACGroup[i].Planes[2].PosX)/2);
FY := ((arrACGroup[i].Planes[1].PosY + arrACGroup[i].Planes[2].PosY)/2);
// Titik Pertama
KoorX[0] := FX - (dist * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[0] := FY - (dist * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Kedua
KoorX[1] := FX + (dist * Cos((315 - arrACGroup[i].Heading)* PI/180));
KoorY[1] := FY + (dist * Sin((315 - arrACGroup[i].Heading)* PI/180));
// Titik Label
KoorX[2] := KoorX[0] - (((0.5 * 1852) / 111321) * Cos((270 - arrACGroup[i].Heading)* PI/180));
KoorY[2] := KoorY[0] - (((0.5 * 1852) / 111321) * Sin((270 - arrACGroup[i].Heading)* PI/180));
end;
end;
end;
if frmarcsMap.IsEmptyOrNull(arrACGroup[i].RectID) then
begin
arrACGroup[i].RectID := frmarcsMap.MakeOvrRectangleX(koorX[0], koorY[0], koorX[1], koorY[1]);
//arrACGroup[i].LabelID := frmarcsMap.MakeOvrTextX(koorX[2], koorY[2], arrACGroup[i].GroupID);
PutBullEyesFrm.BullsSetting(koorX[2], koorY[2], arrACGroup[i].GroupID);
end else
begin
//frmarcsMap.DeleteRect(arrACGroup[i].RectID, arrACGroup[i].LabelID);
frmarcsMap.DeleteRect(arrACGroup[i].RectID);
if l = 1 then
begin
for k := frmarcsMap.BullsLabel.BullEyesPoints.Count -1 downto 0 do
begin
frmarcsMap.BullsLabel.BullEyesPoints.Delete(k);
inc(l);
end;
end;